Skip to content

Commit

Permalink
Closes #60
Browse files Browse the repository at this point in the history
Move rename request parameters into class
  • Loading branch information
mtracewicz committed Sep 11, 2024
1 parent 18da5bc commit 9d4de18
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions backend/src/api/Controllers/TodoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ async Task<IActionResult> Create(string user, string name)
}

[HttpPut("lists/{id}")]
public async Task<IActionResult> RenameList([FromRoute] int id, [FromBody] Request request)
public async Task<IActionResult> RenameList(RenameRequest request)
{
var userId = Request.UserId();
_logger.LogDebug("User: {user} renamed: {id} to: {list}", userId, id, request.Name);
_logger.LogDebug("User: {user} renamed: {id} to: {list}", userId, request.Id, request.Body.Name);
return userId switch
{
null => Unauthorized(),
var user => await Rename(user, id, request.Name),
var user => await Rename(user, request.Id, request.Body.Name),
};

async Task<IActionResult> Rename(string user, int id, string name)
Expand All @@ -105,3 +105,16 @@ 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 required string Name { get; set; }
}
}

0 comments on commit 9d4de18

Please sign in to comment.