Added linkage to primary tenant entities #89

Merged
khwezi merged 1 commits from finishline into main 2026-09-22 07:09:21 +02:00
4 changed files with 21 additions and 11 deletions
@@ -1,5 +1,6 @@
using PostFundManagement.Application.Abstractions.Services;
using PostFundManagement.Domain;
using PostFundManagement.Domain.Abstractions;
using PostFundManagement.Domain.Errors;
using PostFundManagement.Domain.Extensions;
using PostFundManagement.Domain.Models;
@@ -7,7 +8,7 @@ using PostFundManagement.Infrastructure.Database;
namespace PostFundManagement.Application.Services.Communications;
public sealed class CommunicationsService(IDbContextFactory<ApplicationDbContext> contextFactory) : ICommunicationsService
public sealed class CommunicationsService(IDbContextFactory<ApplicationDbContext> contextFactory, ITenantContextService tenantContext) : ICommunicationsService
{
public async Task<Result<Invite>> SendInviteAsync(InviteRequest request, Guid userId, CancellationToken cancellationToken = default) =>
await Result.Try((Func<Task<Result<Invite>>>)(async () =>
@@ -15,7 +16,7 @@ public sealed class CommunicationsService(IDbContextFactory<ApplicationDbContext
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var invite = new Domain.Entities.Invite
{
{
OrganisationId = request.OrganisationId,
InvitedOrganisationId = request.InvitedOrganisationId,
AwardId = request.AwardId,
@@ -35,7 +36,8 @@ public sealed class CommunicationsService(IDbContextFactory<ApplicationDbContext
Status = NotificationStatus.Pending,
Subject = "Invitation to Onboard",
Message = request.Message,
CreatedAt = DateTime.UtcNow
CreatedAt = DateTime.UtcNow,
TenantId = tenantContext.TenantId
});
return Result.FailIf(await context.SaveChangesAsync(cancellationToken) <= 0, CreateError.New)
@@ -2,6 +2,7 @@
using PostFundManagement.Application.Extensions;
using PostFundManagement.Application.Services.Shared;
using PostFundManagement.Domain;
using PostFundManagement.Domain.Abstractions;
using PostFundManagement.Domain.Errors;
using PostFundManagement.Domain.Extensions;
using PostFundManagement.Domain.Models;
@@ -9,7 +10,8 @@ using PostFundManagement.Infrastructure.Database;
namespace PostFundManagement.Application.Services.Governance;
public sealed class GovernanceService(IDbContextFactory<ApplicationDbContext> contextFactory, HashService hashService) : IGovernanceService
public sealed class GovernanceService(IDbContextFactory<ApplicationDbContext> contextFactory, HashService hashService,
ITenantContextService tenantContext) : IGovernanceService
{
public async Task<Result<Programme[]>> GetProgrammesAsync(string portfolioIdHash, CancellationToken cancellationToken = default) =>
await Result.Try((Func<Task<Result<Programme[]>>>)(async () =>
@@ -144,7 +146,7 @@ public sealed class GovernanceService(IDbContextFactory<ApplicationDbContext> co
Type = request.Type,
Status = ActivityStatus.Active,
CreatedBy = userId,
CreatedAt = DateTime.UtcNow
CreatedAt = DateTime.UtcNow
});
return Result.OkIf(await context.SaveChangesAsync(cancellationToken) > 0, CreateError.New);
@@ -189,7 +191,8 @@ public sealed class GovernanceService(IDbContextFactory<ApplicationDbContext> co
OrganisationId = request.OrganisationId,
OwnedBy = request.OwnerId,
Name = name,
Description = request.Description.Humanize(LetterCasing.Sentence).Trim()
Description = request.Description.Humanize(LetterCasing.Sentence).Trim(),
TenantId = tenantContext.TenantId
});
return Result.OkIf(await context.SaveChangesAsync(cancellationToken) > 0, CreateError.New);
@@ -10,7 +10,7 @@ using PostFundManagement.Infrastructure.Database;
namespace PostFundManagement.Application.Services.Grants;
public sealed class GrantsService(IDbContextFactory<ApplicationDbContext> contextFactory, HashService hashService,
[FromKeyedServices(Constants.GeneralBucketName)] IS3Service s3Service) : IGrantsService
[FromKeyedServices(Constants.GeneralBucketName)] IS3Service s3Service, ITenantContextService tenantContext) : IGrantsService
{
public async Task<Result<Contract[]>> GetContractsAsync(Pagination pagination, CancellationToken cancellationToken = default) =>
await Result.Try((Func<Task<Result<Contract[]>>>)(async () =>
@@ -196,7 +196,8 @@ public sealed class GrantsService(IDbContextFactory<ApplicationDbContext> contex
Amount = request.Amount,
Status = ApprovalStatus.Pending,
CreatedBy = userId,
CreatedAt = DateTime.UtcNow
CreatedAt = DateTime.UtcNow,
TenantId = tenantContext.TenantId
};
context.Awards.Add(award);
@@ -1,6 +1,7 @@
using PostFundManagement.Application.Abstractions.Services;
using PostFundManagement.Application.Services.Shared;
using PostFundManagement.Domain;
using PostFundManagement.Domain.Abstractions;
using PostFundManagement.Domain.Errors;
using PostFundManagement.Domain.Extensions;
using PostFundManagement.Domain.Models;
@@ -8,7 +9,8 @@ using PostFundManagement.Infrastructure.Database;
namespace PostFundManagement.Application.Services.Projects;
public sealed class ProjectService(IDbContextFactory<ApplicationDbContext> contextFactory, HashService hashService) : IProjectService
public sealed class ProjectService(IDbContextFactory<ApplicationDbContext> contextFactory, HashService hashService,
ITenantContextService tenantContext) : IProjectService
{
public async Task<Result> UpdateProjectStatusAsync(UpdateProjectStatusRequest request, Guid userId, CancellationToken cancellationToken = default) =>
await Result.Try((Func<Task<Result>>)(async () =>
@@ -101,7 +103,8 @@ public sealed class ProjectService(IDbContextFactory<ApplicationDbContext> conte
ProjectType = request.ProjectType,
Status = ApprovalStatus.Pending,
CreatedBy = userId,
CreatedAt = DateTime.UtcNow
CreatedAt = DateTime.UtcNow,
TenantId = tenantContext.TenantId
});
return Result.OkIf(await context.SaveChangesAsync(cancellationToken) > 0,
@@ -303,7 +306,8 @@ public sealed class ProjectService(IDbContextFactory<ApplicationDbContext> conte
Name = name,
CreatedBy = userId,
CreatedAt = DateTime.UtcNow,
Status = ApprovalStatus.Pending
Status = ApprovalStatus.Pending,
TenantId = tenantContext.TenantId
});
return Result.OkIf(await context.SaveChangesAsync(cancellationToken) > 0, CreateError.New);