Initial commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using AutoMapper;
|
||||
using FastEndpoints;
|
||||
using MetaCourse.Api.Data;
|
||||
using MetaCourse.Api.DTOs.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MetaCourse.Api.Endpoints.Users;
|
||||
|
||||
public class GetUserRequest
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetUserEndpoint(AppDbContext db, AutoMapper.IMapper mapper) : Endpoint<GetUserRequest, GetUserDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("api/users/{id}");
|
||||
AllowAnonymous();
|
||||
Summary(s => s.Summary = "Récupère le profil d'un utilisateur");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetUserRequest req, CancellationToken ct)
|
||||
{
|
||||
var user = await db.Users.AsNoTracking().FirstOrDefaultAsync(u => u.Id == req.Id, ct);
|
||||
if (user is null)
|
||||
{
|
||||
await SendNotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
await SendOkAsync(mapper.Map<GetUserDto>(user), ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user