feat: retornar WorkshopResponseDTO no GetById e GetAllAsync
This commit is contained in:
@@ -21,19 +21,20 @@ public class WorkshopsController : ControllerBase
|
|||||||
var workshops = await _repo.GetAllAsync(from, to, q, ct);
|
var workshops = await _repo.GetAllAsync(from, to, q, ct);
|
||||||
if (!workshops.Any())
|
if (!workshops.Any())
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
return Ok(workshops);
|
var workshopDTOs = workshops.Select(w => ConvertToWorkshopResponseDTO(w)).ToList();
|
||||||
|
return Ok(workshopDTOs);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id:guid}")]
|
[HttpGet("{id:guid}")]
|
||||||
public async Task<IActionResult> GetById(Guid id, CancellationToken ct)
|
public async Task<IActionResult> GetById(Guid id, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var result = await _repo.GetByIdAsync(id, ct);
|
var workshop = await _repo.GetByIdAsync(id, ct);
|
||||||
|
|
||||||
if (result == null)
|
if (workshop == null)
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(ConvertToWorkshopResponseDTO(workshop));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
@@ -75,4 +76,18 @@ public class WorkshopsController : ControllerBase
|
|||||||
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private WorkshopResponseDTO ConvertToWorkshopResponseDTO(Workshop workshop)
|
||||||
|
{
|
||||||
|
return new WorkshopResponseDTO(
|
||||||
|
workshop.Id,
|
||||||
|
workshop.Title,
|
||||||
|
workshop.Description,
|
||||||
|
workshop.StartAt,
|
||||||
|
workshop.EndAt,
|
||||||
|
workshop.Location,
|
||||||
|
workshop.Capacity,
|
||||||
|
workshop.IsOnline
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user