Endpoint to see users list
This commit is contained in:
@@ -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<GetAllUserRequest, List<GetUserDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/Users/");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetAllUserRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
await Send.OkAsync(await usersRepository.ProjectToListAsync<GetUserDto>(new GetUserNotFriendSpec(req.Id), ct), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using Ardalis.Specification;
|
||||||
|
using BeReadyBackend.Models;
|
||||||
|
|
||||||
|
namespace BeReadyBackend.Specifications.Users;
|
||||||
|
|
||||||
|
public class GetUserNotFriendSpec : Specification<User>
|
||||||
|
{
|
||||||
|
public GetUserNotFriendSpec(int userId)
|
||||||
|
{
|
||||||
|
Query
|
||||||
|
.Where(x => x.Id != userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user