From 1c0fc26f7ee90d05b0ed4ce5b13fa3f9163f4bec Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Sat, 21 Feb 2026 19:06:04 +0100 Subject: [PATCH] Endpoint to see users list --- .../Endpoints/Users/GetAllUsersEndpoint.cs | 26 +++++++++++++++++++ .../Users/GetUserNotFriendSpec.cs | 13 ++++++++++ 2 files changed, 39 insertions(+) create mode 100644 BeReadyBackend/Endpoints/Users/GetAllUsersEndpoint.cs create mode 100644 BeReadyBackend/Specifications/Users/GetUserNotFriendSpec.cs 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