Skip to content

Commit

Permalink
Making Services to use DTOs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tudor3510 committed Jan 31, 2025
1 parent 67e6b36 commit 3ab6f6c
Show file tree
Hide file tree
Showing 35 changed files with 345 additions and 642 deletions.
75 changes: 0 additions & 75 deletions backend-MT/Controllers/AbonamentController.cs

This file was deleted.

17 changes: 7 additions & 10 deletions backend-MT/Controllers/CursController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using backend_MT.Models;
using backend_MT.Models.DTOs;
using backend_MT.Service.CursService;
using Microsoft.AspNetCore.Mvc;

Expand Down Expand Up @@ -37,22 +38,18 @@ public async Task<ActionResult<Curs>> GetCourseById(int id)

// POST: api/curs
[HttpPost]
public async Task<ActionResult<Curs>> AddCourse(Curs curs)
public async Task<IActionResult> AddCourse(CursDTO curs)
{
await _cursService.AddCourseAsync(curs);
return CreatedAtAction(nameof(GetCourseById), new { id = curs.cursId }, curs); // Asumând că Curs are o proprietate Id
if (await _cursService.AddCourseAsync(curs))
return Ok();
return BadRequest();
}

// PUT: api/curs/{id}
[HttpPut("{id}")]
public async Task<IActionResult> UpdateCourse(int id, Curs curs)
public async Task<IActionResult> UpdateCourse(int id, CursDTO curs)
{
if (id != curs.cursId) // Verifică dacă ID-urile se potrivesc
{
return BadRequest();
}

await _cursService.UpdateCourseAsync(curs);
await _cursService.UpdateCourseAsync(id, curs);
return NoContent();
}

Expand Down
18 changes: 8 additions & 10 deletions backend-MT/Controllers/DisponibilitateController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using backend_MT.Models;
using backend_MT.Models.DTOs;
using backend_MT.Service.DisponibilitateService;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
Expand All @@ -19,7 +20,7 @@ public DisponibilitateController(IDisponibilitateService disponibilitateService)

