diff --git a/BeReadyBackend/Endpoints/Groups/AddUserToGroupEndpoint.cs b/BeReadyBackend/Endpoints/Groups/AddUserToGroupEndpoint.cs deleted file mode 100644 index a53ff56..0000000 --- a/BeReadyBackend/Endpoints/Groups/AddUserToGroupEndpoint.cs +++ /dev/null @@ -1,47 +0,0 @@ -using BeReadyBackend.Models; -using BeReadyBackend.Repositories; -using BeReadyBackend.Services; -using BeReadyBackend.Specifications.Groups; -using FastEndpoints; - -namespace BeReadyBackend.Endpoints.Groups; - -public class AddUserToGroupRequest -{ - public int UserId { get; set; } - public int GroupId { get; set; } -} - -public class AddUserToGroupEndpoint(UserService userService, UserGroupsRepository userGroupsRepository, AutoMapper.IMapper mapper) : Endpoint -{ - public override void Configure() - { - Post("/Groups/{@GroupId}/Users/{@UserId}/", x => new { x.GroupId, x.UserId }); - } - - public override async Task HandleAsync(AddUserToGroupRequest req, CancellationToken ct) - { - int userId = userService.GetUserIdFromToken(); - - UserGroup? member = await userGroupsRepository.SingleOrDefaultAsync(new GetUserInGroupByIdsSpec(req.GroupId, userId), ct); - - if (member is null) - { - await Send.StringAsync("Vous n'êtes pas dans ce groupe", 400, cancellation: ct); - return; - } - - UserGroup? userGroup = await userGroupsRepository.SingleOrDefaultAsync(new GetUserInGroupByIdsSpec(req.GroupId, req.UserId), ct); - if (userGroup is not null) - { - await Send.StringAsync("L'utilisateur fait déjà partie du groupe", 400, cancellation: ct); - return; - } - - userGroup = mapper.Map(req); - userGroup.Grade = "Member"; - - await userGroupsRepository.AddAsync(userGroup, ct); - await Send.NoContentAsync(ct); - } -} \ No newline at end of file