|
| 1 | +using CCE.Api.Common.Extensions; |
| 2 | +using CCE.Application.Evaluation.Queries.GetAllEvaluations; |
| 3 | +using CCE.Application.Evaluation.Queries.GetEvaluationById; |
| 4 | +using CCE.Domain; |
| 5 | +using MediatR; |
| 6 | +using Microsoft.AspNetCore.Builder; |
| 7 | +using Microsoft.AspNetCore.Http; |
| 8 | +using Microsoft.AspNetCore.Routing; |
| 9 | + |
| 10 | +namespace CCE.Api.Internal.Endpoints; |
| 11 | + |
| 12 | +public static class EvaluationEndpoints |
| 13 | +{ |
| 14 | + public static IEndpointRouteBuilder MapEvaluationEndpoints(this IEndpointRouteBuilder app) |
| 15 | + { |
| 16 | + var group = app.MapGroup("/api/admin/evaluations").WithTags("Evaluations"); |
| 17 | + |
| 18 | + // GET /api/admin/evaluations — list all (admin only) |
| 19 | + group.MapGet("", async ( |
| 20 | + int? page, int? pageSize, |
| 21 | + IMediator mediator, |
| 22 | + CancellationToken ct) => |
| 23 | + { |
| 24 | + var result = await mediator.Send(new GetAllEvaluationsQuery(page ?? 1, pageSize ?? 20), ct).ConfigureAwait(false); |
| 25 | + return result.ToHttpResult(); |
| 26 | + }) |
| 27 | + .RequireAuthorization(Permissions.Survey_ReadAll) |
| 28 | + .WithName("GetAllEvaluations"); |
| 29 | + |
| 30 | + // GET /api/admin/evaluations/{id} — get by id (admin only) |
| 31 | + group.MapGet("{id:guid}", async ( |
| 32 | + System.Guid id, |
| 33 | + IMediator mediator, |
| 34 | + CancellationToken ct) => |
| 35 | + { |
| 36 | + var result = await mediator.Send(new GetEvaluationByIdQuery(id), ct).ConfigureAwait(false); |
| 37 | + return result.ToHttpResult(); |
| 38 | + }) |
| 39 | + .RequireAuthorization(Permissions.Survey_ReadAll) |
| 40 | + .WithName("GetEvaluationById"); |
| 41 | + |
| 42 | + return app; |
| 43 | + } |
| 44 | +} |
0 commit comments