using FluentResults; using IdentityShroud.Core.Contracts; using IdentityShroud.Core.Messages.Realm; using IdentityShroud.Core.Model; using IdentityShroud.Core.Services; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; namespace IdentityShroud.Api; public record ClientCreateReponse(int Id, string ClientId); /// /// The part of the api below realms/{slug}/clients /// public static class ClientApi { public const string ClientGetRouteName = "ClientGet"; public static void MapEndpoints(this IEndpointRouteBuilder erp) { RouteGroupBuilder clientsGroup = erp.MapGroup("clients"); clientsGroup.MapPost("", ClientCreate) .Validate() .WithName("ClientCreate") .Produces(StatusCodes.Status201Created); var clientIdGroup = clientsGroup.MapGroup("{clientId}") .AddEndpointFilter(); clientIdGroup.MapGet("", ClientGet) .WithName(ClientGetRouteName); } private static Task ClientGet(HttpContext context) { throw new NotImplementedException(); } private static async Task, InternalServerError>> ClientCreate( ClientCreateRequest request, [FromServices] IClientService service, HttpContext context, CancellationToken cancellationToken) { Realm realm = context.GetValidatedRealm(); Result result = await service.Create(realm.Id, request, cancellationToken); if (result.IsFailed) { throw new NotImplementedException(); } Client client = result.Value; return TypedResults.CreatedAtRoute( new ClientCreateReponse(client.Id, client.ClientId), ClientGetRouteName, new RouteValueDictionary() { ["realmId"] = realm.Id, ["clientId"] = client.Id, }); throw new NotImplementedException(); } }