diff --git a/BeReadyBackend/Endpoints/Users/GetAllUsersEndpoint.cs b/BeReadyBackend/Endpoints/Users/GetAllUsersEndpoint.cs new file mode 100644 index 0000000..13ad38b --- /dev/null +++ b/BeReadyBackend/Endpoints/Users/GetAllUsersEndpoint.cs @@ -0,0 +1,26 @@ +using BeReadyBackend.DTO.Users; +using BeReadyBackend.Repositories; +using BeReadyBackend.Specifications.Users; +using FastEndpoints; + +namespace BeReadyBackend.Endpoints.Users; + +// TODO: Prendre directement dans le token (comme pour partout où je peux recup l'id du user d'ailleurs en vrai) !! +public class GetAllUserRequest +{ + public int Id { get; set; } +} + +public class GetAllUsersEndpoint(UsersRepository usersRepository) : Endpoint> +{ + public override void Configure() + { + Get("/Users/"); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetAllUserRequest req, CancellationToken ct) + { + await Send.OkAsync(await usersRepository.ProjectToListAsync(new GetUserNotFriendSpec(req.Id), ct), ct); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Specifications/Users/GetUserNotFriendSpec.cs b/BeReadyBackend/Specifications/Users/GetUserNotFriendSpec.cs new file mode 100644 index 0000000..402d6b1 --- /dev/null +++ b/BeReadyBackend/Specifications/Users/GetUserNotFriendSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using BeReadyBackend.Models; + +namespace BeReadyBackend.Specifications.Users; + +public class GetUserNotFriendSpec : Specification +{ + public GetUserNotFriendSpec(int userId) + { + Query + .Where(x => x.Id != userId); + } +} \ No newline at end of file