using PostFundManagement.Application.Abstractions.Services; using PostFundManagement.Application.Extensions; using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Errors; using PostFundManagement.Domain.Extensions; using PostFundManagement.Domain.Models; namespace PostFundManagement.Api.Endpoints.Users; [ApiVersionTarget(1)] public sealed class GetUserEndpoint : IEndpoint { public void Map(IEndpointRouteBuilder builder) { builder.MapGet("api/users/{userId:Guid}", async (Guid userId, IUserService service, HttpContext context, CancellationToken cancellationToken = default) => await service.GetUserAsync(userId, cancellationToken) switch { { IsSuccess: true, Value: var user } => Results.Ok(user), var r when r.HasError() => Results.NotFound(r.Errors.ToProblems()), var r => Results.InternalServerError(r.Errors.ToProblems()) }) .WithDescription("Gets the metadata of a single user.") .RequireAuthorization(Constants.MainScope) .WithName(typeof(GetUserEndpoint).ToEndpointName()) .MapToApiVersion(new ApiVersion(1)) .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status401Unauthorized) .Produces(StatusCodes.Status404NotFound) .Produces(StatusCodes.Status500InternalServerError) .WithTags(EndpointTags.Users) .CacheOutput(); } }