Skip to content

Commit

Permalink
return cost when user do new, renew, update and replace (#744)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

-return cost when user do new, renew, update and replace - spdbt-2186
  • Loading branch information
peggy-quartech authored Feb 7, 2024
1 parent 09b61fc commit b064685
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/Spd.Manager.Licence/Mappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Mappings()
.ForMember(d => d.ResidentialAddress, opt => opt.MapFrom(s => s.ResidentialAddressData))
.ForMember(d => d.MailingAddress, opt => opt.MapFrom(s => s.MailingAddressData))
.ForMember(d => d.Aliases, opt => opt.MapFrom(s => s.Aliases));
CreateMap<LicenceApplicationCmdResp, WorkerLicenceAppUpsertResponse>();
CreateMap<LicenceApplicationCmdResp, WorkerLicenceCommandResponse>();
CreateMap<LicenceApplicationResp, WorkerLicenceResponse>();
CreateMap<LicenceResp, LicenceResponse>();
CreateMap<LicenceFeeResp, LicenceFeeResponse>();
Expand Down
31 changes: 16 additions & 15 deletions src/Spd.Manager.Licence/SecurityWorkerAppContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@
namespace Spd.Manager.Licence;
public interface ISecurityWorkerAppManager
{
public Task<WorkerLicenceAppUpsertResponse> Handle(WorkerLicenceUpsertCommand command, CancellationToken ct);
public Task<WorkerLicenceAppUpsertResponse> Handle(WorkerLicenceSubmitCommand command, CancellationToken ct);
public Task<WorkerLicenceCommandResponse> Handle(WorkerLicenceUpsertCommand command, CancellationToken ct);
public Task<WorkerLicenceCommandResponse> Handle(WorkerLicenceSubmitCommand command, CancellationToken ct);
public Task<WorkerLicenceResponse> Handle(GetWorkerLicenceQuery query, CancellationToken ct);
public Task<IEnumerable<WorkerLicenceAppListResponse>> Handle(GetWorkerLicenceAppListQuery query, CancellationToken ct);
public Task<IEnumerable<LicenceAppDocumentResponse>> Handle(CreateLicenceAppDocumentCommand command, CancellationToken ct);
//deprecated
public Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceSubmitCommand command, CancellationToken ct);
public Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceAppNewCommand command, CancellationToken ct);
public Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceAppReplaceCommand command, CancellationToken ct);
public Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceAppRenewCommand command, CancellationToken ct);
public Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceAppUpdateCommand command, CancellationToken ct);
public Task<WorkerLicenceCommandResponse> Handle(AnonymousWorkerLicenceSubmitCommand command, CancellationToken ct);
public Task<WorkerLicenceCommandResponse> Handle(AnonymousWorkerLicenceAppNewCommand command, CancellationToken ct);
public Task<WorkerLicenceCommandResponse> Handle(AnonymousWorkerLicenceAppReplaceCommand command, CancellationToken ct);
public Task<WorkerLicenceCommandResponse> Handle(AnonymousWorkerLicenceAppRenewCommand command, CancellationToken ct);
public Task<WorkerLicenceCommandResponse> Handle(AnonymousWorkerLicenceAppUpdateCommand command, CancellationToken ct);
public Task<IEnumerable<LicAppFileInfo>> Handle(CreateDocumentInCacheCommand command, CancellationToken ct);
}

public record WorkerLicenceUpsertCommand(WorkerLicenceAppUpsertRequest LicenceUpsertRequest, string? BcscGuid = null) : IRequest<WorkerLicenceAppUpsertResponse>;
public record WorkerLicenceUpsertCommand(WorkerLicenceAppUpsertRequest LicenceUpsertRequest, string? BcscGuid = null) : IRequest<WorkerLicenceCommandResponse>;
public record WorkerLicenceSubmitCommand(WorkerLicenceAppUpsertRequest LicenceUpsertRequest, string? BcscGuid = null)
: WorkerLicenceUpsertCommand(LicenceUpsertRequest, BcscGuid), IRequest<WorkerLicenceAppUpsertResponse>;
: WorkerLicenceUpsertCommand(LicenceUpsertRequest, BcscGuid), IRequest<WorkerLicenceCommandResponse>;
//deprecated
public record AnonymousWorkerLicenceSubmitCommand(
WorkerLicenceAppAnonymousSubmitRequest LicenceAnonymousRequest,
ICollection<UploadFileRequest> UploadFileRequests)
: IRequest<WorkerLicenceAppUpsertResponse>;
: IRequest<WorkerLicenceCommandResponse>;

