38 lines
1.8 KiB
C#
38 lines
1.8 KiB
C#
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;
|
|
using static PostFundManagement.Application.Extensions.General;
|
|
using Problems = Microsoft.AspNetCore.Mvc.ProblemDetails;
|
|
|
|
namespace PostFundManagement.Api.Endpoints.Communications;
|
|
|
|
[ApiVersionTarget(1)]
|
|
public sealed class GetNotificationsEndpoint : IEndpoint
|
|
{
|
|
public void Map(IEndpointRouteBuilder builder)
|
|
{
|
|
builder.MapGet("api/communications/notifications/{organisationId}", async (string organisationId,
|
|
ICommunicationsService service, CancellationToken cancellationToken = default) =>
|
|
await service.GetNotificationsAsync(organisationId, cancellationToken) switch
|
|
{
|
|
{ IsSuccess: true, Value: var notifications } => Results.Ok(notifications),
|
|
var r when r.HasError<IdDecodeError>() => Results.Forbid(),
|
|
var r => Results.InternalServerError(r.Errors.ToProblems()),
|
|
})
|
|
.WithDescription("Retrieves the notification system report")
|
|
.RequireAuthorization(Constants.MainScope)
|
|
.WithName(typeof(GetNotificationsEndpoint).ToEndpointName())
|
|
.MapToApiVersion(new ApiVersion(1))
|
|
.Produces<Notification[]>(StatusCodes.Status200OK)
|
|
.Produces(StatusCodes.Status403Forbidden)
|
|
.Produces(StatusCodes.Status401Unauthorized)
|
|
.Produces<Notification[]>(StatusCodes.Status404NotFound)
|
|
.Produces<Problems>(StatusCodes.Status500InternalServerError)
|
|
.WithTags(EndpointTags.Communications)
|
|
.CacheOutput();
|
|
}
|
|
}
|