// GET: api/disponibilitate
[HttpGet]
public async Task<ActionResult<IEnumerable<Disponibilitate>>> GetAllDisponibilitati()
public async Task<ActionResult<IEnumerable<DisponibilitateDTO>>> GetAllDisponibilitati()
{
var disponibilitati = await _disponibilitateService.GetAllDisponibilitatiAsync();
return Ok(disponibilitati);
Expand All @@ -39,22 +40,19 @@ public async Task<ActionResult<Disponibilitate>> GetDisponibilitateById(int id)

// POST: api/disponibilitate
[HttpPost]
public async Task<ActionResult<Disponibilitate>> AddDisponibilitate(Disponibilitate disponibilitate)
public async Task<IActionResult> AddDisponibilitate(DisponibilitateDTO disponibilitate)
{
await _disponibilitateService.AddDisponibilitateAsync(disponibilitate);
return CreatedAtAction(nameof(GetDisponibilitateById), new { id = disponibilitate.disponibilitateId }, disponibilitate);
if (await _disponibilitateService.AddDisponibilitateAsync(disponibilitate))
return Ok();
return BadRequest();
}

// PUT: api/disponibilitate/{id}
[HttpPut("{id}")]
public async Task<IActionResult> UpdateDisponibilitate(int id, Disponibilitate disponibilitate)
public async Task<IActionResult> UpdateDisponibilitate(int id, DisponibilitateDTO disponibilitate)
{
if (id != disponibilitate.disponibilitateId)
{
return BadRequest();
}

await _disponibilitateService.UpdateDisponibilitateAsync(disponibilitate);
await _disponibilitateService.UpdateDisponibilitateAsync(id, disponibilitate);
return NoContent();
}

Expand Down
127 changes: 62 additions & 65 deletions backend-MT/Controllers/FeedbackController.cs
Original file line number Diff line number Diff line change
@@ -1,73 +1,70 @@
//using backend_MT.Models;
//using backend_MT.Service.FeedbackService;
//using Microsoft.AspNetCore.Mvc;
using backend_MT.Models;
using backend_MT.Models.DTOs;
using backend_MT.Service.FeedbackService;
using Microsoft.AspNetCore.Mvc;

//namespace backend_MT.Controllers
//{
// [Route("api/[controller]")]
// [ApiController]
// public class FeedbackController : ControllerBase
// {
// private readonly IFeedbackService _feedbackService;
namespace backend_MT.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class FeedbackController : ControllerBase
{
private readonly IFeedbackService _feedbackService;

// public FeedbackController(IFeedbackService feedbackService)
// {
// _feedbackService = feedbackService;
// }
public FeedbackController(IFeedbackService feedbackService)
{
_feedbackService = feedbackService;
}

// // GET: api/feedback
// [HttpGet]
// public async Task<ActionResult<IEnumerable<Feedback>>> GetAllFeedbacks()
// {
// var feedbacks = await _feedbackService.GetAllFeedbacksAsync();
// return Ok(feedbacks);
// }
// GET: api/feedback
[HttpGet]
public async Task<ActionResult<IEnumerable<FeedbackDTO>>> GetAllFeedbacks()
{
var feedbacks = await _feedbackService.GetAllFeedbacksAsync();
return Ok(feedbacks);
}

// // GET: api/feedback/{id}
// [HttpGet("{id}")]
// public async Task<ActionResult<Feedback>> GetFeedbackById(int id)
// {
// var feedback = await _feedbackService.GetFeedbackByIdAsync(id);
// if (feedback == null)
// {
// return NotFound();
// }
// return Ok(feedback);
// }
// GET: api/feedback/{id}
[HttpGet("{id}")]
public async Task<ActionResult<Feedback>> GetFeedbackById(int id)
{
var feedback = await _feedbackService.GetFeedbackByIdAsync(id);
if (feedback == null)
{
return NotFound();
}
return Ok(feedback);
}

// // POST: api/feedback
// [HttpPost]
// public async Task<ActionResult<Feedback>> AddFeedback(Feedback feedback)
// {
// await _feedbackService.AddFeedbackAsync(feedback);
// return CreatedAtAction(nameof(GetFeedbackById), new { id = feedback.FeedbackId }, feedback); // Asumând că Feedback are o proprietate Id
// }
// POST: api/feedback
[HttpPost]
public async Task<ActionResult> AddFeedback(FeedbackDTO feedback)
{
if (await _feedbackService.AddFeedbackAsync(feedback))
return Ok();
return BadRequest();
}

// // PUT: api/feedback/{id}
// [HttpPut("{id}")]
// public async Task<IActionResult> UpdateFeedback(int id, Feedback feedback)
// {
// if (id != feedback.FeedbackId) // Verifică dacă ID-urile se potrivesc
// {
// return BadRequest();
// }
// PUT: api/feedback/{id}
[HttpPut("{id}")]
public async Task<IActionResult> UpdateFeedback(int id, FeedbackDTO feedback)
{
await _feedbackService.UpdateFeedbackAsync(id, feedback);
return NoContent();
}

// await _feedbackService.UpdateFeedbackAsync(feedback);
// return NoContent();
// }
// DELETE: api/feedback/{id}
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteFeedback(int id)
{
var feedback = await _feedbackService.GetFeedbackByIdAsync(id);
if (feedback == null)
{
return NotFound();
}

// // DELETE: api/feedback/{id}
// [HttpDelete("{id}")]
// public async Task<IActionResult> DeleteFeedback(int id)
// {
// var feedback = await _feedbackService.GetFeedbackByIdAsync(id);
// if (feedback == null)
// {
// return NotFound();
// }

// await _feedbackService.DeleteFeedbackAsync(id);
// return NoContent();
// }
// }
//}
await _feedbackService.DeleteFeedbackAsync(id);
return NoContent();
}
}
}
Loading

0 comments on commit 3ab6f6c

Please sign in to comment.