Skip to content

Commit

Permalink
Fix put/delete endpoints (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Buratinas authored Jun 8, 2024
1 parent 49c62a4 commit 1a6b191
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions dotnet/Users.API/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public async Task<List<User>> GetAllUsersAsync() =>
public async Task<User?> GetUserByEmailAsync(string email) =>
await context.Users.Find(user => user.Email == email).FirstOrDefaultAsync();

public async Task<User?> GetUserByIdAsync(string id) =>
await context.Users.Find(user => user.Id == id).FirstOrDefaultAsync();

public async Task<User> CreateUserAsync(User user)
{
await context.Users.InsertOneAsync(user);
Expand Down
6 changes: 3 additions & 3 deletions dotnet/Users.API/UserApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static RouteGroupBuilder MapUserApi(this IEndpointRouteBuilder routes)

group.MapPut("/{id}", async (UserService userService, string id, User user) =>
{
var existingUser = await userService.GetUserByEmailAsync(user.Email);
var existingUser = await userService.GetUserByIdAsync(id);
if (existingUser is null)
{
return Results.NotFound();
Expand All @@ -48,13 +48,13 @@ public static RouteGroupBuilder MapUserApi(this IEndpointRouteBuilder routes)

group.MapDelete("/{id}", async (UserService userService, string id) =>
{
var user = await userService.GetUserByEmailAsync(id);
var user = await userService.GetUserByIdAsync(id);
if (user is null)
{
return Results.NotFound();
}
await userService.DeleteUserAsync(user.Email);
await userService.DeleteUserAsync(user.Id);
return Results.NoContent();
});

Expand Down

0 comments on commit 1a6b191

Please sign in to comment.