public record AnonymousWorkerLicenceAppNewCommand(
WorkerLicenceAppAnonymousSubmitRequestJson LicenceAnonymousRequest,
Guid KeyCode)
: IRequest<WorkerLicenceAppUpsertResponse>;
: IRequest<WorkerLicenceCommandResponse>;

public record AnonymousWorkerLicenceAppReplaceCommand(
WorkerLicenceAppAnonymousSubmitRequestJson LicenceAnonymousRequest,
Guid KeyCode)
: IRequest<WorkerLicenceAppUpsertResponse>;
: IRequest<WorkerLicenceCommandResponse>;

public record AnonymousWorkerLicenceAppRenewCommand(
WorkerLicenceAppAnonymousSubmitRequestJson LicenceAnonymousRequest,
Guid KeyCode)
: IRequest<WorkerLicenceAppUpsertResponse>;
: IRequest<WorkerLicenceCommandResponse>;

public record AnonymousWorkerLicenceAppUpdateCommand(
WorkerLicenceAppAnonymousSubmitRequestJson LicenceAnonymousRequest,
Guid KeyCode)
: IRequest<WorkerLicenceAppUpsertResponse>;
: IRequest<WorkerLicenceCommandResponse>;

public record GetWorkerLicenceQuery(Guid LicenceApplicationId) : IRequest<WorkerLicenceResponse>;
public record GetWorkerLicenceAppListQuery(Guid ApplicantId) : IRequest<IEnumerable<WorkerLicenceAppListResponse>>;
Expand Down Expand Up @@ -145,9 +145,10 @@ public record WorkerLicenceAppUpsertRequest : WorkerLicenceAppBase

public record WorkerLicenceAppSubmitRequest : WorkerLicenceAppUpsertRequest;

public record WorkerLicenceAppUpsertResponse
public record WorkerLicenceCommandResponse
{
public Guid? LicenceAppId { get; set; }
public decimal? Cost { get; set; }
}

#endregion
Expand Down
123 changes: 80 additions & 43 deletions src/Spd.Manager.Licence/SecurityWorkerAppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

