diff --git a/backend/src/api/Controllers/TodoController.cs b/backend/src/api/Controllers/TodoController.cs index bc83dc8..dbc0ddb 100644 --- a/backend/src/api/Controllers/TodoController.cs +++ b/backend/src/api/Controllers/TodoController.cs @@ -1,6 +1,7 @@ using core.Ports; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using api.Resonses; namespace api.Controllers; @@ -26,7 +27,7 @@ public IActionResult GetLists() return userId switch { null => Unauthorized(), - var user => Ok(_service.GetLists(user)), + var user => Ok(_service.GetLists(user).Select(l => l.ToResponse())), }; } @@ -36,7 +37,7 @@ public IActionResult GetList([FromRoute] int id) var userId = Request.UserId(); _logger.LogDebug("User: {user} requested his list: {id}", userId, id); if (userId is null) { return Unauthorized(); } - var list = _service.GetList(userId, id); + var list = _service.GetList(userId, id)?.ToResponse(); return list switch { null => NotFound(), @@ -73,7 +74,7 @@ async Task Create(string user, string name) { //TODO: return DTO instead of DAO var list = await _service.CreateList(user, name); - return Created(HttpContext.Request.Path.Add(new PathString($"/{list.Id}")), list); + return Created(HttpContext.Request.Path.Add(new PathString($"/{list.Id}")), list.ToResponse()); } } diff --git a/backend/src/api/Data/DTO/TodoListDTO.cs b/backend/src/api/Data/DTO/TodoListDTO.cs deleted file mode 100644 index 275e8d4..0000000 --- a/backend/src/api/Data/DTO/TodoListDTO.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace api.Data.DTO; - -public record TodoListDTO(int Id, string Name); diff --git a/backend/src/api/Responses/TodoList.cs b/backend/src/api/Responses/TodoList.cs new file mode 100644 index 0000000..9207e35 --- /dev/null +++ b/backend/src/api/Responses/TodoList.cs @@ -0,0 +1,8 @@ +namespace api.Resonses; + +public record TodoList(int Id, string Name); + +public static class MapExtensions +{ + public static TodoList ToResponse(this core.TodoList list) => new TodoList(list.Id, list.Name); +}