Skip to content

Commit

Permalink
Closes #60
Browse files Browse the repository at this point in the history
Add maping to a repsonse
  • Loading branch information
mtracewicz committed Sep 11, 2024
1 parent c25c17e commit 0c91d2a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions backend/src/api/Controllers/TodoController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using core.Ports;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using api.Resonses;

namespace api.Controllers;

Expand All @@ -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())),
};
}

Expand All @@ -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(),
Expand Down Expand Up @@ -73,7 +74,7 @@ async Task<IActionResult> 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());
}
}

Expand Down
3 changes: 0 additions & 3 deletions backend/src/api/Data/DTO/TodoListDTO.cs

This file was deleted.

8 changes: 8 additions & 0 deletions backend/src/api/Responses/TodoList.cs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 0c91d2a

Please sign in to comment.