namespace Spd.Manager.Licence;
internal partial class SecurityWorkerAppManager :
IRequestHandler<WorkerLicenceUpsertCommand, WorkerLicenceAppUpsertResponse>,
IRequestHandler<WorkerLicenceSubmitCommand, WorkerLicenceAppUpsertResponse>,
IRequestHandler<WorkerLicenceUpsertCommand, WorkerLicenceCommandResponse>,
IRequestHandler<WorkerLicenceSubmitCommand, WorkerLicenceCommandResponse>,
IRequestHandler<GetWorkerLicenceQuery, WorkerLicenceResponse>,
IRequestHandler<CreateLicenceAppDocumentCommand, IEnumerable<LicenceAppDocumentResponse>>,
IRequestHandler<GetWorkerLicenceAppListQuery, IEnumerable<WorkerLicenceAppListResponse>>,
IRequestHandler<AnonymousWorkerLicenceSubmitCommand, WorkerLicenceAppUpsertResponse>,//not used
IRequestHandler<AnonymousWorkerLicenceAppNewCommand, WorkerLicenceAppUpsertResponse>,
IRequestHandler<AnonymousWorkerLicenceAppReplaceCommand, WorkerLicenceAppUpsertResponse>,
IRequestHandler<AnonymousWorkerLicenceAppRenewCommand, WorkerLicenceAppUpsertResponse>,
IRequestHandler<AnonymousWorkerLicenceAppUpdateCommand, WorkerLicenceAppUpsertResponse>,
IRequestHandler<AnonymousWorkerLicenceSubmitCommand, WorkerLicenceCommandResponse>,//not used
IRequestHandler<AnonymousWorkerLicenceAppNewCommand, WorkerLicenceCommandResponse>,
IRequestHandler<AnonymousWorkerLicenceAppReplaceCommand, WorkerLicenceCommandResponse>,
IRequestHandler<AnonymousWorkerLicenceAppRenewCommand, WorkerLicenceCommandResponse>,
IRequestHandler<AnonymousWorkerLicenceAppUpdateCommand, WorkerLicenceCommandResponse>,
IRequestHandler<CreateDocumentInCacheCommand, IEnumerable<LicAppFileInfo>>,
ISecurityWorkerAppManager
{
Expand Down Expand Up @@ -72,7 +72,7 @@ public SecurityWorkerAppManager(

#region for portal
//authenticated save
public async Task<WorkerLicenceAppUpsertResponse> Handle(WorkerLicenceUpsertCommand cmd, CancellationToken ct)
public async Task<WorkerLicenceCommandResponse> Handle(WorkerLicenceUpsertCommand cmd, CancellationToken ct)
{
_logger.LogDebug($"manager get WorkerLicenceUpsertCommand={cmd}");
var identityResult = await _identityRepository.Query(new IdentityQry(cmd.BcscGuid, null, Resource.Repository.Registration.IdentityProviderTypeEnum.BcServicesCard), ct);
Expand All @@ -96,11 +96,11 @@ public async Task<WorkerLicenceAppUpsertResponse> Handle(WorkerLicenceUpsertComm

await UpdateDocumentsAsync(cmd.LicenceUpsertRequest, ct);
await RemoveDeletedDocumentsAsync(cmd.LicenceUpsertRequest, ct);
return _mapper.Map<WorkerLicenceAppUpsertResponse>(response);
return _mapper.Map<WorkerLicenceCommandResponse>(response);
}

// authenticated submit
public async Task<WorkerLicenceAppUpsertResponse> Handle(WorkerLicenceSubmitCommand cmd, CancellationToken ct)
public async Task<WorkerLicenceCommandResponse> Handle(WorkerLicenceSubmitCommand cmd, CancellationToken ct)
{
var response = await this.Handle((WorkerLicenceUpsertCommand)cmd, ct);
//check if payment is done
Expand All @@ -112,7 +112,7 @@ public async Task<WorkerLicenceAppUpsertResponse> Handle(WorkerLicenceSubmitComm
//move the file from temp file repo to formal file repo.
//todo

return _mapper.Map<WorkerLicenceAppUpsertResponse>(response);
return _mapper.Map<WorkerLicenceCommandResponse>(response);
}
public async Task<WorkerLicenceResponse> Handle(GetWorkerLicenceQuery query, CancellationToken ct)
{
Expand Down Expand Up @@ -153,7 +153,7 @@ public async Task<IEnumerable<WorkerLicenceAppListResponse>> Handle(GetWorkerLic

#region anonymous
//deprecated
public async Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceSubmitCommand cmd, CancellationToken ct)
public async Task<WorkerLicenceCommandResponse> Handle(AnonymousWorkerLicenceSubmitCommand cmd, CancellationToken ct)
{
WorkerLicenceAppAnonymousSubmitRequest request = cmd.LicenceAnonymousRequest;
ICollection<UploadFileRequest> fileRequests = cmd.UploadFileRequests;
Expand All @@ -172,10 +172,10 @@ public async Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceS
//create bcgov_documenturl and file
await _documentRepository.ManageAsync(fileCmd, ct);
}
return new WorkerLicenceAppUpsertResponse { LicenceAppId = response.LicenceAppId };
return new WorkerLicenceCommandResponse { LicenceAppId = response.LicenceAppId };
}

public async Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceAppNewCommand cmd, CancellationToken ct)
public async Task<WorkerLicenceCommandResponse> Handle(AnonymousWorkerLicenceAppNewCommand cmd, CancellationToken ct)
{
WorkerLicenceAppAnonymousSubmitRequestJson request = cmd.LicenceAnonymousRequest;

Expand All @@ -185,11 +185,25 @@ public async Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceA
CreateLicenceApplicationCmd createApp = _mapper.Map<CreateLicenceApplicationCmd>(request);
var response = await _licenceAppRepository.CreateLicenceApplicationAsync(createApp, ct);
await UploadNewDocs(request, response.LicenceAppId, response.ContactId, ct);
await CommitApplicationAsync(request, response.LicenceAppId, ct);
return new WorkerLicenceAppUpsertResponse { LicenceAppId = response.LicenceAppId };

//if payment price is 0, directly set to Submitted, or PaymentPending
var price = await _feeRepository.QueryAsync(new LicenceFeeQry()
{
ApplicationTypeEnum = request.ApplicationTypeCode == null ? null : Enum.Parse<ApplicationTypeEnum>(request.ApplicationTypeCode.ToString()),
BusinessTypeEnum = request.BusinessTypeCode == null ? BusinessTypeEnum.None : Enum.Parse<BusinessTypeEnum>(request.BusinessTypeCode.ToString()),
LicenceTermEnum = request.LicenceTermCode == null ? null : Enum.Parse<LicenceTermEnum>(request.LicenceTermCode.ToString()),
WorkerLicenceTypeEnum = WorkerLicenceTypeEnum.SecurityWorkerLicence,
HasValidSwl90DayLicence = false
}, ct);
if (price.LicenceFees.FirstOrDefault() == null || price.LicenceFees.FirstOrDefault()?.Amount == 0)
await _licenceAppRepository.CommitLicenceApplicationAsync(response.LicenceAppId, ApplicationStatusEnum.Submitted, ct);
else
await _licenceAppRepository.CommitLicenceApplicationAsync(response.LicenceAppId, ApplicationStatusEnum.PaymentPending, ct);

return new WorkerLicenceCommandResponse { LicenceAppId = response.LicenceAppId, Cost = price.LicenceFees.FirstOrDefault()?.Amount };
}

public async Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceAppReplaceCommand cmd, CancellationToken ct)
public async Task<WorkerLicenceCommandResponse> Handle(AnonymousWorkerLicenceAppReplaceCommand cmd, CancellationToken ct)
{
WorkerLicenceAppAnonymousSubmitRequestJson request = cmd.LicenceAnonymousRequest;
if (cmd.LicenceAnonymousRequest.ApplicationTypeCode != ApplicationTypeCode.Replacement)
Expand Down Expand Up @@ -223,11 +237,24 @@ await _documentRepository.ManageAsync(
}
}

await CommitApplicationAsync(request, response.LicenceAppId, ct);
return new WorkerLicenceAppUpsertResponse { LicenceAppId = response.LicenceAppId };
//if payment price is 0, directly set to Submitted, or PaymentPending
var price = await _feeRepository.QueryAsync(new LicenceFeeQry()
{
ApplicationTypeEnum = ApplicationTypeEnum.Replacement,
BusinessTypeEnum = request.BusinessTypeCode == null ? BusinessTypeEnum.None : Enum.Parse<BusinessTypeEnum>(request.BusinessTypeCode.ToString()),
LicenceTermEnum = request.LicenceTermCode == null ? null : Enum.Parse<LicenceTermEnum>(request.LicenceTermCode.ToString()),
WorkerLicenceTypeEnum = WorkerLicenceTypeEnum.SecurityWorkerLicence,
HasValidSwl90DayLicence = false
}, ct);
if (price.LicenceFees.FirstOrDefault() == null || price.LicenceFees.FirstOrDefault()?.Amount == 0)
await _licenceAppRepository.CommitLicenceApplicationAsync(response.LicenceAppId, ApplicationStatusEnum.Submitted, ct);
else
await _licenceAppRepository.CommitLicenceApplicationAsync(response.LicenceAppId, ApplicationStatusEnum.PaymentPending, ct);

return new WorkerLicenceCommandResponse { LicenceAppId = response.LicenceAppId, Cost = price.LicenceFees.FirstOrDefault()?.Amount };
}

public async Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceAppRenewCommand cmd, CancellationToken ct)
public async Task<WorkerLicenceCommandResponse> Handle(AnonymousWorkerLicenceAppRenewCommand cmd, CancellationToken ct)
{
WorkerLicenceAppAnonymousSubmitRequestJson request = cmd.LicenceAnonymousRequest;
if (cmd.LicenceAnonymousRequest.ApplicationTypeCode != ApplicationTypeCode.Renewal)
Expand Down Expand Up @@ -270,12 +297,23 @@ await _documentRepository.ManageAsync(
bool hasSwl90DayLicence = originalLic.LicenceTermCode == LicenceTermEnum.NinetyDays &&
originalLic.WorkerLicenceTypeCode == WorkerLicenceTypeEnum.SecurityWorkerLicence;

await CommitApplicationAsync(request, response.LicenceAppId, ct, hasSwl90DayLicence);
var price = await _feeRepository.QueryAsync(new LicenceFeeQry()
{
ApplicationTypeEnum = ApplicationTypeEnum.Renewal,
BusinessTypeEnum = request.BusinessTypeCode == null ? BusinessTypeEnum.None : Enum.Parse<BusinessTypeEnum>(request.BusinessTypeCode.ToString()),
LicenceTermEnum = request.LicenceTermCode == null ? null : Enum.Parse<LicenceTermEnum>(request.LicenceTermCode.ToString()),
WorkerLicenceTypeEnum = WorkerLicenceTypeEnum.SecurityWorkerLicence,
HasValidSwl90DayLicence = hasSwl90DayLicence
}, ct);
if (price.LicenceFees.FirstOrDefault() == null || price.LicenceFees.FirstOrDefault()?.Amount == 0)
await _licenceAppRepository.CommitLicenceApplicationAsync(response.LicenceAppId, ApplicationStatusEnum.Submitted, ct);
else
await _licenceAppRepository.CommitLicenceApplicationAsync(response.LicenceAppId, ApplicationStatusEnum.PaymentPending, ct);

return new WorkerLicenceAppUpsertResponse { LicenceAppId = response.LicenceAppId };
return new WorkerLicenceCommandResponse { LicenceAppId = response.LicenceAppId, Cost = price.LicenceFees.FirstOrDefault()?.Amount };
}

public async Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceAppUpdateCommand cmd, CancellationToken ct)
public async Task<WorkerLicenceCommandResponse> Handle(AnonymousWorkerLicenceAppUpdateCommand cmd, CancellationToken ct)
{
WorkerLicenceAppAnonymousSubmitRequestJson request = cmd.LicenceAnonymousRequest;
if (cmd.LicenceAnonymousRequest.ApplicationTypeCode != ApplicationTypeCode.Update)
Expand Down Expand Up @@ -329,35 +367,34 @@ public async Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceA
await _documentRepository.ManageAsync(fileCmd, ct);
}
}
await CommitApplicationAsync(request, createLicResponse.LicenceAppId, ct);
var price = await _feeRepository.QueryAsync(new LicenceFeeQry()
{
ApplicationTypeEnum = ApplicationTypeEnum.Update,
BusinessTypeEnum = request.BusinessTypeCode == null ? BusinessTypeEnum.None : Enum.Parse<BusinessTypeEnum>(request.BusinessTypeCode.ToString()),
LicenceTermEnum = request.LicenceTermCode == null ? null : Enum.Parse<LicenceTermEnum>(request.LicenceTermCode.ToString()),
WorkerLicenceTypeEnum = WorkerLicenceTypeEnum.SecurityWorkerLicence,
HasValidSwl90DayLicence = false
}, ct);
if (price.LicenceFees.FirstOrDefault() == null || price.LicenceFees.FirstOrDefault()?.Amount == 0)
await _licenceAppRepository.CommitLicenceApplicationAsync(createLicResponse.LicenceAppId, ApplicationStatusEnum.Submitted, ct);
else
await _licenceAppRepository.CommitLicenceApplicationAsync(createLicResponse.LicenceAppId, ApplicationStatusEnum.PaymentPending, ct);

