Added missing endpoints
This commit is contained in:
+4
-4
@@ -9,11 +9,11 @@ using Problems = Microsoft.AspNetCore.Mvc.ProblemDetails;
|
||||
namespace PostFundManagement.Api.Endpoints.Evidence;
|
||||
|
||||
[ApiVersionTarget(1)]
|
||||
public class UploadEvidenceFilesEndpoint : IEndpoint
|
||||
public class CreateEvidenceEndpoint : IEndpoint
|
||||
{
|
||||
public void Map(IEndpointRouteBuilder builder)
|
||||
{
|
||||
builder.MapPost("api/evidence/files", async (HttpRequest request, EvidenceService service,
|
||||
builder.MapPut("api/evidence/file", async (HttpRequest request, EvidenceService service,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
{
|
||||
var userId = request.HttpContext.GetUserId();
|
||||
@@ -27,7 +27,7 @@ public class UploadEvidenceFilesEndpoint : IEndpoint
|
||||
if (file == null || file.Length == 0)
|
||||
return Results.BadRequest("No file uploaded or file is empty.");
|
||||
|
||||
return await service.UploadEvidenceFileAsync(userId, form, file, cancellationToken) switch
|
||||
return await service.CreateEvidenceAsync(userId, form, file, cancellationToken) switch
|
||||
{
|
||||
{ IsSuccess: true } => Results.Ok(),
|
||||
var r when r.HasError<CreateError>() => Results.BadRequest(r.Errors.ToProblems()),
|
||||
@@ -37,7 +37,7 @@ public class UploadEvidenceFilesEndpoint : IEndpoint
|
||||
.RequireAuthorization()
|
||||
.DisableAntiforgery()
|
||||
.WithDescription("Upload supporting evidence file to S3 and register metadata (M14)")
|
||||
.WithName(typeof(UploadEvidenceFilesEndpoint).ToEndpointName())
|
||||
.WithName(typeof(CreateEvidenceEndpoint).ToEndpointName())
|
||||
.MapToApiVersion(new ApiVersion(1))
|
||||
.Produces(StatusCodes.Status200OK)
|
||||
.Produces<Problems>(StatusCodes.Status400BadRequest)
|
||||
@@ -0,0 +1,36 @@
|
||||
using PostFundManagement.Application.Extensions;
|
||||
using PostFundManagement.Application.Services.Evidence;
|
||||
using PostFundManagement.Domain.Abstractions;
|
||||
using PostFundManagement.Domain.Errors;
|
||||
using PostFundManagement.Domain.Extensions;
|
||||
using PostFundManagement.Domain.Security;
|
||||
using Problems = Microsoft.AspNetCore.Mvc.ProblemDetails;
|
||||
|
||||
namespace PostFundManagement.Api.Endpoints.Evidence;
|
||||
|
||||
[ApiVersionTarget(1)]
|
||||
public sealed class UpdateEvidenceEndpoint : IEndpoint
|
||||
{
|
||||
public void Map(IEndpointRouteBuilder builder)
|
||||
{
|
||||
builder.MapPut("api/evidence", async (UpdateEvidenceRequest request, HttpContext context, EvidenceService service,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
await service.UpdateEvidenceAsync(request, context.GetUserId(), cancellationToken) switch
|
||||
{
|
||||
{ IsSuccess: true } => Results.Ok(),
|
||||
var r when r.HasError<IdDecodeError>() => Results.Forbid(),
|
||||
var r when r.HasError<UpdateError>() => Results.BadRequest(r.Errors.ToProblems()),
|
||||
var r => Results.InternalServerError(r.Errors.ToProblems())
|
||||
})
|
||||
.WithDescription("Updates a specific evidence record metadata")
|
||||
.WithName(typeof(UpdateEvidenceEndpoint).ToEndpointName())
|
||||
.MapToApiVersion(new ApiVersion(1))
|
||||
.Produces<Domain.Models.Evidence>(StatusCodes.Status200OK)
|
||||
.Produces(StatusCodes.Status404NotFound)
|
||||
.Produces(StatusCodes.Status403Forbidden)
|
||||
.Produces(StatusCodes.Status401Unauthorized)
|
||||
.Produces<Problems>(StatusCodes.Status400BadRequest)
|
||||
.Produces<Problems>(StatusCodes.Status500InternalServerError)
|
||||
.WithTags(EndpointTags.Evidence);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using Problems = Microsoft.AspNetCore.Mvc.ProblemDetails;
|
||||
namespace PostFundManagement.Api.Endpoints.Governance;
|
||||
|
||||
[ApiVersionTarget(1)]
|
||||
public class CreateOrganisationEndpoint : IEndpoint
|
||||
public sealed class CreateOrganisationEndpoint : IEndpoint
|
||||
{
|
||||
public void Map(IEndpointRouteBuilder builder)
|
||||
{
|
||||
|
||||
+3
-3
@@ -10,13 +10,13 @@ using Problems = Microsoft.AspNetCore.Mvc.ProblemDetails;
|
||||
namespace PostFundManagement.Api.Endpoints.Governance;
|
||||
|
||||
[ApiVersionTarget(1)]
|
||||
public class GetOrganisationByIdEndpoint : IEndpoint
|
||||
public class GetOrganisationEndpoint : IEndpoint
|
||||
{
|
||||
public void Map(IEndpointRouteBuilder builder)
|
||||
{
|
||||
builder.MapGet("api/governance/organisations/{organisationId}", async (string organisationId,
|
||||
GovernanceService service, CancellationToken cancellationToken = default) =>
|
||||
await service.GetOrganisationByIdAsync(organisationId, cancellationToken) switch
|
||||
await service.GetOrganisationAsync(organisationId, cancellationToken) switch
|
||||
{
|
||||
{ IsSuccess: true, Value: var organisation } => Results.Ok(organisationId),
|
||||
var r when r.HasError<IdDecodeError>() => Results.Forbid(),
|
||||
@@ -24,7 +24,7 @@ public class GetOrganisationByIdEndpoint : IEndpoint
|
||||
var r => Results.InternalServerError(r.Errors.ToProblems())
|
||||
})
|
||||
.WithDescription("Get organization profile by ID")
|
||||
.WithName(typeof(GetOrganisationByIdEndpoint).ToEndpointName())
|
||||
.WithName(typeof(GetOrganisationEndpoint).ToEndpointName())
|
||||
.MapToApiVersion(new ApiVersion(1))
|
||||
.Produces<Organisation>(StatusCodes.Status200OK)
|
||||
.Produces(StatusCodes.Status404NotFound)
|
||||
@@ -0,0 +1,34 @@
|
||||
using PostFundManagement.Application.Extensions;
|
||||
using PostFundManagement.Application.Services.Governance;
|
||||
using PostFundManagement.Domain.Abstractions;
|
||||
using PostFundManagement.Domain.Errors;
|
||||
using PostFundManagement.Domain.Extensions;
|
||||
using PostFundManagement.Domain.Security;
|
||||
using Problems = Microsoft.AspNetCore.Mvc.ProblemDetails;
|
||||
|
||||
namespace PostFundManagement.Api.Endpoints.Governance;
|
||||
|
||||
[ApiVersionTarget(1)]
|
||||
public sealed class UpdateOrganisationEndpoint : IEndpoint
|
||||
{
|
||||
public void Map(IEndpointRouteBuilder builder)
|
||||
{
|
||||
builder.MapPut("api/governance/organisations", async (UpdateOrganisationRequest request,
|
||||
GovernanceService service, CancellationToken cancellationToken = default) =>
|
||||
await service.UpdateOrganisationAsync(request, cancellationToken) switch
|
||||
{
|
||||
{ IsSuccess: true } => Results.Ok(),
|
||||
var r when r.HasError<UpdateError>() => Results.BadRequest(r.Errors.ToProblems()),
|
||||
var r => Results.InternalServerError(r.Errors.ToProblems())
|
||||
})
|
||||
.WithDescription("Update an existing organization profile")
|
||||
.WithName(typeof(UpdateOrganisationEndpoint).ToEndpointName())
|
||||
.MapToApiVersion(new ApiVersion(1))
|
||||
.Produces(StatusCodes.Status200OK)
|
||||
.Produces(StatusCodes.Status404NotFound)
|
||||
.Produces<Problems>(StatusCodes.Status400BadRequest)
|
||||
.Produces<Problems>(StatusCodes.Status500InternalServerError)
|
||||
.Produces(StatusCodes.Status401Unauthorized)
|
||||
.WithTags(EndpointTags.Governance);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace PostFundManagement.Application.Services.Evidence;
|
||||
public sealed class EvidenceService(IDbContextFactory<ApplicationDbContext> contextFactory, HashService hashService,
|
||||
[FromKeyedServices(Constants.EvidenceBucketName)] IS3Service s3Service) : IService
|
||||
{
|
||||
public async ValueTask<Result> UploadEvidenceFileAsync(Guid userId, IFormCollection form, IFormFile file, CancellationToken cancellationToken = default) =>
|
||||
public async ValueTask<Result> CreateEvidenceAsync(Guid userId, IFormCollection form, IFormFile file, CancellationToken cancellationToken = default) =>
|
||||
await Result.Try((Func<ValueTask<Result>>)(async () =>
|
||||
{
|
||||
if (!long.TryParse(form["projectId"], out var projectId) || !long.TryParse(form["milestoneId"], out var milestoneId) ||
|
||||
@@ -216,4 +216,9 @@ public sealed class EvidenceService(IDbContextFactory<ApplicationDbContext> cont
|
||||
|
||||
return Result.Ok(evidences.Select(e => e.Map()).ToArray());
|
||||
}));
|
||||
|
||||
public async Task<Result> UpdateEvidenceAsync(UpdateEvidenceRequest request, Guid userId, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace PostFundManagement.Application.Services.Evidence;
|
||||
|
||||
public record UpdateEvidenceRequest(long EvidenceId, int Version, EvidenceType EvidenceType, ApprovalStatus Status);
|
||||
|
||||
public record RecordActualRequest(decimal ActualAmount);
|
||||
|
||||
public record CreateMilestoneRequest(long ProjectId, DateTime DueAt, string Name, Priority Priority);
|
||||
|
||||
@@ -44,7 +44,7 @@ public sealed class GovernanceService(IDbContextFactory<ApplicationDbContext> co
|
||||
return Result.Ok(organisations.Select(o => o.Map()).ToArray());
|
||||
}));
|
||||
|
||||
public async ValueTask<Result<Organisation>> GetOrganisationByIdAsync(string organisationIdHash, CancellationToken cancellationToken = default) =>
|
||||
public async ValueTask<Result<Organisation>> GetOrganisationAsync(string organisationIdHash, CancellationToken cancellationToken = default) =>
|
||||
await Result.Try((Func<ValueTask<Result<Organisation>>>)(async () =>
|
||||
{
|
||||
var decodeResult = hashService.DecodeLongIdHash(organisationIdHash);
|
||||
@@ -120,4 +120,20 @@ public sealed class GovernanceService(IDbContextFactory<ApplicationDbContext> co
|
||||
|
||||
return Result.FailIf(await context.SaveChangesAsync(cancellationToken) <= 0, CreateError.New);
|
||||
}));
|
||||
|
||||
public async ValueTask<Result<Organisation>> UpdateOrganisationAsync(UpdateOrganisationRequest request, CancellationToken cancellationToken = default) =>
|
||||
await Result.Try((Func<ValueTask<Result<Organisation>>>)(async () =>
|
||||
{
|
||||
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
var changedTotal = await context.Organisations
|
||||
.Where(f => f.Id == request.OrganisationId)
|
||||
.ExecuteUpdateAsync(f => f
|
||||
.SetProperty(u => u.Name, request.Name)
|
||||
.SetProperty(u => u.RegistrationNo, request.RegistrationNo)
|
||||
.SetProperty(u => u.Email, request.Email)
|
||||
.SetProperty(u => u.Type, request.Type), cancellationToken);
|
||||
|
||||
return Result.FailIf(changedTotal <= 0, UpdateError.New);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace PostFundManagement.Application.Services.Governance;
|
||||
|
||||
public record UpdateOrganisationRequest(long OrganisationId, string Name, string RegistrationNo, string Email, OrganisationType Type);
|
||||
|
||||
public record CreateOrganisationRequest(string Name, string RegistrationNo, string Email, OrganisationType Type);
|
||||
|
||||
public record Dashboard(decimal PortfolioValue, int ActiveAwards, decimal Disbursed, double OnTrackPercentage, int AtRiskCount, int BeneficiariesReached);
|
||||
|
||||
Reference in New Issue
Block a user