Skip to content

Commit

Permalink
Closes #60
Browse files Browse the repository at this point in the history
Rename and make requests nested class
Add comment for UserId
  • Loading branch information
mtracewicz committed Sep 27, 2024
1 parent 84564a3 commit bd3598f
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions backend/src/api/Controllers/TodoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class TodoController(ITodoService service, ILogger<TodoController> logger
{
private readonly ITodoService _service = service;
private readonly ILogger<TodoController> _logger = logger;

//We are sure that this is not null because of the [UserIdFilter]
private Guid UserId => (Guid)HttpContext.Items["UserId"]!;

[HttpGet("lists")]
Expand Down Expand Up @@ -49,15 +51,15 @@ public IActionResult DeleteList([FromRoute] int id)
}

[HttpPost("lists")]
public async Task<IActionResult> CreateLists([FromBody] Request request)
public async Task<IActionResult> CreateLists([FromBody] ListCreationRequest request)
{
_logger.LogDebug("User: {user} created: {list}", UserId, request.Name);
var list = await _service.CreateList(UserId, request.Name);
return Created(HttpContext.Request.Path.Add(new PathString($"/{list.Id}")), list.ToResponse());
}

[HttpPut("lists/{id}")]
public async Task<IActionResult> RenameList(RenameRequest request)
public async Task<IActionResult> RenameList(ListRenameRequest request)
{
_logger.LogDebug("User: {user} renamed: {id} to: {list}", UserId, request.Id, request.Body.Name);
var list = await _service.RenameList(UserId, request.Id, request.Body.Name);
Expand Down Expand Up @@ -122,22 +124,22 @@ public async Task<IActionResult> UpdateItem([FromRoute] int id, [FromBody] TodoI
}
return BadRequest();
}
}

public class Request
{
public required string Name { get; set; }
}

public class RenameRequest
{
[FromRoute]
public required int Id { get; set; }
[FromBody]
public required Payload Body { get; set; }

public class Payload
public class ListCreationRequest
{
public required string Name { get; set; }
}

public class ListRenameRequest
{
[FromRoute]
public required int Id { get; set; }
[FromBody]
public required Payload Body { get; set; }

public class Payload
{
public required string Name { get; set; }
}
}
}

0 comments on commit bd3598f

Please sign in to comment.