return new WorkerLicenceCommandResponse()
{
LicenceAppId = createLicResponse.LicenceAppId,
Cost = price.LicenceFees.FirstOrDefault()?.Amount
};
}
else
{
//update contact directly
await _contactRepository.ManageAsync(_mapper.Map<UpdateContactCmd>(request), ct);
return new WorkerLicenceCommandResponse() { LicenceAppId = createLicResponse?.LicenceAppId, Cost = 0 };
}

return new WorkerLicenceAppUpsertResponse() { LicenceAppId = createLicResponse?.LicenceAppId };
}

#endregion

private async Task CommitApplicationAsync(WorkerLicenceAppAnonymousSubmitRequestJson request, Guid licenceAppId, CancellationToken ct, bool HasSwl90DayLicence = false)
{
//if payment price is 0, directly set to Submitted, or PaymentPending
var price = await _feeRepository.QueryAsync(new LicenceFeeQry()
{
ApplicationTypeEnum = request.ApplicationTypeCode == null ? null : Enum.Parse<ApplicationTypeEnum>(request.ApplicationTypeCode.ToString()),
BusinessTypeEnum = request.BusinessTypeCode == null ? BusinessTypeEnum.None : Enum.Parse<BusinessTypeEnum>(request.BusinessTypeCode.ToString()),
LicenceTermEnum = request.LicenceTermCode == null ? null : Enum.Parse<LicenceTermEnum>(request.LicenceTermCode.ToString()),
WorkerLicenceTypeEnum = request.WorkerLicenceTypeCode == null ? null : Enum.Parse<WorkerLicenceTypeEnum>(request.WorkerLicenceTypeCode.ToString()),
HasValidSwl90DayLicence = HasSwl90DayLicence
}, ct);
if (price.LicenceFees.FirstOrDefault() == null || price.LicenceFees.FirstOrDefault()?.Amount == 0)
await _licenceAppRepository.CommitLicenceApplicationAsync(licenceAppId, ApplicationStatusEnum.Submitted, ct);
else
await _licenceAppRepository.CommitLicenceApplicationAsync(licenceAppId, ApplicationStatusEnum.PaymentPending, ct);
}
private async Task<bool> HasDuplicates(Guid applicantId, WorkerLicenceTypeEnum workerLicenceType, Guid? existingLicAppId, CancellationToken ct)
{
LicenceAppQuery q = new LicenceAppQuery
Expand Down
Loading

0 comments on commit b064685

Please sign in to comment.