27 lines
980 B
C#
27 lines
980 B
C#
using BeReadyBackend.Models;
|
|
using BeReadyBackend.Repositories;
|
|
using BeReadyBackend.Services;
|
|
using BeReadyBackend.Specifications.Friends;
|
|
using BeReadyBackend.Specifications.Users;
|
|
using FastEndpoints;
|
|
|
|
namespace BeReadyBackend.Endpoints.Users;
|
|
|
|
public class DeleteUserEndpoint(UsersRepository usersRepository, UserFriendsRepository userFriendsRepository, UserService userService) : EndpointWithoutRequest
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Delete("/Users/");
|
|
}
|
|
|
|
public override async Task HandleAsync(CancellationToken ct)
|
|
{
|
|
int userId = userService.GetUserIdFromToken();
|
|
|
|
List<UserFriend> friends = await userFriendsRepository.ListAsync(new GetAllFriendsRelationsByIdSpec(userId), ct);
|
|
await userFriendsRepository.DeleteRangeAsync(friends, ct);
|
|
|
|
await usersRepository.DeleteAsync((await usersRepository.SingleOrDefaultAsync(new GetUserByIdSpec(userId), ct))!, ct);
|
|
await Send.NoContentAsync(ct);
|
|
}
|
|
} |