Skip to content

Commit

Permalink
re-org code for permit new (#748)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

- re-org code for permit
  • Loading branch information
peggy-quartech authored Feb 7, 2024
1 parent f996dfe commit 2695d51
Show file tree
Hide file tree
Showing 14 changed files with 880 additions and 392 deletions.
65 changes: 65 additions & 0 deletions src/Spd.Manager.Licence/LicenceAppContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Spd.Manager.Shared;
using GenderCode = Spd.Manager.Shared.GenderCode;

namespace Spd.Manager.Licence;
public abstract record PersonalLicenceAppBase
{
public WorkerLicenceTypeCode? WorkerLicenceTypeCode { get; set; }
public ApplicationTypeCode? ApplicationTypeCode { get; set; }
public BusinessTypeCode? BusinessTypeCode { get; set; }
public string? GivenName { get; set; }
public string? MiddleName1 { get; set; }
public string? MiddleName2 { get; set; }
public string? Surname { get; set; }
public DateOnly? DateOfBirth { get; set; }
public GenderCode? GenderCode { get; set; }
public bool? OneLegalName { get; set; }
public string? ExpiredLicenceNumber { get; set; }
public Guid? ExpiredLicenceId { get; set; } //for new application type, for renew, replace, update, it should be null.
public bool? HasExpiredLicence { get; set; } //for new application type
public LicenceTermCode? LicenceTermCode { get; set; }
public bool? HasCriminalHistory { get; set; }
public bool? HasPreviousName { get; set; }
public IEnumerable<Alias>? Aliases { get; set; }
public bool? HasBcDriversLicence { get; set; }
public string? BcDriversLicenceNumber { get; set; }
public HairColourCode? HairColourCode { get; set; }
public EyeColourCode? EyeColourCode { get; set; }
public int? Height { get; set; }
public HeightUnitCode? HeightUnitCode { get; set; }
public int? Weight { get; set; }
public WeightUnitCode? WeightUnitCode { get; set; }
public string? ContactEmailAddress { get; set; }
public string? ContactPhoneNumber { get; set; }
public bool? IsMailingTheSameAsResidential { get; set; }
public ResidentialAddress? ResidentialAddressData { get; set; }
public MailingAddress? MailingAddressData { get; set; }
public bool? IsPoliceOrPeaceOfficer { get; set; }
public PoliceOfficerRoleCode? PoliceOfficerRoleCode { get; set; }
public string? OtherOfficerRole { get; set; }
public bool? IsTreatedForMHC { get; set; }
public bool? UseBcServicesCardPhoto { get; set; }
public bool? CarryAndUseRestraints { get; set; }
public bool? UseDogs { get; set; }
public bool? IsDogsPurposeProtection { get; set; }
public bool? IsDogsPurposeDetectionDrugs { get; set; }
public bool? IsDogsPurposeDetectionExplosives { get; set; }
public bool? IsCanadianCitizen { get; set; }
public bool? AgreeToCompleteAndAccurate { get; set; }
public bool? LegalNameChanged { get; set; }
public IEnumerable<DocumentExpiredInfo> DocumentExpiredInfos { get; set; } = Enumerable.Empty<DocumentExpiredInfo>();
}

public record ResidentialAddress : Address;
public record MailingAddress : Address;
public record DocumentExpiredInfo
{
public LicenceDocumentTypeCode LicenceDocumentTypeCode { get; set; }
public DateOnly? ExpiryDate { get; set; }
}
public record LicenceAppUpsertResponse
{
public Guid? LicenceAppId { get; set; }
}


46 changes: 46 additions & 0 deletions src/Spd.Manager.Licence/LicenceAppDocumentContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using MediatR;
using Microsoft.AspNetCore.Http;

namespace Spd.Manager.Licence;
public interface ILicenceAppDocumentManager
{
public Task<IEnumerable<LicAppFileInfo>> Handle(CreateDocumentInCacheCommand command, CancellationToken ct);
public Task<IEnumerable<LicenceAppDocumentResponse>> Handle(CreateLicenceAppDocumentCommand command, CancellationToken ct);
}


#region file upload
public record CreateLicenceAppDocumentCommand(LicenceAppDocumentUploadRequest Request, string? BcscId, Guid AppId) : IRequest<IEnumerable<LicenceAppDocumentResponse>>;
public record CreateDocumentInCacheCommand(LicenceAppDocumentUploadRequest Request) : IRequest<IEnumerable<LicAppFileInfo>>;

public record LicenceAppDocumentUploadRequest(
IList<IFormFile> Documents,
LicenceDocumentTypeCode LicenceDocumentTypeCode
);
public record LicenceAppDocumentResponse
{
public Guid DocumentUrlId { get; set; }
public DateTimeOffset UploadedDateTime { get; set; }
public Guid? LicenceAppId { get; set; }
public string? DocumentName { get; set; }
public string? DocumentExtension { get; set; }
};
public record LicenceAppDocumentsCache
{
public IEnumerable<LicAppFileInfo> Items { get; set; } = Enumerable.Empty<LicAppFileInfo>();
}
public record LicAppFileInfo
{
public LicenceDocumentTypeCode LicenceDocumentTypeCode { get; set; }
public string? TempFileKey { get; set; } = null!;
public string ContentType { get; set; } = null!;
public string FileName { get; set; } = null!;
public long FileSize { get; set; }
}
#endregion






Original file line number Diff line number Diff line change
@@ -1,11 +1,61 @@
using Spd.Resource.Repository.Application;
using AutoMapper;
using MediatR;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Logging;
using Spd.Resource.Repository.Application;
using Spd.Resource.Repository.Contact;
using Spd.Resource.Repository.Document;
using Spd.Resource.Repository.Identity;
using Spd.Resource.Repository.Licence;
using Spd.Resource.Repository.LicenceApplication;
using Spd.Resource.Repository.LicenceFee;
using Spd.Resource.Repository.Tasks;
using Spd.Utilities.TempFileStorage;

namespace Spd.Manager.Licence;
internal partial class SecurityWorkerAppManager
internal partial class LicenceAppDocumentManager :
IRequestHandler<CreateDocumentInCacheCommand, IEnumerable<LicAppFileInfo>>,
IRequestHandler<CreateLicenceAppDocumentCommand, IEnumerable<LicenceAppDocumentResponse>>,
ILicenceAppDocumentManager
{
private readonly ILicenceRepository _licenceRepository;
private readonly ILicenceApplicationRepository _licenceAppRepository;
private readonly IMapper _mapper;
private readonly ITempFileStorageService _tempFile;
private readonly IIdentityRepository _identityRepository;
private readonly IDocumentRepository _documentRepository;
private readonly ILogger<ISecurityWorkerAppManager> _logger;
private readonly ILicenceFeeRepository _feeRepository;
private readonly ITaskRepository _taskRepository;
private readonly IContactRepository _contactRepository;
private readonly IDistributedCache _cache;

public LicenceAppDocumentManager(
ILicenceRepository licenceRepository,
ILicenceApplicationRepository licenceAppRepository,
IMapper mapper,
ITempFileStorageService tempFile,
IIdentityRepository identityRepository,
IDocumentRepository documentUrlRepository,
ILogger<ISecurityWorkerAppManager> logger,
ILicenceFeeRepository feeRepository,
IDistributedCache cache,
ITaskRepository taskRepository,
IContactRepository contactRepository)
{
_licenceRepository = licenceRepository;
_licenceAppRepository = licenceAppRepository;
_tempFile = tempFile;
_mapper = mapper;
_identityRepository = identityRepository;
_documentRepository = documentUrlRepository;
_logger = logger;
_feeRepository = feeRepository;
_cache = cache;
_taskRepository = taskRepository;
_contactRepository = contactRepository;
}

public async Task<IEnumerable<LicenceAppDocumentResponse>> Handle(CreateLicenceAppDocumentCommand command, CancellationToken ct)
{
DocumentTypeEnum? docType1 = Mappings.GetDocumentType1Enum(command.Request.LicenceDocumentTypeCode);
Expand Down Expand Up @@ -65,7 +115,32 @@ public async Task<IEnumerable<LicAppFileInfo>> Handle(CreateDocumentInCacheComma

return cacheFileInfos;
}
public static readonly List<LicenceDocumentTypeCode> WorkProofCodes = new List<LicenceDocumentTypeCode> {
LicenceDocumentTypeCode.PermanentResidentCard,
LicenceDocumentTypeCode.RecordOfLandingDocument,
LicenceDocumentTypeCode.ConfirmationOfPermanentResidenceDocument,
LicenceDocumentTypeCode.WorkPermit,
LicenceDocumentTypeCode.StudyPermit,
LicenceDocumentTypeCode.DocumentToVerifyLegalWorkStatus,
};

public static readonly List<LicenceDocumentTypeCode> CitizenshipProofCodes = new List<LicenceDocumentTypeCode> {
LicenceDocumentTypeCode.CanadianPassport,
LicenceDocumentTypeCode.BirthCertificate,
LicenceDocumentTypeCode.CertificateOfIndianStatusForCitizen,
};

public static readonly List<WorkerCategoryTypeCode> WorkerCategoryTypeCode_NoNeedDocument = new List<WorkerCategoryTypeCode> {
WorkerCategoryTypeCode.ElectronicLockingDeviceInstaller,
WorkerCategoryTypeCode.SecurityGuardUnderSupervision,
WorkerCategoryTypeCode.SecurityAlarmInstallerUnderSupervision,
WorkerCategoryTypeCode.SecurityAlarmMonitor,
WorkerCategoryTypeCode.SecurityAlarmResponse,
WorkerCategoryTypeCode.SecurityAlarmSales,
WorkerCategoryTypeCode.ClosedCircuitTelevisionInstaller,
WorkerCategoryTypeCode.LocksmithUnderSupervision,
WorkerCategoryTypeCode.BodyArmourSales
};
private async Task UpdateDocumentsAsync(WorkerLicenceAppUpsertRequest request, CancellationToken ct)
{
////citizenship
Expand Down Expand Up @@ -153,40 +228,4 @@ private async Task RemoveDeletedDocumentsAsync(WorkerLicenceAppUpsertRequest req
// await _documentRepository.ManageAsync(new RemoveDocumentCmd(doc.DocumentUrlId), ct);
//}
}

private async Task GetDocumentsAsync(Guid LicenceAppId, WorkerLicenceResponse result, CancellationToken ct)
{
var existingDocs = await _documentRepository.QueryAsync(new DocumentQry(LicenceAppId), ct);
result.DocumentInfos = _mapper.Map<Document[]>(existingDocs.Items);
}




public static readonly List<LicenceDocumentTypeCode> WorkProofCodes = new List<LicenceDocumentTypeCode> {
LicenceDocumentTypeCode.PermanentResidentCard,
LicenceDocumentTypeCode.RecordOfLandingDocument,
LicenceDocumentTypeCode.ConfirmationOfPermanentResidenceDocument,
LicenceDocumentTypeCode.WorkPermit,
LicenceDocumentTypeCode.StudyPermit,
LicenceDocumentTypeCode.DocumentToVerifyLegalWorkStatus,
};

public static readonly List<LicenceDocumentTypeCode> CitizenshipProofCodes = new List<LicenceDocumentTypeCode> {
LicenceDocumentTypeCode.CanadianPassport,
LicenceDocumentTypeCode.BirthCertificate,
LicenceDocumentTypeCode.CertificateOfIndianStatusForCitizen,
};

public static readonly List<WorkerCategoryTypeCode> WorkerCategoryTypeCode_NoNeedDocument = new List<WorkerCategoryTypeCode> {
WorkerCategoryTypeCode.ElectronicLockingDeviceInstaller,
WorkerCategoryTypeCode.SecurityGuardUnderSupervision,
WorkerCategoryTypeCode.SecurityAlarmInstallerUnderSupervision,
WorkerCategoryTypeCode.SecurityAlarmMonitor,
WorkerCategoryTypeCode.SecurityAlarmResponse,
WorkerCategoryTypeCode.SecurityAlarmSales,
WorkerCategoryTypeCode.ClosedCircuitTelevisionInstaller,
WorkerCategoryTypeCode.LocksmithUnderSupervision,
WorkerCategoryTypeCode.BodyArmourSales
};
}
48 changes: 48 additions & 0 deletions src/Spd.Manager.Licence/LicenceAppValidation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using FluentValidation;

namespace Spd.Manager.Licence;
public class PersonalLicenceAppBaseValidator<T> : AbstractValidator<T> where T : PersonalLicenceAppBase
{
public PersonalLicenceAppBaseValidator()
{
RuleFor(r => r.WorkerLicenceTypeCode).NotEmpty();
RuleFor(r => r.ApplicationTypeCode).NotEmpty();
RuleFor(r => r.Surname).NotEmpty();
RuleFor(r => r.DateOfBirth).NotEmpty();
RuleFor(r => r.GenderCode).NotEmpty();
RuleFor(r => r.LicenceTermCode).NotEmpty();
RuleFor(r => r.HasExpiredLicence).NotEmpty();
RuleFor(r => r.ExpiredLicenceNumber).NotEmpty().When(r => r.HasExpiredLicence == true);
RuleFor(r => r.HasCriminalHistory).NotEmpty();
RuleFor(r => r.HasBcDriversLicence).NotEmpty();
RuleFor(r => r.HairColourCode).NotEmpty();
RuleFor(r => r.EyeColourCode).NotEmpty();
RuleFor(r => r.Height).NotEmpty();
RuleFor(r => r.HeightUnitCode).NotEmpty();
RuleFor(r => r.Weight).NotEmpty();
RuleFor(r => r.WeightUnitCode).NotEmpty();
RuleFor(r => r.HasCriminalHistory).NotEmpty();
RuleFor(r => r.IsMailingTheSameAsResidential).NotEmpty();
RuleFor(r => r.ContactPhoneNumber).MaximumLength(15).NotEmpty();
RuleFor(r => r.ContactEmailAddress).MaximumLength(75).When(r => r.ContactEmailAddress != null);
RuleFor(r => r.IsPoliceOrPeaceOfficer).NotEmpty();
RuleFor(r => r.PoliceOfficerRoleCode).NotEmpty().When(r => r.IsPoliceOrPeaceOfficer == true);
RuleFor(r => r.OtherOfficerRole).NotEmpty()
.When(r => r.IsPoliceOrPeaceOfficer != null && r.IsPoliceOrPeaceOfficer == true && r.PoliceOfficerRoleCode != null && r.PoliceOfficerRoleCode == PoliceOfficerRoleCode.Other);
RuleFor(r => r.IsTreatedForMHC).NotEmpty();
RuleFor(r => r.UseBcServicesCardPhoto).NotEmpty();
RuleFor(r => r.IsCanadianCitizen).NotEmpty();
//residential address
RuleFor(r => r.ResidentialAddressData).NotEmpty().WithMessage("ResidentialAddress cannot be empty");
RuleFor(r => r.ResidentialAddressData.Province).NotEmpty().When(r => r.ResidentialAddressData != null);
RuleFor(r => r.ResidentialAddressData.City).NotEmpty().MaximumLength(100).When(r => r.ResidentialAddressData != null);
RuleFor(r => r.ResidentialAddressData.AddressLine1).NotEmpty().MaximumLength(100).When(r => r.ResidentialAddressData != null);
RuleFor(r => r.ResidentialAddressData.Country).NotEmpty().MaximumLength(100).When(r => r.ResidentialAddressData != null);
RuleFor(r => r.ResidentialAddressData.PostalCode).NotEmpty().MaximumLength(20).When(r => r.ResidentialAddressData != null);

}
}




2 changes: 0 additions & 2 deletions src/Spd.Manager.Licence/Mappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public Mappings()
CreateMap<Alias, Spd.Resource.Repository.Alias>()
.ReverseMap();
CreateMap<LicenceAppListResp, WorkerLicenceAppListResponse>();
CreateMap<WorkerLicenceAppAnonymousSubmitRequest, SaveLicenceApplicationCmd>()
.ForMember(d => d.CategoryCodes, opt => opt.MapFrom(s => GetCategories(s.CategoryCodes)));
CreateMap<WorkerLicenceAppAnonymousSubmitRequestJson, SaveLicenceApplicationCmd>()
.ForMember(d => d.CategoryCodes, opt => opt.MapFrom(s => GetCategories(s.CategoryCodes)));
CreateMap<UploadFileRequest, SpdTempFile>()
Expand Down
66 changes: 66 additions & 0 deletions src/Spd.Manager.Licence/PermitAppContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using MediatR;

namespace Spd.Manager.Licence;
public interface IPermitAppManager
{
public Task<PermitAppCommandResponse> Handle(AnonymousPermitAppNewCommand command, CancellationToken ct);
public Task<PermitAppCommandResponse> Handle(AnonymousPermitAppReplaceCommand command, CancellationToken ct);
public Task<PermitAppCommandResponse> Handle(AnonymousPermitAppRenewCommand command, CancellationToken ct);
public Task<PermitAppCommandResponse> Handle(AnonymousPermitAppUpdateCommand command, CancellationToken ct);
}

#region anonymous user
public record AnonymousPermitAppNewCommand(
PermitAppAnonymousSubmitRequest LicenceAnonymousRequest,
Guid KeyCode)
: IRequest<PermitAppCommandResponse>;

public record AnonymousPermitAppReplaceCommand(
PermitAppAnonymousSubmitRequest LicenceAnonymousRequest,
Guid KeyCode)
: IRequest<PermitAppCommandResponse>;

public record AnonymousPermitAppRenewCommand(
PermitAppAnonymousSubmitRequest LicenceAnonymousRequest,
Guid KeyCode)
: IRequest<PermitAppCommandResponse>;

public record AnonymousPermitAppUpdateCommand(
PermitAppAnonymousSubmitRequest LicenceAnonymousRequest,
Guid KeyCode)
: IRequest<PermitAppCommandResponse>;

public record PermitAppAnonymousSubmitRequest : PersonalLicenceAppBase
{
public IEnumerable<Guid>? DocumentKeyCodes { get; set; }
public IEnumerable<Guid>? PreviousDocumentIds { get; set; } //documentUrlId, used for renew
public Guid? OriginalApplicationId { get; set; } //for new, it should be null. for renew, replace, update, it should be original application id.
public Guid? OriginalLicenceId { get; set; } //for new, it should be null. for renew, replace, update, it should be original licence id.
public bool? Reprint { get; set; }
public string? PermitOtherRequiredReason { get; set; }
public string? EmployerName { get; set; }
public string? SupervisorName { get; set; }
public string? SupervisorEmailAddress { get; set; }
public string? SupervisorPhoneNumber { get; set; }
public EmployerPrimaryAddress? EmployerPrimaryAddress { get; set; }
public string? Rationale { get; set; }
public bool? IsCanadianResident { get; set; }
public IEnumerable<RequirePermitReasonCode>? RequirePermitReasonCode { get; set; }
}

public record PermitAppCommandResponse : LicenceAppUpsertResponse;

public enum RequirePermitReasonCode
{
PersonalProtection,
MyEmployment,
OutdoorRecreation,
TravelInResponseToInternationalConflict,
Other
}
public record EmployerPrimaryAddress : Address;
#endregion




Loading

0 comments on commit 2695d51

Please sign in to comment.