| | | 1 | | using Anichron.API.Infrastructure; |
| | | 2 | | using Anichron.Core.Data.Repository; |
| | | 3 | | using Microsoft.AspNetCore.Mvc; |
| | | 4 | | using System.Security.Claims; |
| | | 5 | | |
| | | 6 | | namespace Anichron.API.Endpoints; |
| | | 7 | | |
| | | 8 | | public static class BurstEndpoints |
| | | 9 | | { |
| | | 10 | | public static IEndpointRouteBuilder MapBurstEndpoints(this IEndpointRouteBuilder app) |
| | 41 | 11 | | { |
| | 41 | 12 | | var group = app.MapGroup(ApiPaths.Bursts.Group).WithTags("Bursts").RequireUser(); |
| | 41 | 13 | | group.MapGet(ApiPaths.Bursts.Members, GetMembersAsync) |
| | 41 | 14 | | .Produces<IReadOnlyList<AssetDto>>() |
| | 41 | 15 | | .Produces(StatusCodes.Status404NotFound); |
| | 41 | 16 | | return app; |
| | 41 | 17 | | } |
| | | 18 | | |
| | | 19 | | internal static async Task<IResult> GetMembersAsync( |
| | | 20 | | Guid burstId, |
| | | 21 | | ClaimsPrincipal user, |
| | | 22 | | [FromServices] IAssetViewReader reader, |
| | | 23 | | CancellationToken ct) |
| | 2 | 24 | | { |
| | 2 | 25 | | if (!Guid.TryParse(user.FindFirstValue(ClaimTypes.NameIdentifier), out var userId)) |
| | 0 | 26 | | return Results.Unauthorized(); |
| | | 27 | | |
| | 2 | 28 | | var members = await reader.ReadAsync(userId, new BurstMembers(burstId), ct); |
| | 2 | 29 | | return members.Count == 0 |
| | 2 | 30 | | ? Results.NotFound() |
| | 2 | 31 | | : Results.Ok(Bursts.Members(burstId, members)); |
| | 2 | 32 | | } |
| | | 33 | | } |