Refactored Communications and Evidence endpoints
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using PostFundManagement.Application.Communications;
|
||||||
|
using PostFundManagement.Domain;
|
||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using PostFundManagement.Domain.Api;
|
using PostFundManagement.Domain.Api;
|
||||||
using PostFundManagement.Domain.Extensions;
|
using PostFundManagement.Domain.Extensions;
|
||||||
using PostFundManagement.Infrastructure.Database;
|
using PostFundManagement.Domain.Models;
|
||||||
|
using static PostFundManagement.Domain.Extensions.General;
|
||||||
|
|
||||||
namespace PostFundManagement.Api.Endpoints.Communications;
|
namespace PostFundManagement.Api.Endpoints.Communications;
|
||||||
|
|
||||||
@@ -10,31 +14,20 @@ public class GetInvitesEndpoint : IEndpoint
|
|||||||
{
|
{
|
||||||
public void Map(IEndpointRouteBuilder builder)
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
builder.MapGet("api/communications/invites", async (IDbContextFactory<ApplicationDbContext> contextFactory,
|
builder.MapGet("api/communications/invites/{page:int}/{pageSize:int}", async (CommunicationsService service, int page = 1, int pageSize = 100,
|
||||||
int page = 1, int pageSize = 10, CancellationToken cancellationToken = default) =>
|
CancellationToken cancellationToken = default) =>
|
||||||
{
|
{
|
||||||
if (page < 1) page = 1;
|
var result = await service.GetInvitesAsync(new Pagination { Page = page, PageSize = pageSize }, cancellationToken);
|
||||||
if (pageSize < 1) pageSize = 10;
|
|
||||||
if (pageSize > 100) pageSize = 100;
|
|
||||||
|
|
||||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
return result.IsSuccess
|
||||||
|
? Results.Ok(result.Value)
|
||||||
var query = context.Invites.AsNoTracking();
|
: Results.BadRequest(result.Errors.ToProblems("Failed to get invites"));
|
||||||
|
|
||||||
var totalCount = await query.CountAsync(cancellationToken);
|
|
||||||
|
|
||||||
var items = await query.OrderByDescending(i => i.CreatedAt)
|
|
||||||
.Skip((page - 1) * pageSize)
|
|
||||||
.Take(pageSize)
|
|
||||||
.ToListAsync(cancellationToken);
|
|
||||||
|
|
||||||
return Results.Ok(new { Items = items, TotalCount = totalCount, Page = page, PageSize = pageSize });
|
|
||||||
})
|
})
|
||||||
.RequireAuthorization()
|
.RequireAuthorization()
|
||||||
.WithDescription("Get a list of sent invitations")
|
.WithDescription("Get a list of sent invitations")
|
||||||
.WithName(typeof(GetInvitesEndpoint).ToEndpointName())
|
.WithName(typeof(GetInvitesEndpoint).ToEndpointName())
|
||||||
.MapToApiVersion(new ApiVersion(1))
|
.MapToApiVersion(new ApiVersion(1))
|
||||||
.Produces(StatusCodes.Status200OK)
|
.Produces<Invite[]>(StatusCodes.Status200OK)
|
||||||
.Produces(StatusCodes.Status401Unauthorized)
|
.Produces(StatusCodes.Status401Unauthorized)
|
||||||
.WithTags(EndpointTags.Communications);
|
.WithTags(EndpointTags.Communications);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +1,23 @@
|
|||||||
using PostFundManagement.Domain;
|
using PostFundManagement.Application.Communications;
|
||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using PostFundManagement.Domain.Api;
|
using PostFundManagement.Domain.Api;
|
||||||
using PostFundManagement.Domain.Extensions;
|
using PostFundManagement.Domain.Extensions;
|
||||||
using PostFundManagement.Infrastructure.Database;
|
|
||||||
|
|
||||||
namespace PostFundManagement.Api.Endpoints.Communications;
|
namespace PostFundManagement.Api.Endpoints.Communications;
|
||||||
|
|
||||||
[ApiVersionTarget(1)]
|
[ApiVersionTarget(1)]
|
||||||
public class SendInviteEndpoint : IEndpoint
|
public class SendInviteEndpoint : IEndpoint
|
||||||
{
|
{
|
||||||
public record InviteRequest(long OrganisationId, long InvitedOrganisationId, long AwardId, long ContractId, Guid Recipient, string Message, NotificationPlatform Platform);
|
|
||||||
|
|
||||||
public void Map(IEndpointRouteBuilder builder)
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
builder.MapPost("api/communications/invite", async (InviteRequest request, ClaimsPrincipal principal,
|
builder.MapPost("api/communications/invite", async (InviteRequest request, ClaimsPrincipal principal,
|
||||||
IDbContextFactory<ApplicationDbContext> contextFactory, CancellationToken cancellationToken = default) =>
|
CommunicationsService service, CancellationToken cancellationToken = default) =>
|
||||||
{
|
{
|
||||||
var sidClaim = principal.FindFirst("sid")?.Value ?? principal.FindFirst(ClaimTypes.Sid)?.Value;
|
var result = await service.SendInviteAsync(request, principal, cancellationToken);
|
||||||
|
|
||||||
if (!Guid.TryParse(sidClaim, out var currentUserId))
|
return result.IsSuccess
|
||||||
return Results.BadRequest("Missing or invalid 'sid' claim.");
|
? Results.Ok(result.Value)
|
||||||
|
: Results.BadRequest(result.Errors.ToProblems("Failed to create invite"));
|
||||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
|
||||||
|
|
||||||
var invite = new Domain.Entities.Invite
|
|
||||||
{
|
|
||||||
OrganisationId = request.OrganisationId,
|
|
||||||
InvitedOrganisationId = request.InvitedOrganisationId,
|
|
||||||
AwardId = request.AwardId,
|
|
||||||
ContractId = request.ContractId,
|
|
||||||
Recipient = request.Recipient,
|
|
||||||
CreatedBy = currentUserId,
|
|
||||||
CreatedAt = DateTime.UtcNow
|
|
||||||
};
|
|
||||||
|
|
||||||
context.Invites.Add(invite);
|
|
||||||
|
|
||||||
context.Notifications.Add(new Domain.Entities.Notification
|
|
||||||
{
|
|
||||||
OrganisationId = request.OrganisationId,
|
|
||||||
Recipient = request.Recipient,
|
|
||||||
Platform = request.Platform,
|
|
||||||
Status = NotificationStatus.Pending,
|
|
||||||
Subject = "Invitation to Onboard",
|
|
||||||
Message = request.Message,
|
|
||||||
CreatedAt = DateTime.UtcNow
|
|
||||||
});
|
|
||||||
|
|
||||||
return await context.SaveChangesAsync(cancellationToken) > 0
|
|
||||||
? Results.Ok(invite)
|
|
||||||
: Results.BadRequest("Failed to create invite");
|
|
||||||
})
|
})
|
||||||
.RequireAuthorization()
|
.RequireAuthorization()
|
||||||
.WithDescription("Trigger an invite to an organization or candidate (specifying NotificationPlatform)")
|
.WithDescription("Trigger an invite to an organization or candidate (specifying NotificationPlatform)")
|
||||||
|
|||||||
+5
-19
@@ -1,41 +1,27 @@
|
|||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using PostFundManagement.Domain.Api;
|
using PostFundManagement.Domain.Api;
|
||||||
|
using PostFundManagement.Domain.Events.Communications;
|
||||||
using PostFundManagement.Domain.Extensions;
|
using PostFundManagement.Domain.Extensions;
|
||||||
|
|
||||||
namespace PostFundManagement.Api.Endpoints.Communications;
|
namespace PostFundManagement.Api.Endpoints.Communications;
|
||||||
|
|
||||||
public class SyncEvent : EventBase, IEvent
|
|
||||||
{
|
|
||||||
public string Name { get; set; } = nameof(SyncEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SyncEventHandler : INotificationHandler<SyncEvent>
|
|
||||||
{
|
|
||||||
public ValueTask Handle(SyncEvent notification, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
Trace.WriteLine($"Integration Sync executed. Correlation ID: {notification.CorrelationId}");
|
|
||||||
|
|
||||||
return ValueTask.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[ApiVersionTarget(1)]
|
[ApiVersionTarget(1)]
|
||||||
public class SyncEndpoint : IEndpoint
|
public class SyncUserEndpoint : IEndpoint
|
||||||
{
|
{
|
||||||
public void Map(IEndpointRouteBuilder builder)
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
builder.MapPost("api/integration/sync", async (IJobOrchestrator jobOrchestrator,
|
builder.MapPost("api/integration/sync", async (IJobOrchestrator jobOrchestrator,
|
||||||
CancellationToken cancellationToken = default) =>
|
CancellationToken cancellationToken = default) =>
|
||||||
{
|
{
|
||||||
var syncEvent = new SyncEvent();
|
var syncEvent = new SyncUserEvent();
|
||||||
|
|
||||||
await jobOrchestrator.SendAsync(syncEvent, cancellationToken);
|
await jobOrchestrator.SendAsync(syncEvent, cancellationToken);
|
||||||
|
|
||||||
return Results.Ok(new { Queued = true, syncEvent.CorrelationId });
|
return Results.Ok();
|
||||||
})
|
})
|
||||||
.RequireAuthorization()
|
.RequireAuthorization()
|
||||||
.WithDescription("Trigger integration and data synchronization in the background")
|
.WithDescription("Trigger integration and data synchronization in the background")
|
||||||
.WithName(typeof(SyncEndpoint).ToEndpointName())
|
.WithName(typeof(SyncUserEndpoint).ToEndpointName())
|
||||||
.MapToApiVersion(new ApiVersion(1))
|
.MapToApiVersion(new ApiVersion(1))
|
||||||
.Produces(StatusCodes.Status200OK)
|
.Produces(StatusCodes.Status200OK)
|
||||||
.Produces(StatusCodes.Status401Unauthorized)
|
.Produces(StatusCodes.Status401Unauthorized)
|
||||||
@@ -1,54 +1,30 @@
|
|||||||
using PostFundManagement.Domain;
|
using PostFundManagement.Application.Evidence;
|
||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using PostFundManagement.Domain.Api;
|
using PostFundManagement.Domain.Api;
|
||||||
using PostFundManagement.Domain.Extensions;
|
using PostFundManagement.Domain.Extensions;
|
||||||
using PostFundManagement.Infrastructure.Database;
|
using PostFundManagement.Domain.Models;
|
||||||
|
|
||||||
namespace PostFundManagement.Api.Endpoints.Evidence;
|
namespace PostFundManagement.Api.Endpoints.Evidence;
|
||||||
|
|
||||||
[ApiVersionTarget(1)]
|
[ApiVersionTarget(1)]
|
||||||
public class CreateIndicatorEndpoint : IEndpoint
|
public class CreateIndicatorEndpoint : IEndpoint
|
||||||
{
|
{
|
||||||
public record CreateIndicatorRequest(long ProjectId, string Name, UnitOfMeasure UnitOfMeasure, decimal BaselineAmount, decimal TargetAmount);
|
|
||||||
|
|
||||||
public void Map(IEndpointRouteBuilder builder)
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
builder.MapPost("api/evidence/indicators", async (CreateIndicatorRequest request, ClaimsPrincipal principal,
|
builder.MapPost("api/evidence/indicators", async (CreateIndicatorRequest request, ClaimsPrincipal principal,
|
||||||
IDbContextFactory<ApplicationDbContext> contextFactory, CancellationToken cancellationToken = default) =>
|
EvidenceService service, CancellationToken cancellationToken = default) =>
|
||||||
{
|
{
|
||||||
var sidClaim = principal.FindFirst("sid")?.Value ?? principal.FindFirst(ClaimTypes.Sid)?.Value;
|
var result = await service.CreateIndicatorAsync(request, principal, cancellationToken);
|
||||||
|
|
||||||
if (!Guid.TryParse(sidClaim, out var userId))
|
return result.IsSuccess
|
||||||
return Results.BadRequest("Missing or invalid 'sid' claim.");
|
? Results.Created($"api/evidence/indicators/{result.Value.Id}", result.Value.Indicator)
|
||||||
|
: Results.BadRequest(result.Errors.ToProblems("Failed to create indicator"));
|
||||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
|
||||||
|
|
||||||
if (!await context.Projects.AnyAsync(p => p.Id == request.ProjectId, cancellationToken))
|
|
||||||
return Results.BadRequest($"Project with ID {request.ProjectId} does not exist.");
|
|
||||||
|
|
||||||
var indicator = new Domain.Entities.Indicator
|
|
||||||
{
|
|
||||||
ProjectId = request.ProjectId,
|
|
||||||
Name = request.Name,
|
|
||||||
UnitOfMeasure = request.UnitOfMeasure,
|
|
||||||
BaselineAmount = request.BaselineAmount,
|
|
||||||
TargetAmount = request.TargetAmount,
|
|
||||||
ActualAmount = request.BaselineAmount,
|
|
||||||
CreatedBy = userId,
|
|
||||||
CreatedAt = DateTime.UtcNow
|
|
||||||
};
|
|
||||||
|
|
||||||
context.Indicators.Add(indicator);
|
|
||||||
|
|
||||||
return await context.SaveChangesAsync(cancellationToken) > 0
|
|
||||||
? Results.Created($"api/evidence/indicators/{indicator.Id}", indicator)
|
|
||||||
: Results.BadRequest("Failed to create indicator");
|
|
||||||
})
|
})
|
||||||
.RequireAuthorization()
|
.RequireAuthorization()
|
||||||
.WithDescription("Define indicators and baselines/targets (M08)")
|
.WithDescription("Define indicators and baselines/targets (M08)")
|
||||||
.WithName(typeof(CreateIndicatorEndpoint).ToEndpointName())
|
.WithName(typeof(CreateIndicatorEndpoint).ToEndpointName())
|
||||||
.MapToApiVersion(new ApiVersion(1))
|
.MapToApiVersion(new ApiVersion(1))
|
||||||
.Produces<PostFundManagement.Domain.Entities.Indicator>(StatusCodes.Status201Created)
|
.Produces<Indicator>(StatusCodes.Status201Created)
|
||||||
.Produces(StatusCodes.Status400BadRequest)
|
.Produces(StatusCodes.Status400BadRequest)
|
||||||
.Produces(StatusCodes.Status401Unauthorized)
|
.Produces(StatusCodes.Status401Unauthorized)
|
||||||
.WithTags(EndpointTags.Evidence);
|
.WithTags(EndpointTags.Evidence);
|
||||||
|
|||||||
@@ -1,53 +1,30 @@
|
|||||||
using PostFundManagement.Domain;
|
using PostFundManagement.Application.Evidence;
|
||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using PostFundManagement.Domain.Api;
|
using PostFundManagement.Domain.Api;
|
||||||
using PostFundManagement.Domain.Extensions;
|
using PostFundManagement.Domain.Extensions;
|
||||||
using PostFundManagement.Infrastructure.Database;
|
using PostFundManagement.Domain.Models;
|
||||||
|
|
||||||
namespace PostFundManagement.Api.Endpoints.Evidence;
|
namespace PostFundManagement.Api.Endpoints.Evidence;
|
||||||
|
|
||||||
[ApiVersionTarget(1)]
|
[ApiVersionTarget(1)]
|
||||||
public class CreateMilestoneEndpoint : IEndpoint
|
public class CreateMilestoneEndpoint : IEndpoint
|
||||||
{
|
{
|
||||||
public record CreateMilestoneRequest(long ProjectId, DateTime DueAt, string Name, Priority Priority);
|
|
||||||
|
|
||||||
public void Map(IEndpointRouteBuilder builder)
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
builder.MapPost("api/evidence/milestones", async (CreateMilestoneRequest request, ClaimsPrincipal principal,
|
builder.MapPost("api/evidence/milestones", async (CreateMilestoneRequest request, ClaimsPrincipal principal,
|
||||||
IDbContextFactory<ApplicationDbContext> contextFactory, CancellationToken cancellationToken = default) =>
|
EvidenceService service, CancellationToken cancellationToken = default) =>
|
||||||
{
|
{
|
||||||
var sidClaim = principal.FindFirst("sid")?.Value ?? principal.FindFirst(ClaimTypes.Sid)?.Value;
|
var result = await service.CreateMilestoneAsync(request, principal, cancellationToken);
|
||||||
|
|
||||||
if (!Guid.TryParse(sidClaim, out var userId))
|
return result.IsSuccess
|
||||||
return Results.BadRequest("Missing or invalid 'sid' claim.");
|
? Results.Created($"api/evidence/milestones/{result.Value.Id}", result.Value.Milestone)
|
||||||
|
: Results.BadRequest(result.Errors.ToProblems("Failed to create a new milestone"));
|
||||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
|
||||||
|
|
||||||
if (!await context.Projects.AnyAsync(p => p.Id == request.ProjectId, cancellationToken))
|
|
||||||
return Results.BadRequest($"Project with ID {request.ProjectId} does not exist.");
|
|
||||||
|
|
||||||
var milestone = new Domain.Entities.Milestone
|
|
||||||
{
|
|
||||||
ProjectId = request.ProjectId,
|
|
||||||
DueAt = request.DueAt,
|
|
||||||
Name = request.Name,
|
|
||||||
Priority = request.Priority,
|
|
||||||
Status = ApprovalStatus.Pending,
|
|
||||||
CreatedBy = userId,
|
|
||||||
CreatedAt = DateTime.UtcNow
|
|
||||||
};
|
|
||||||
|
|
||||||
context.Milestones.Add(milestone);
|
|
||||||
|
|
||||||
return await context.SaveChangesAsync(cancellationToken) > 0
|
|
||||||
? Results.Created($"api/evidence/milestones/{milestone.Id}", milestone)
|
|
||||||
: Results.BadRequest("Failed to create a new milestone");
|
|
||||||
})
|
})
|
||||||
.RequireAuthorization()
|
.RequireAuthorization()
|
||||||
.WithDescription("Define contractual milestones (M07)")
|
.WithDescription("Define contractual milestones (M07)")
|
||||||
.WithName(typeof(CreateMilestoneRequest).ToEndpointName())
|
.WithName(typeof(CreateMilestoneRequest).ToEndpointName())
|
||||||
.MapToApiVersion(new ApiVersion(1))
|
.MapToApiVersion(new ApiVersion(1))
|
||||||
.Produces<Domain.Entities.Milestone>(StatusCodes.Status201Created)
|
.Produces<Milestone>(StatusCodes.Status201Created)
|
||||||
.Produces(StatusCodes.Status400BadRequest)
|
.Produces(StatusCodes.Status400BadRequest)
|
||||||
.Produces(StatusCodes.Status401Unauthorized)
|
.Produces(StatusCodes.Status401Unauthorized)
|
||||||
.WithTags(EndpointTags.Evidence);
|
.WithTags(EndpointTags.Evidence);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
using PostFundManagement.Application.Evidence;
|
||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using PostFundManagement.Domain.Api;
|
using PostFundManagement.Domain.Api;
|
||||||
using PostFundManagement.Domain.Extensions;
|
using PostFundManagement.Domain.Extensions;
|
||||||
using PostFundManagement.Infrastructure.Database;
|
|
||||||
|
|
||||||
namespace PostFundManagement.Api.Endpoints.Evidence;
|
namespace PostFundManagement.Api.Endpoints.Evidence;
|
||||||
|
|
||||||
@@ -10,31 +10,19 @@ public class GetEvidenceFilesEndpoint : IEndpoint
|
|||||||
{
|
{
|
||||||
public void Map(IEndpointRouteBuilder builder)
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
builder.MapGet("api/evidence/files", async (IDbContextFactory<ApplicationDbContext> contextFactory,
|
builder.MapGet("api/evidence/files/{page:int}/{pageSize:int}", async (EvidenceService service, int page = 1, int pageSize = 100, CancellationToken cancellationToken = default) =>
|
||||||
int page = 1, int pageSize = 10, CancellationToken cancellationToken = default) =>
|
|
||||||
{
|
{
|
||||||
if (page < 1) page = 1;
|
var result = await service.GetEvidenceFilesAsync(new Domain.Pagination(page, pageSize), cancellationToken);
|
||||||
if (pageSize < 1) pageSize = 10;
|
|
||||||
if (pageSize > 100) pageSize = 100;
|
|
||||||
|
|
||||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
return result.IsSuccess
|
||||||
|
? Results.Ok(result.Value)
|
||||||
var query = context.Evidences.AsNoTracking();
|
: Results.BadRequest(result.Errors.ToProblems("Failed to get evidence"));
|
||||||
|
|
||||||
var totalCount = await query.CountAsync(cancellationToken);
|
|
||||||
|
|
||||||
var items = await query.OrderByDescending(e => e.CreatedAt)
|
|
||||||
.Skip((page - 1) * pageSize)
|
|
||||||
.Take(pageSize)
|
|
||||||
.ToListAsync(cancellationToken);
|
|
||||||
|
|
||||||
return Results.Ok(new { Items = items, TotalCount = totalCount, Page = page, PageSize = pageSize });
|
|
||||||
})
|
})
|
||||||
.RequireAuthorization()
|
.RequireAuthorization()
|
||||||
.WithDescription("Get a list of all uploaded evidence files metadata")
|
.WithDescription("Get a list of all uploaded evidence files metadata")
|
||||||
.WithName(typeof(GetEvidenceFilesEndpoint).ToEndpointName())
|
.WithName(typeof(GetEvidenceFilesEndpoint).ToEndpointName())
|
||||||
.MapToApiVersion(new ApiVersion(1))
|
.MapToApiVersion(new ApiVersion(1))
|
||||||
.Produces(StatusCodes.Status200OK)
|
.Produces<Domain.Models.Evidence[]>(StatusCodes.Status200OK)
|
||||||
.Produces(StatusCodes.Status401Unauthorized)
|
.Produces(StatusCodes.Status401Unauthorized)
|
||||||
.WithTags(EndpointTags.Evidence);
|
.WithTags(EndpointTags.Evidence);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,29 @@
|
|||||||
|
using PostFundManagement.Application.Evidence;
|
||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using PostFundManagement.Domain.Api;
|
using PostFundManagement.Domain.Api;
|
||||||
using PostFundManagement.Domain.Extensions;
|
using PostFundManagement.Domain.Extensions;
|
||||||
using PostFundManagement.Infrastructure.Database;
|
using PostFundManagement.Domain.Models;
|
||||||
|
|
||||||
namespace PostFundManagement.Api.Endpoints.Evidence;
|
namespace PostFundManagement.Api.Endpoints.Evidence;
|
||||||
|
|
||||||
[ApiVersionTarget(1)]
|
[ApiVersionTarget(1)]
|
||||||
public class GetIndicatorsEndpoint : IEndpoint
|
public class GetIndicatorsEndpoint : IEndpoint
|
||||||
{
|
{
|
||||||
public record RecordActualRequest(decimal ActualAmount);
|
|
||||||
|
|
||||||
public void Map(IEndpointRouteBuilder builder)
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
builder.MapGet("api/evidence/indicators", async (IDbContextFactory<ApplicationDbContext> contextFactory,
|
builder.MapGet("api/evidence/indicators/{page:int}/{pageSize:int}", async (EvidenceService service, int page = 1, int pageSize = 100, CancellationToken cancellationToken = default) =>
|
||||||
int page = 1, int pageSize = 10, CancellationToken cancellationToken = default) =>
|
|
||||||
{
|
{
|
||||||
if (page < 1) page = 1;
|
var result = await service.GetIndicatorsAsync(new Domain.Pagination { Page = page, PageSize = pageSize }, cancellationToken);
|
||||||
if (pageSize < 1) pageSize = 10;
|
|
||||||
if (pageSize > 100) pageSize = 100;
|
|
||||||
|
|
||||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
return result.IsSuccess
|
||||||
|
? Results.Ok(result.Value)
|
||||||
var query = context.Indicators.AsNoTracking();
|
: Results.BadRequest(result.Errors.ToProblems("Failed to get indicators"));
|
||||||
|
|
||||||
var totalCount = await query.CountAsync(cancellationToken);
|
|
||||||
|
|
||||||
var items = await query.OrderByDescending(i => i.CreatedAt)
|
|
||||||
.Skip((page - 1) * pageSize)
|
|
||||||
.Take(pageSize)
|
|
||||||
.ToListAsync(cancellationToken);
|
|
||||||
|
|
||||||
return Results.Ok(new { Items = items, TotalCount = totalCount, Page = page, PageSize = pageSize });
|
|
||||||
})
|
})
|
||||||
.RequireAuthorization()
|
.RequireAuthorization()
|
||||||
.WithDescription("Get a list of indicators")
|
.WithDescription("Get a list of indicators")
|
||||||
.WithName(typeof(GetIndicatorsEndpoint).ToEndpointName())
|
.WithName(typeof(GetIndicatorsEndpoint).ToEndpointName())
|
||||||
.MapToApiVersion(new ApiVersion(1))
|
.MapToApiVersion(new ApiVersion(1))
|
||||||
.Produces(StatusCodes.Status200OK)
|
.Produces<Indicator[]>(StatusCodes.Status200OK)
|
||||||
.Produces(StatusCodes.Status401Unauthorized)
|
.Produces(StatusCodes.Status401Unauthorized)
|
||||||
.WithTags(EndpointTags.Evidence);
|
.WithTags(EndpointTags.Evidence);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
using PostFundManagement.Application.Evidence;
|
||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using PostFundManagement.Domain.Api;
|
using PostFundManagement.Domain.Api;
|
||||||
|
using PostFundManagement.Domain.Models;
|
||||||
using PostFundManagement.Domain.Extensions;
|
using PostFundManagement.Domain.Extensions;
|
||||||
using PostFundManagement.Infrastructure.Database;
|
|
||||||
|
|
||||||
namespace PostFundManagement.Api.Endpoints.Evidence;
|
namespace PostFundManagement.Api.Endpoints.Evidence;
|
||||||
|
|
||||||
@@ -10,31 +11,20 @@ public class GetMilestonesEndpoint : IEndpoint
|
|||||||
{
|
{
|
||||||
public void Map(IEndpointRouteBuilder builder)
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
builder.MapGet("api/evidence/milestones", async (IDbContextFactory<ApplicationDbContext> contextFactory,
|
builder.MapGet("api/evidence/milestones/{page:int}/{pageSize:int}", async (EvidenceService service,
|
||||||
int page = 1, int pageSize = 10, CancellationToken cancellationToken = default) =>
|
int page = 1, int pageSize = 10, CancellationToken cancellationToken = default) =>
|
||||||
{
|
{
|
||||||
if (page < 1) page = 1;
|
var result = await service.GetMilestonesAsync(new Domain.Pagination { Page = page, PageSize = pageSize }, cancellationToken);
|
||||||
if (pageSize < 1) pageSize = 10;
|
|
||||||
if (pageSize > 100) pageSize = 100;
|
|
||||||
|
|
||||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
return result.IsSuccess
|
||||||
|
? Results.Ok(result.Value)
|
||||||
var query = context.Milestones.AsNoTracking();
|
: Results.BadRequest(result.Errors.ToProblems("Failed to fetch milestones"));
|
||||||
|
|
||||||
var totalCount = await query.CountAsync(cancellationToken);
|
|
||||||
|
|
||||||
var items = await query.OrderByDescending(m => m.CreatedAt)
|
|
||||||
.Skip((page - 1) * pageSize)
|
|
||||||
.Take(pageSize)
|
|
||||||
.ToListAsync(cancellationToken);
|
|
||||||
|
|
||||||
return Results.Ok(new { Items = items, TotalCount = totalCount, Page = page, PageSize = pageSize });
|
|
||||||
})
|
})
|
||||||
.RequireAuthorization()
|
.RequireAuthorization()
|
||||||
.WithDescription("Get a list of all milestones")
|
.WithDescription("Get a list of all milestones")
|
||||||
.WithName(typeof(GetMilestonesEndpoint).ToEndpointName())
|
.WithName(typeof(GetMilestonesEndpoint).ToEndpointName())
|
||||||
.MapToApiVersion(new ApiVersion(1))
|
.MapToApiVersion(new ApiVersion(1))
|
||||||
.Produces(StatusCodes.Status200OK)
|
.Produces<Milestone[]>(StatusCodes.Status200OK)
|
||||||
.Produces(StatusCodes.Status401Unauthorized)
|
.Produces(StatusCodes.Status401Unauthorized)
|
||||||
.WithTags(EndpointTags.Evidence);
|
.WithTags(EndpointTags.Evidence);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
using PostFundManagement.Application.Evidence;
|
||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using PostFundManagement.Domain.Api;
|
using PostFundManagement.Domain.Api;
|
||||||
|
using PostFundManagement.Domain.Configuration.Entities;
|
||||||
using PostFundManagement.Domain.Extensions;
|
using PostFundManagement.Domain.Extensions;
|
||||||
using PostFundManagement.Infrastructure.Database;
|
|
||||||
|
|
||||||
namespace PostFundManagement.Api.Endpoints.Evidence;
|
namespace PostFundManagement.Api.Endpoints.Evidence;
|
||||||
|
|
||||||
@@ -11,23 +12,21 @@ public class GetProjectMilestonesEndpoint : IEndpoint
|
|||||||
public void Map(IEndpointRouteBuilder builder)
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
builder.MapGet("api/evidence/milestones/project/{projectId:long}", async (long projectId,
|
builder.MapGet("api/evidence/milestones/project/{projectId:long}", async (long projectId,
|
||||||
IDbContextFactory<ApplicationDbContext> contextFactory, CancellationToken cancellationToken = default) =>
|
EvidenceService service, CancellationToken cancellationToken = default) =>
|
||||||
{
|
{
|
||||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
var result = await service.GetMilestonesByProjectIdAsync(projectId, cancellationToken);
|
||||||
|
|
||||||
var milestones = await context.Milestones.AsNoTracking()
|
return result.IsSuccess
|
||||||
.Where(m => m.ProjectId == projectId)
|
? Results.Ok(result.Value)
|
||||||
.OrderBy(m => m.DueAt)
|
: Results.NotFound();
|
||||||
.ToListAsync(cancellationToken);
|
|
||||||
|
|
||||||
return Results.Ok(milestones);
|
|
||||||
})
|
})
|
||||||
.RequireAuthorization()
|
.RequireAuthorization()
|
||||||
.WithDescription("Get a list of milestones for a project")
|
.WithDescription("Get a list of milestones for a project")
|
||||||
.WithName(typeof(GetProjectMilestonesEndpoint).ToEndpointName())
|
.WithName(typeof(GetProjectMilestonesEndpoint).ToEndpointName())
|
||||||
.MapToApiVersion(new ApiVersion(1))
|
.MapToApiVersion(new ApiVersion(1))
|
||||||
.Produces(StatusCodes.Status200OK)
|
.Produces<Milestone[]>(StatusCodes.Status200OK)
|
||||||
.Produces(StatusCodes.Status401Unauthorized)
|
.Produces(StatusCodes.Status401Unauthorized)
|
||||||
|
.Produces(StatusCodes.Status404NotFound)
|
||||||
.WithTags(EndpointTags.Evidence);
|
.WithTags(EndpointTags.Evidence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
using PostFundManagement.Domain.Abstractions;
|
|
||||||
using PostFundManagement.Domain.Api;
|
|
||||||
using PostFundManagement.Domain.Extensions;
|
|
||||||
using PostFundManagement.Infrastructure.Database;
|
|
||||||
|
|
||||||
namespace PostFundManagement.Api.Endpoints.Evidence;
|
|
||||||
|
|
||||||
[ApiVersionTarget(1)]
|
|
||||||
public class RecordIndicatorActualAmountEndpoint : IEndpoint
|
|
||||||
{
|
|
||||||
public void Map(IEndpointRouteBuilder builder)
|
|
||||||
{
|
|
||||||
builder.MapPost("api/evidence/indicators/{id:long}/actuals/{actualAmount:decimal}", async (long id, decimal actualAmount,
|
|
||||||
ClaimsPrincipal principal, IDbContextFactory<ApplicationDbContext> contextFactory, CancellationToken cancellationToken = default) =>
|
|
||||||
{
|
|
||||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
|
||||||
|
|
||||||
var indicator = await context.Indicators.FirstOrDefaultAsync(i => i.Id == id, cancellationToken);
|
|
||||||
|
|
||||||
if (indicator is null)
|
|
||||||
return Results.NotFound($"Indicator with ID {id} does not exist.");
|
|
||||||
|
|
||||||
indicator.ActualAmount = actualAmount;
|
|
||||||
|
|
||||||
context.Indicators.Update(indicator);
|
|
||||||
|
|
||||||
return await context.SaveChangesAsync(cancellationToken) > 0
|
|
||||||
? Results.Ok(indicator)
|
|
||||||
: Results.BadRequest("Failed to record actual amount");
|
|
||||||
})
|
|
||||||
.RequireAuthorization()
|
|
||||||
.WithDescription("Record actual values for indicators (M08)")
|
|
||||||
.WithName(typeof(RecordIndicatorActualAmountEndpoint).ToEndpointName())
|
|
||||||
.MapToApiVersion(new ApiVersion(1))
|
|
||||||
.Produces<Domain.Entities.Indicator>(StatusCodes.Status200OK)
|
|
||||||
.Produces(StatusCodes.Status404NotFound)
|
|
||||||
.Produces(StatusCodes.Status401Unauthorized)
|
|
||||||
.WithTags(EndpointTags.Evidence);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using PostFundManagement.Application.Evidence;
|
||||||
|
using PostFundManagement.Domain.Abstractions;
|
||||||
|
using PostFundManagement.Domain.Api;
|
||||||
|
using PostFundManagement.Domain.Extensions;
|
||||||
|
|
||||||
|
namespace PostFundManagement.Api.Endpoints.Evidence;
|
||||||
|
|
||||||
|
[ApiVersionTarget(1)]
|
||||||
|
public class RecordIndicatorAmountEndpoint : IEndpoint
|
||||||
|
{
|
||||||
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
|
{
|
||||||
|
builder.MapPost("api/evidence/indicators/{id:string}/actuals/{actualAmount:decimal}", async (string id, decimal actualAmount,
|
||||||
|
ClaimsPrincipal principal, EvidenceService service, CancellationToken cancellationToken = default) =>
|
||||||
|
{
|
||||||
|
var result = await service.RecordIndicatorActualAmountAsync(id, actualAmount, principal, cancellationToken);
|
||||||
|
|
||||||
|
return result.IsSuccess
|
||||||
|
? Results.Ok()
|
||||||
|
: Results.BadRequest("Failed to record actual amount");
|
||||||
|
})
|
||||||
|
.RequireAuthorization()
|
||||||
|
.WithDescription("Record actual values for indicators (M08)")
|
||||||
|
.WithName(typeof(RecordIndicatorAmountEndpoint).ToEndpointName())
|
||||||
|
.MapToApiVersion(new ApiVersion(1))
|
||||||
|
.Produces<Domain.Entities.Indicator>(StatusCodes.Status200OK)
|
||||||
|
.Produces(StatusCodes.Status404NotFound)
|
||||||
|
.Produces(StatusCodes.Status401Unauthorized)
|
||||||
|
.WithTags(EndpointTags.Evidence);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
using PostFundManagement.Domain;
|
using PostFundManagement.Application.Evidence;
|
||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using PostFundManagement.Domain.Api;
|
using PostFundManagement.Domain.Api;
|
||||||
using PostFundManagement.Domain.Extensions;
|
using PostFundManagement.Domain.Extensions;
|
||||||
using PostFundManagement.Infrastructure.Database;
|
|
||||||
|
|
||||||
namespace PostFundManagement.Api.Endpoints.Evidence;
|
namespace PostFundManagement.Api.Endpoints.Evidence;
|
||||||
|
|
||||||
@@ -11,8 +10,7 @@ public class UploadEvidenceFilesEndpoint : IEndpoint
|
|||||||
{
|
{
|
||||||
public void Map(IEndpointRouteBuilder builder)
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
{
|
{
|
||||||
builder.MapPost("api/evidence/files", async (HttpRequest request, ClaimsPrincipal principal, IDbContextFactory<ApplicationDbContext> contextFactory,
|
builder.MapPost("api/evidence/files", async (HttpRequest request, ClaimsPrincipal principal, EvidenceService service, CancellationToken cancellationToken = default) =>
|
||||||
[FromKeyedServices(Constants.EvidenceS3SettingsSection)] IS3Service s3Service, CancellationToken cancellationToken = default) =>
|
|
||||||
{
|
{
|
||||||
var sidClaim = principal.FindFirst("sid")?.Value ?? principal.FindFirst(ClaimTypes.Sid)?.Value;
|
var sidClaim = principal.FindFirst("sid")?.Value ?? principal.FindFirst(ClaimTypes.Sid)?.Value;
|
||||||
|
|
||||||
@@ -28,41 +26,10 @@ public class UploadEvidenceFilesEndpoint : IEndpoint
|
|||||||
if (file == null || file.Length == 0)
|
if (file == null || file.Length == 0)
|
||||||
return Results.BadRequest("No file uploaded or file is empty.");
|
return Results.BadRequest("No file uploaded or file is empty.");
|
||||||
|
|
||||||
_ = long.TryParse(form["projectId"], out var projectId);
|
var result = await service.UploadEvidenceFileAsync(userId, form, file, cancellationToken);
|
||||||
_ = long.TryParse(form["milestoneId"], out var milestoneId);
|
|
||||||
_ = long.TryParse(form["indicatorId"], out var indicatorId);
|
|
||||||
_ = long.TryParse(form["activityId"], out var activityId);
|
|
||||||
_ = Enum.TryParse<EvidenceType>(form["type"], out var type);
|
|
||||||
|
|
||||||
using var stream = file.OpenReadStream();
|
return result.IsSuccess
|
||||||
|
? Results.Created()
|
||||||
var uploadResult = await s3Service.UploadFileAsync(file.FileName, stream, file.ContentType, cancellationToken);
|
|
||||||
|
|
||||||
if (uploadResult.IsFailed)
|
|
||||||
return Results.BadRequest(uploadResult.Errors.FirstOrDefault()?.Message ?? "File upload failed.");
|
|
||||||
|
|
||||||
var documentUrl = uploadResult.Value;
|
|
||||||
|
|
||||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
|
||||||
|
|
||||||
var evidence = new Domain.Entities.Evidence
|
|
||||||
{
|
|
||||||
ProjectId = projectId,
|
|
||||||
MilestoneId = milestoneId,
|
|
||||||
IndicatorId = indicatorId,
|
|
||||||
ActivityId = activityId,
|
|
||||||
CreatedBy = userId,
|
|
||||||
CreatedAt = DateTime.UtcNow,
|
|
||||||
Version = 1,
|
|
||||||
Type = type,
|
|
||||||
DocumentUrl = documentUrl,
|
|
||||||
Status = ApprovalStatus.Pending
|
|
||||||
};
|
|
||||||
|
|
||||||
context.Evidences.Add(evidence);
|
|
||||||
|
|
||||||
return await context.SaveChangesAsync(cancellationToken) > 0
|
|
||||||
? Results.Created($"api/evidence/files/{evidence.Id}", evidence)
|
|
||||||
: Results.BadRequest("Evidence upload failed");
|
: Results.BadRequest("Evidence upload failed");
|
||||||
})
|
})
|
||||||
.RequireAuthorization()
|
.RequireAuthorization()
|
||||||
@@ -70,7 +37,7 @@ public class UploadEvidenceFilesEndpoint : IEndpoint
|
|||||||
.WithDescription("Upload supporting evidence file to S3 and register metadata (M14)")
|
.WithDescription("Upload supporting evidence file to S3 and register metadata (M14)")
|
||||||
.WithName(typeof(UploadEvidenceFilesEndpoint).ToEndpointName())
|
.WithName(typeof(UploadEvidenceFilesEndpoint).ToEndpointName())
|
||||||
.MapToApiVersion(new ApiVersion(1))
|
.MapToApiVersion(new ApiVersion(1))
|
||||||
.Produces<PostFundManagement.Domain.Entities.Evidence>(StatusCodes.Status201Created)
|
.Produces(StatusCodes.Status200OK)
|
||||||
.Produces(StatusCodes.Status400BadRequest)
|
.Produces(StatusCodes.Status400BadRequest)
|
||||||
.Produces(StatusCodes.Status401Unauthorized)
|
.Produces(StatusCodes.Status401Unauthorized)
|
||||||
.WithTags(EndpointTags.Evidence);
|
.WithTags(EndpointTags.Evidence);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using PostFundManagement.Domain.Api.Configuration;
|
using PostFundManagement.Domain.Api.Configuration;
|
||||||
using PostFundManagement.Domain.Extensions;
|
using PostFundManagement.Domain.Extensions;
|
||||||
using PostFundManagement.Domain.Sdk;
|
using PostFundManagement.Domain.Sdk;
|
||||||
using PostFundManagement.Domain.Services;
|
using PostFundManagement.Domain.Services.Shared;
|
||||||
using PostFundManagement.Infrastructure.Database;
|
using PostFundManagement.Infrastructure.Database;
|
||||||
|
|
||||||
namespace PostFundManagement.Api.Extensions;
|
namespace PostFundManagement.Api.Extensions;
|
||||||
|
|||||||
@@ -93,8 +93,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\PostFundManagement.Domain\PostFundManagement.Domain.csproj" />
|
<ProjectReference Include="..\PostFundManagement.Application\PostFundManagement.Application.csproj" />
|
||||||
<ProjectReference Include="..\PostFundManagement.Infrastructure\PostFundManagement.Infrastructure.csproj" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
using PostFundManagement.Domain;
|
||||||
|
using PostFundManagement.Domain.Abstractions;
|
||||||
|
using PostFundManagement.Domain.Extensions;
|
||||||
|
using PostFundManagement.Domain.Models;
|
||||||
|
using PostFundManagement.Infrastructure.Database;
|
||||||
|
|
||||||
|
namespace PostFundManagement.Application.Communications;
|
||||||
|
|
||||||
|
public sealed class CommunicationsService(IDbContextFactory<ApplicationDbContext> contextFactory) : IService
|
||||||
|
{
|
||||||
|
public async ValueTask<Result<Invite>> SendInviteAsync(InviteRequest request, ClaimsPrincipal principal, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sidClaim = principal.FindFirst("sid")?.Value ?? principal.FindFirst(ClaimTypes.Sid)?.Value;
|
||||||
|
|
||||||
|
if (!Guid.TryParse(sidClaim, out var currentUserId))
|
||||||
|
return Result.Fail("Missing or invalid 'sid' claim.");
|
||||||
|
|
||||||
|
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var invite = new Domain.Entities.Invite
|
||||||
|
{
|
||||||
|
OrganisationId = request.OrganisationId,
|
||||||
|
InvitedOrganisationId = request.InvitedOrganisationId,
|
||||||
|
AwardId = request.AwardId,
|
||||||
|
ContractId = request.ContractId,
|
||||||
|
Recipient = request.Recipient,
|
||||||
|
CreatedBy = currentUserId,
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
|
||||||
|
context.Invites.Add(invite);
|
||||||
|
|
||||||
|
context.Notifications.Add(new Domain.Entities.Notification
|
||||||
|
{
|
||||||
|
OrganisationId = request.OrganisationId,
|
||||||
|
Recipient = request.Recipient,
|
||||||
|
Platform = request.Platform,
|
||||||
|
Status = NotificationStatus.Pending,
|
||||||
|
Subject = "Invitation to Onboard",
|
||||||
|
Message = request.Message,
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
|
||||||
|
return await context.SaveChangesAsync(cancellationToken) > 0
|
||||||
|
? Result.Ok(invite.Map())
|
||||||
|
: Result.Fail("Failed to complete the insite distribution");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask<Result<Invite[]>> GetInvitesAsync(Pagination pagination, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var envites = await context.Invites.AsNoTracking()
|
||||||
|
.OrderByDescending(i => i.CreatedAt)
|
||||||
|
.Skip((pagination.Page - 1) * pagination.PageSize)
|
||||||
|
.Take(pagination.PageSize)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
return Result.Ok(envites.Select(i => i.Map()).ToArray());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using PostFundManagement.Domain.Events.Communications;
|
||||||
|
|
||||||
|
namespace PostFundManagement.Application.Communications.Events;
|
||||||
|
|
||||||
|
public class SyncUserEventHandler(ILogger<SyncUserEvent> logger) : INotificationHandler<SyncUserEvent>
|
||||||
|
{
|
||||||
|
public ValueTask Handle(SyncUserEvent notification, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
logger.LogInformation("Integration Sync executed. Correlation ID: {CorrelationId}", notification.CorrelationId);
|
||||||
|
|
||||||
|
return ValueTask.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
using PostFundManagement.Domain;
|
||||||
|
|
||||||
|
namespace PostFundManagement.Application.Communications;
|
||||||
|
|
||||||
|
public record InviteRequest(long OrganisationId, long InvitedOrganisationId, long AwardId, long ContractId, Guid Recipient, string Message, NotificationPlatform Platform);
|
||||||
@@ -0,0 +1,251 @@
|
|||||||
|
using PostFundManagement.Application.Shared;
|
||||||
|
using PostFundManagement.Domain;
|
||||||
|
using PostFundManagement.Domain.Abstractions;
|
||||||
|
using PostFundManagement.Domain.Extensions;
|
||||||
|
using PostFundManagement.Domain.Models;
|
||||||
|
using PostFundManagement.Infrastructure.Database;
|
||||||
|
|
||||||
|
namespace PostFundManagement.Application.Evidence;
|
||||||
|
|
||||||
|
public sealed class EvidenceService(IDbContextFactory<ApplicationDbContext> contextFactory, HashService hashService,
|
||||||
|
[FromKeyedServices(Constants.EvidenceS3SettingsSection)] IS3Service s3Service) : IService
|
||||||
|
{
|
||||||
|
public async ValueTask<Result> UploadEvidenceFileAsync(Guid userId, IFormCollection form, IFormFile file, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ = long.TryParse(form["projectId"], out var projectId);
|
||||||
|
_ = long.TryParse(form["milestoneId"], out var milestoneId);
|
||||||
|
_ = long.TryParse(form["indicatorId"], out var indicatorId);
|
||||||
|
_ = long.TryParse(form["activityId"], out var activityId);
|
||||||
|
_ = Enum.TryParse<EvidenceType>(form["type"], out var type);
|
||||||
|
|
||||||
|
using var stream = file.OpenReadStream();
|
||||||
|
|
||||||
|
var uploadResult = await s3Service.UploadFileAsync(file.FileName, stream, file.ContentType, cancellationToken);
|
||||||
|
|
||||||
|
if (uploadResult.IsFailed)
|
||||||
|
return Result.Fail(uploadResult.Errors.FirstOrDefault()?.Message ?? "File upload failed.");
|
||||||
|
|
||||||
|
var documentUrl = uploadResult.Value;
|
||||||
|
|
||||||
|
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var evidence = new Domain.Entities.Evidence
|
||||||
|
{
|
||||||
|
ProjectId = projectId,
|
||||||
|
MilestoneId = milestoneId,
|
||||||
|
IndicatorId = indicatorId,
|
||||||
|
ActivityId = activityId,
|
||||||
|
CreatedBy = userId,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
Version = 1,
|
||||||
|
Type = type,
|
||||||
|
DocumentUrl = documentUrl,
|
||||||
|
Status = ApprovalStatus.Pending
|
||||||
|
};
|
||||||
|
|
||||||
|
context.Evidences.Add(evidence);
|
||||||
|
|
||||||
|
return await context.SaveChangesAsync(cancellationToken) > 0
|
||||||
|
? Result.Ok()
|
||||||
|
: Result.Fail("Evidence upload failed");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask<Result> RecordIndicatorActualAmountAsync(string hash, decimal amount, ClaimsPrincipal principal, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sidClaim = principal.FindFirst("sid")?.Value ?? principal.FindFirst(ClaimTypes.Sid)?.Value;
|
||||||
|
|
||||||
|
if (!Guid.TryParse(sidClaim, out var userId))
|
||||||
|
return Result.Fail("Missing or invalid 'sid' claim.");
|
||||||
|
|
||||||
|
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var hashResult = hashService.DecodeLongIdHash(hash);
|
||||||
|
long indicatorId = 0;
|
||||||
|
|
||||||
|
if (hashResult.IsFailed)
|
||||||
|
return Result.Fail(hashResult.Errors);
|
||||||
|
|
||||||
|
var totalUpdated = await context.Indicators.Where(i => i.Id == indicatorId)
|
||||||
|
.ExecuteUpdateAsync(f => f
|
||||||
|
.SetProperty(f => f.ActualAmount, amount)
|
||||||
|
.SetProperty(f => f.CreatedBy, userId), cancellationToken);
|
||||||
|
|
||||||
|
return totalUpdated > 0
|
||||||
|
? Result.Ok()
|
||||||
|
: Result.Fail("Failed to record actual amount");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask<Result<Milestone[]>> GetMilestonesByProjectIdAsync(long projectId, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var milestones = await context.Milestones.AsNoTracking()
|
||||||
|
.Where(m => m.ProjectId == projectId)
|
||||||
|
.OrderBy(m => m.DueAt)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
return Result.Ok(milestones.Select(m => m.Map()).ToArray());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask<Result<Milestone[]>> GetMilestonesAsync(Pagination pagination, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var milestones = await context.Milestones.AsNoTracking()
|
||||||
|
.OrderByDescending(m => m.CreatedAt)
|
||||||
|
.Skip((pagination.Page - 1) * pagination.PageSize)
|
||||||
|
.Take(pagination.PageSize)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
return milestones?.Count > 0
|
||||||
|
? Result.Ok(milestones.Select(i => i.Map()).ToArray())
|
||||||
|
: Result.Ok<Milestone[]>([]);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask<Result<Indicator[]>> GetIndicatorsAsync(Pagination pagination, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var indicators = await context.Indicators.AsNoTracking()
|
||||||
|
.OrderByDescending(i => i.CreatedAt)
|
||||||
|
.Skip((pagination.Page - 1) * pagination.PageSize)
|
||||||
|
.Take(pagination.PageSize)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
return indicators?.Count > 0
|
||||||
|
? Result.Ok(indicators.Select(i => i.Map()).ToArray())
|
||||||
|
: Result.Ok<Indicator[]>([]);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask<Result<Domain.Models.Evidence[]>> GetEvidenceFilesAsync(Pagination pagination, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
var evidence = await context.Evidences.AsNoTracking()
|
||||||
|
.OrderByDescending(e => e.CreatedAt)
|
||||||
|
.Skip((pagination.Page - 1) * pagination.PageSize)
|
||||||
|
.Take(pagination.PageSize)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
return evidence?.Count > 0
|
||||||
|
? Result.Ok(evidence.Select(e => e.Map()).ToArray())
|
||||||
|
: Result.Ok<Domain.Models.Evidence[]>([]);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask<Result<(string Id, Milestone Milestone)>> CreateMilestoneAsync(CreateMilestoneRequest request, ClaimsPrincipal principal, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sidClaim = principal.FindFirst("sid")?.Value ?? principal.FindFirst(ClaimTypes.Sid)?.Value;
|
||||||
|
|
||||||
|
if (!Guid.TryParse(sidClaim, out var userId))
|
||||||
|
return Result.Fail("Missing or invalid 'sid' claim.");
|
||||||
|
|
||||||
|
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
if (!await context.Projects.AnyAsync(p => p.Id == request.ProjectId, cancellationToken))
|
||||||
|
return Result.Fail($"Project with ID {request.ProjectId} does not exist.");
|
||||||
|
|
||||||
|
var milestone = new Domain.Entities.Milestone
|
||||||
|
{
|
||||||
|
ProjectId = request.ProjectId,
|
||||||
|
DueAt = request.DueAt,
|
||||||
|
Name = request.Name,
|
||||||
|
Priority = request.Priority,
|
||||||
|
Status = ApprovalStatus.Pending,
|
||||||
|
CreatedBy = userId,
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
|
||||||
|
context.Milestones.Add(milestone);
|
||||||
|
|
||||||
|
return await context.SaveChangesAsync(cancellationToken) > 0
|
||||||
|
? Result.Ok((hashService.HashEncodeLongId(milestone.Id).Value, milestone.Map()))
|
||||||
|
: Result.Fail("Failed to create the milestone");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask<Result<(string Id, Indicator Indicator)>> CreateIndicatorAsync(CreateIndicatorRequest request, ClaimsPrincipal principal, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sidClaim = principal.FindFirst("sid")?.Value ?? principal.FindFirst(ClaimTypes.Sid)?.Value;
|
||||||
|
|
||||||
|
if (!Guid.TryParse(sidClaim, out var userId))
|
||||||
|
return Result.Fail("Missing or invalid 'sid' claim.");
|
||||||
|
|
||||||
|
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||||
|
|
||||||
|
if (!await context.Projects.AnyAsync(p => p.Id == request.ProjectId, cancellationToken))
|
||||||
|
return Result.Fail($"Project with ID {request.ProjectId} does not exist.");
|
||||||
|
|
||||||
|
var indicator = new Domain.Entities.Indicator
|
||||||
|
{
|
||||||
|
ProjectId = request.ProjectId,
|
||||||
|
Name = request.Name,
|
||||||
|
UnitOfMeasure = request.UnitOfMeasure,
|
||||||
|
BaselineAmount = request.BaselineAmount,
|
||||||
|
TargetAmount = request.TargetAmount,
|
||||||
|
ActualAmount = request.BaselineAmount,
|
||||||
|
CreatedBy = userId,
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
|
||||||
|
context.Indicators.Add(indicator);
|
||||||
|
|
||||||
|
return await context.SaveChangesAsync(cancellationToken) > 0
|
||||||
|
? Result.Ok((hashService.HashEncodeLongId(indicator.Id).Value, indicator.Map()))
|
||||||
|
: Result.Fail("Failed to create the invite");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result.Fail(new Error(ex.Message).CausedBy(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using PostFundManagement.Domain;
|
||||||
|
|
||||||
|
namespace PostFundManagement.Application.Evidence;
|
||||||
|
|
||||||
|
public record RecordActualRequest(decimal ActualAmount);
|
||||||
|
|
||||||
|
public record CreateMilestoneRequest(long ProjectId, DateTime DueAt, string Name, Priority Priority);
|
||||||
|
|
||||||
|
public record CreateIndicatorRequest(long ProjectId, string Name, UnitOfMeasure UnitOfMeasure, decimal BaselineAmount, decimal TargetAmount);
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<AssemblyOriginatorKeyFile>..\PostFundManagement.snk</AssemblyOriginatorKeyFile>
|
||||||
|
<SignAssembly>True</SignAssembly>
|
||||||
|
<PackageLicenseFile>..\LICENSE</PackageLicenseFile>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PostFundManagement.Domain\PostFundManagement.Domain.csproj" />
|
||||||
|
<ProjectReference Include="..\PostFundManagement.Infrastructure\PostFundManagement.Infrastructure.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!-- Shared Usings -->
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="System.Security.Claims" />
|
||||||
|
<Using Include="System.Diagnostics" />
|
||||||
|
<Using Include="MimeKit" />
|
||||||
|
<Using Include="MailKit.Net.Smtp" />
|
||||||
|
<Using Include="Quartz" />
|
||||||
|
<Using Include="Refit" />
|
||||||
|
<Using Include="AccessTokenClient" />
|
||||||
|
<Using Include="Microsoft.AspNetCore.Authentication" />
|
||||||
|
<Using Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
|
||||||
|
<Using Include="Microsoft.AspNetCore.Authentication.Cookies" />
|
||||||
|
<Using Include="IdentityModel.AspNetCore.OAuth2Introspection" />
|
||||||
|
<Using Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
|
||||||
|
<Using Include="Microsoft.Extensions.Configuration" />
|
||||||
|
<Using Include="Amazon.S3" />
|
||||||
|
<Using Include="Amazon.S3.Model" />
|
||||||
|
<Using Include="Amazon.Runtime" />
|
||||||
|
<Using Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" />
|
||||||
|
<Using Include="Microsoft.EntityFrameworkCore" />
|
||||||
|
<Using Include="Microsoft.EntityFrameworkCore.Design" />
|
||||||
|
<Using Include="Microsoft.EntityFrameworkCore.Metadata.Builders" />
|
||||||
|
<Using Include="Mediator" />
|
||||||
|
<Using Include="FluentResults" />
|
||||||
|
<Using Include="Microsoft.AspNetCore.DataProtection" />
|
||||||
|
<Using Include="System.Security.Cryptography.X509Certificates" />
|
||||||
|
<Using Include="Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage" />
|
||||||
|
<Using Include="System.Text.Json.Serialization" />
|
||||||
|
<Using Include="System.Reflection" />
|
||||||
|
<Using Include="Microsoft.Extensions.DependencyInjection.Extensions" />
|
||||||
|
<Using Include="Microsoft.AspNetCore.Routing" />
|
||||||
|
<Using Include="System.Web" />
|
||||||
|
<Using Include="Microsoft.IdentityModel.Tokens" />
|
||||||
|
<Using Include="Microsoft.AspNetCore.Http" />
|
||||||
|
<Using Include="HashidsNet" />
|
||||||
|
<Using Include="System.Net" />
|
||||||
|
<Using Include="System.Text.RegularExpressions" />
|
||||||
|
<Using Include="System.Globalization" />
|
||||||
|
<Using Include="Microsoft.AspNetCore.Builder" />
|
||||||
|
<Using Include="Microsoft.Extensions.Hosting" />
|
||||||
|
<Using Include="System.Text" />
|
||||||
|
<Using Include="System.Text.Json" />
|
||||||
|
<Using Include="System.Threading.Channels" />
|
||||||
|
<Using Include="System.Collections.ObjectModel" />
|
||||||
|
<Using Include="Microsoft.Extensions.DependencyInjection" />
|
||||||
|
<Using Include="System.Security.Cryptography" />
|
||||||
|
<Using Include="Microsoft.Extensions.Options" />
|
||||||
|
<Using Include="Microsoft.Extensions.Logging" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace PostFundManagement.Domain.Services;
|
namespace PostFundManagement.Application.Shared;
|
||||||
|
|
||||||
public sealed class BrowserLocalStorageService(ProtectedLocalStorage storage)
|
public sealed class BrowserLocalStorageService(ProtectedLocalStorage storage)
|
||||||
{
|
{
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using static PostFundManagement.Domain.Extensions.Constants;
|
using static PostFundManagement.Domain.Extensions.Constants;
|
||||||
|
|
||||||
namespace PostFundManagement.Domain.Services;
|
namespace PostFundManagement.Application.Shared;
|
||||||
|
|
||||||
public sealed class ContractS3Service(IConfiguration configuration, [FromKeyedServices(ContractBucketName)] IAmazonS3 amazonS3) :
|
public sealed class ContractS3Service(IConfiguration configuration, [FromKeyedServices(ContractBucketName)] IAmazonS3 amazonS3) :
|
||||||
S3ServiceBase(amazonS3), IS3Service
|
S3ServiceBase(amazonS3), IS3Service
|
||||||
+2
-3
@@ -1,10 +1,9 @@
|
|||||||
using System.Diagnostics;
|
using PostFundManagement.Domain;
|
||||||
using PostFundManagement.Domain.Configuration.Email;
|
using PostFundManagement.Domain.Configuration.Email;
|
||||||
using PostFundManagement.Domain.Extensions;
|
using PostFundManagement.Domain.Extensions;
|
||||||
using PostFundManagement.Domain.Models.Email;
|
using PostFundManagement.Domain.Models.Email;
|
||||||
using static PostFundManagement.Domain.Extensions.EmailTelemetry;
|
|
||||||
|
|
||||||
namespace PostFundManagement.Domain.Services;
|
namespace PostFundManagement.Application.Shared;
|
||||||
|
|
||||||
public sealed class EmailService(IOptions<SmtpSettings> options) : IDisposable
|
public sealed class EmailService(IOptions<SmtpSettings> options) : IDisposable
|
||||||
{
|
{
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using static PostFundManagement.Domain.Extensions.Constants;
|
using static PostFundManagement.Domain.Extensions.Constants;
|
||||||
|
|
||||||
namespace PostFundManagement.Domain.Services;
|
namespace PostFundManagement.Application.Shared;
|
||||||
|
|
||||||
public sealed class EvidenceS3Service(IConfiguration configuration, [FromKeyedServices(EvidenceBucketName)] IAmazonS3 amazonS3) :
|
public sealed class EvidenceS3Service(IConfiguration configuration, [FromKeyedServices(EvidenceBucketName)] IAmazonS3 amazonS3) :
|
||||||
S3ServiceBase(amazonS3), IS3Service
|
S3ServiceBase(amazonS3), IS3Service
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using static PostFundManagement.Domain.Extensions.Constants;
|
using static PostFundManagement.Domain.Extensions.Constants;
|
||||||
|
|
||||||
namespace PostFundManagement.Domain.Services;
|
namespace PostFundManagement.Application.Shared;
|
||||||
|
|
||||||
public sealed class GeneralS3Service(IConfiguration configuration, [FromKeyedServices(GeneralBucketName)] IAmazonS3 amazonS3) :
|
public sealed class GeneralS3Service(IConfiguration configuration, [FromKeyedServices(GeneralBucketName)] IAmazonS3 amazonS3) :
|
||||||
S3ServiceBase(amazonS3), IS3Service
|
S3ServiceBase(amazonS3), IS3Service
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
|
|
||||||
namespace PostFundManagement.Domain.Services;
|
namespace PostFundManagement.Application.Shared;
|
||||||
|
|
||||||
public sealed partial class HashService(IHashids hasher) : IService
|
public sealed partial class HashService(IHashids hasher) : IService
|
||||||
{
|
{
|
||||||
+5
-5
@@ -2,17 +2,17 @@ using PostFundManagement.Domain.Api.Configuration;
|
|||||||
using PostFundManagement.Domain.Api.Models;
|
using PostFundManagement.Domain.Api.Models;
|
||||||
using PostFundManagement.Domain.Sdk;
|
using PostFundManagement.Domain.Sdk;
|
||||||
|
|
||||||
namespace PostFundManagement.Domain.Services;
|
namespace PostFundManagement.Application.Shared;
|
||||||
|
|
||||||
public sealed class TokenService(ISecurityConnectApi connectApi, IOptions<SecurityClientSettings> clientOptions)
|
public sealed class TokenService(ISecurityConnectApi connectApi, IOptions<SecurityClientSettings> clientOptions)
|
||||||
{
|
{
|
||||||
private readonly SecurityClientSettings clientSettings = clientOptions.Value;
|
private readonly SecurityClientSettings clientSettings = clientOptions.Value;
|
||||||
|
|
||||||
public async Task<Result<Api.Models.TokenResponse>> GenerateAsync(CancellationToken cancellationToken = default)
|
public async Task<Result<Domain.Api.Models.TokenResponse>> GenerateAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var request = new Api.Models.TokenRequest
|
var request = new Domain.Api.Models.TokenRequest
|
||||||
{
|
{
|
||||||
ClientId = clientSettings.ClientId,
|
ClientId = clientSettings.ClientId,
|
||||||
ClientSecret = clientSettings.ClientSecret,
|
ClientSecret = clientSettings.ClientSecret,
|
||||||
@@ -29,11 +29,11 @@ public sealed class TokenService(ISecurityConnectApi connectApi, IOptions<Securi
|
|||||||
|
|
||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var tokenResponse = JsonSerializer.Deserialize<Api.Models.TokenResponse>(contentRaw);
|
var tokenResponse = JsonSerializer.Deserialize<Domain.Api.Models.TokenResponse>(contentRaw);
|
||||||
|
|
||||||
return !string.IsNullOrWhiteSpace(tokenResponse?.AccessToken)
|
return !string.IsNullOrWhiteSpace(tokenResponse?.AccessToken)
|
||||||
? Result.Ok(tokenResponse)
|
? Result.Ok(tokenResponse)
|
||||||
: Result.Fail<Api.Models.TokenResponse>(new Error("Authentication succeeded, but no access token was found in the response payload."));
|
: Result.Fail<Domain.Api.Models.TokenResponse>(new Error("Authentication succeeded, but no access token was found in the response payload."));
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using PostFundManagement.Domain.Abstractions;
|
||||||
|
|
||||||
|
namespace PostFundManagement.Domain.Events.Communications;
|
||||||
|
|
||||||
|
public class SyncUserEvent : EventBase, IEvent
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = nameof(SyncUserEvent);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using PostFundManagement.Domain.Configuration.Email;
|
using PostFundManagement.Domain.Configuration.Email;
|
||||||
using PostFundManagement.Domain.Services;
|
using PostFundManagement.Domain.Services.Shared;
|
||||||
|
|
||||||
namespace PostFundManagement.Domain.Extensions;
|
namespace PostFundManagement.Domain.Extensions;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
namespace PostFundManagement.Domain.Extensions;
|
||||||
|
|
||||||
|
public static class General
|
||||||
|
{
|
||||||
|
public static ProblemDetails ToProblems(this IReadOnlyList<IError> errors, string title) => new()
|
||||||
|
{
|
||||||
|
Errors = errors.Select(e => new KeyValuePair<string, string[]>(e.Message,
|
||||||
|
[.. e.Reasons.Select(r => r.Message)])).ToDictionary(),
|
||||||
|
Detail = errors.FirstOrDefault()?.Message,
|
||||||
|
Status = StatusCodes.Status400BadRequest,
|
||||||
|
Title = title,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using PostFundManagement.Domain.Abstractions;
|
using PostFundManagement.Domain.Abstractions;
|
||||||
using PostFundManagement.Domain.Services;
|
using PostFundManagement.Domain.Services.Shared;
|
||||||
using static PostFundManagement.Domain.Extensions.Constants;
|
using static PostFundManagement.Domain.Extensions.Constants;
|
||||||
|
|
||||||
namespace PostFundManagement.Domain.Extensions;
|
namespace PostFundManagement.Domain.Extensions;
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
namespace PostFundManagement.Domain;
|
||||||
|
|
||||||
|
public sealed class Pagination
|
||||||
|
{
|
||||||
|
const int defaultPage = 1;
|
||||||
|
const int defaultPageSize = 100;
|
||||||
|
const long defaultIndex = 0;
|
||||||
|
|
||||||
|
public long Index { get; set; }
|
||||||
|
|
||||||
|
public int Page { get; set; }
|
||||||
|
|
||||||
|
public int PageSize { get; set; }
|
||||||
|
|
||||||
|
public Pagination()
|
||||||
|
{
|
||||||
|
Page = defaultPage;
|
||||||
|
PageSize = defaultPageSize;
|
||||||
|
Index = defaultIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pagination(int page = defaultPage, int pageSize = defaultPageSize, long index = defaultIndex)
|
||||||
|
{
|
||||||
|
if (page < 1) page = defaultPage;
|
||||||
|
|
||||||
|
if (pageSize < 1 || pageSize > 100) pageSize = defaultPageSize;
|
||||||
|
|
||||||
|
Page = page;
|
||||||
|
PageSize = pageSize;
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Pagination Create(int page = defaultPage, int pageSize = defaultPageSize, long index = defaultIndex)
|
||||||
|
{
|
||||||
|
if (page < 1) page = defaultPage;
|
||||||
|
|
||||||
|
if (pageSize < 1 || pageSize > 100) pageSize = defaultPageSize;
|
||||||
|
|
||||||
|
return new(page, pageSize, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<Solution>
|
<Solution>
|
||||||
<Project Path="PostFundManagement.Api/PostFundManagement.Api.csproj" />
|
<Project Path="PostFundManagement.Api/PostFundManagement.Api.csproj" />
|
||||||
|
<Project Path="PostFundManagement.Application/PostFundManagement.Application.csproj" Id="750c7754-53a7-4573-abed-5c436246a04d" />
|
||||||
<Project Path="PostFundManagement.Domain/PostFundManagement.Domain.csproj" />
|
<Project Path="PostFundManagement.Domain/PostFundManagement.Domain.csproj" />
|
||||||
<Project Path="PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj" />
|
<Project Path="PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj" />
|
||||||
</Solution>
|
</Solution>
|
||||||
|
|||||||
Reference in New Issue
Block a user