Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swl - payment pending status #677

Merged
merged 4 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Spd.Manager.Licence/PersonalLicenceAppContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ public interface IPersonalLicenceAppManager
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(AnonymousWorkerLicenceAppSubmitCommand command, CancellationToken ct);
public Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceAppReplaceCommand command, CancellationToken ct);
public Task<IEnumerable<LicAppFileInfo>> Handle(CreateDocumentInCacheCommand command, CancellationToken ct);
}

Expand All @@ -23,13 +25,17 @@ public record AnonymousWorkerLicenceSubmitCommand(
WorkerLicenceAppAnonymousSubmitRequest LicenceAnonymousRequest,
ICollection<UploadFileRequest> UploadFileRequests)
: IRequest<WorkerLicenceAppUpsertResponse>;
//

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

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

public record GetWorkerLicenceQuery(Guid LicenceApplicationId) : IRequest<WorkerLicenceResponse>;
public record GetWorkerLicenceAppListQuery(Guid ApplicantId) : IRequest<IEnumerable<WorkerLicenceAppListResponse>>;

Expand Down Expand Up @@ -177,6 +183,7 @@ public record WorkerLicenceAppAnonymousSubmitRequestJson : WorkerLicenceAppBase
public WorkerCategoryTypeCode[] CategoryCodes { get; set; } = Array.Empty<WorkerCategoryTypeCode>();
public DocumentBase[]? DocumentInfos { get; set; }
public Guid[]? FileKeyCodes { get; set; }
public Guid? OriginalApplicationId { get; set; } = null;//for new, it should be null. for renew, replace, update, it should be original application id.
}

public record WorkerLicenceCreateResponse
Expand Down
31 changes: 26 additions & 5 deletions src/Spd.Manager.Licence/PersonalLicenceAppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using Spd.Resource.Applicants.Licence;
using Spd.Resource.Applicants.LicenceApplication;
using Spd.Resource.Organizations.Identity;
using Spd.Utilities.Cache;
using Spd.Utilities.Shared.Exceptions;
using Spd.Utilities.TempFileStorage;
using Spd.Utilities.Cache;

namespace Spd.Manager.Licence;
internal partial class PersonalLicenceAppManager :
Expand All @@ -18,8 +18,9 @@ internal partial class PersonalLicenceAppManager :
IRequestHandler<GetWorkerLicenceQuery, WorkerLicenceResponse>,
IRequestHandler<CreateLicenceAppDocumentCommand, IEnumerable<LicenceAppDocumentResponse>>,
IRequestHandler<GetWorkerLicenceAppListQuery, IEnumerable<WorkerLicenceAppListResponse>>,
IRequestHandler<AnonymousWorkerLicenceSubmitCommand, WorkerLicenceAppUpsertResponse>,
IRequestHandler<AnonymousWorkerLicenceSubmitCommand, WorkerLicenceAppUpsertResponse>,//not used
IRequestHandler<AnonymousWorkerLicenceAppSubmitCommand, WorkerLicenceAppUpsertResponse>,
IRequestHandler<AnonymousWorkerLicenceAppReplaceCommand, WorkerLicenceAppUpsertResponse>,
IRequestHandler<CreateDocumentInCacheCommand, IEnumerable<LicAppFileInfo>>,
IPersonalLicenceAppManager
{
Expand Down Expand Up @@ -52,6 +53,7 @@ public PersonalLicenceAppManager(
_cache = cache;
}

#region for portal
//authenticated save
public async Task<WorkerLicenceAppUpsertResponse> Handle(WorkerLicenceUpsertCommand cmd, CancellationToken ct)
{
Expand Down Expand Up @@ -129,6 +131,9 @@ public async Task<IEnumerable<WorkerLicenceAppListResponse>> Handle(GetWorkerLic
return _mapper.Map<IEnumerable<WorkerLicenceAppListResponse>>(response);
}

#endregion

#region anonymous
//deprecated
public async Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceSubmitCommand cmd, CancellationToken ct)
{
Expand Down Expand Up @@ -160,12 +165,12 @@ public async Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceA
{
WorkerLicenceAppAnonymousSubmitRequestJson request = cmd.LicenceAnonymousRequest;

LicenceAppDocumentsCache? appDocCache = await _cache.Get<LicenceAppDocumentsCache>(cmd.KeyCode.ToString());

//todo: add checking if all necessary files have been uploaded
SaveLicenceApplicationCmd saveCmd = _mapper.Map<SaveLicenceApplicationCmd>(request);
saveCmd.ApplicationStatusEnum = ApplicationStatusEnum.PaymentPending;
var response = await _licenceAppRepository.SaveLicenceApplicationAsync(saveCmd, ct);

//new application, all file keys are in cache
if (cmd.LicenceAnonymousRequest.FileKeyCodes != null && cmd.LicenceAnonymousRequest.FileKeyCodes.Any())
{
foreach (Guid fileKeyCode in cmd.LicenceAnonymousRequest.FileKeyCodes)
Expand All @@ -187,10 +192,26 @@ await _documentRepository.ManageAsync(new CreateDocumentCmd
}
}
}

return new WorkerLicenceAppUpsertResponse { LicenceAppId = response.LicenceAppId };
}

public async Task<WorkerLicenceAppUpsertResponse> Handle(AnonymousWorkerLicenceAppReplaceCommand cmd, CancellationToken ct)
{
WorkerLicenceAppAnonymousSubmitRequestJson request = cmd.LicenceAnonymousRequest;
if (cmd.LicenceAnonymousRequest.ApplicationTypeCode != ApplicationTypeCode.Replacement)
throw new ArgumentException("should be a replacement request");

//validation: check if original licence meet replacement condition.

SaveLicenceApplicationCmd saveCmd = _mapper.Map<SaveLicenceApplicationCmd>(request);
saveCmd.ApplicationStatusEnum = ApplicationStatusEnum.PaymentPending;
var response = await _licenceAppRepository.SaveLicenceApplicationAsync(saveCmd, ct);

//todo: add file copying here.
return new WorkerLicenceAppUpsertResponse { LicenceAppId = response.LicenceAppId };
}
#endregion

private async Task<bool> HasDuplicates(Guid applicantId, WorkerLicenceTypeEnum workerLicenceType, Guid? existingLicAppId, CancellationToken ct)
{
LicenceAppQuery q = new LicenceAppQuery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,18 @@ public async Task<WorkerLicenceAppUpsertResponse> SubmitSecurityWorkerLicenceApp
if (!validateResult.IsValid)
throw new ApiException(HttpStatusCode.BadRequest, JsonSerializer.Serialize(validateResult.Errors));

AnonymousWorkerLicenceAppSubmitCommand command = new AnonymousWorkerLicenceAppSubmitCommand(jsonRequest, keyCode);
return await _mediator.Send(command);
if (jsonRequest.ApplicationTypeCode == ApplicationTypeCode.New)
{
AnonymousWorkerLicenceAppSubmitCommand command = new (jsonRequest, keyCode);
return await _mediator.Send(command);
}

if (jsonRequest.ApplicationTypeCode == ApplicationTypeCode.Replacement)
{
AnonymousWorkerLicenceAppReplaceCommand command = new (jsonRequest, keyCode);
return await _mediator.Send(command);
}
return null;
}
#endregion
}
Expand Down
1 change: 1 addition & 0 deletions src/Spd.Resource.Applicants/LicenceApplication/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public record WorkerLicenceAppCategory
public record SaveLicenceApplicationCmd() : LicenceApplication
{
public string? BcscGuid { get; set; }
public ApplicationStatusEnum ApplicationStatusEnum { get; set; } = ApplicationStatusEnum.Incomplete;
};

public record LicenceApplicationResp() : LicenceApplication
Expand Down
2 changes: 1 addition & 1 deletion src/Spd.Resource.Applicants/LicenceApplication/Mappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public Mappings()
.ForMember(d => d.spd_businesstype, opt => opt.MapFrom(s => SharedMappingFuncs.GetBusinessType(s.BusinessTypeCode)))
.ForMember(d => d.spd_requestdogs, opt => opt.MapFrom(s => SharedMappingFuncs.GetYesNo(s.UseDogs)))
.ForMember(d => d.statecode, opt => opt.MapFrom(s => DynamicsConstants.StateCode_Active))
.ForMember(d => d.statuscode, opt => opt.MapFrom(s => ApplicationStatusOptionSet.Incomplete))
.ForMember(d => d.spd_requestdogsreasons, opt => opt.MapFrom(s => GetDogReasonOptionSets(s)))
.ReverseMap()
.ForMember(d => d.DateOfBirth, opt => opt.MapFrom(s => SharedMappingFuncs.GetDateOnly(s.spd_dateofbirth)))
Expand Down Expand Up @@ -118,6 +117,7 @@ public Mappings()
opt => opt.MapFrom(s => Enum.Parse<WorkerCategoryTypeEnum>(DynamicsContextLookupHelpers.LookupLicenceCategoryKey(s.spd_licencecategoryid))));

_ = CreateMap<SaveLicenceApplicationCmd, spd_application>()
.ForMember(d => d.statuscode, opt => opt.MapFrom(s => SharedMappingFuncs.GetApplicationStatus(s.ApplicationStatusEnum)))
.IncludeBase<LicenceApplication, spd_application>();

_ = CreateMap<SaveLicenceApplicationCmd, contact>()
Expand Down
13 changes: 13 additions & 0 deletions src/Spd.Resource.Applicants/SharedMappingFuncs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.OData.Edm;
using Spd.Resource.Applicants.Application;
using Spd.Resource.Applicants.LicenceApplication;
using Spd.Utilities.Dynamics;
using Spd.Utilities.Shared.ResourceContracts;
Expand Down Expand Up @@ -105,4 +106,16 @@ internal static class SharedMappingFuncs
_ => throw new ArgumentException("invalid application type code")
};
}

internal static int? GetApplicationStatus(ApplicationStatusEnum? code)
{
if (code == null) return (int)ApplicationStatusOptionSet.Incomplete;
return (int)Enum.Parse<ApplicationStatusOptionSet>(code.ToString());
}

internal static ApplicationStatusEnum? GetApplicationStatusEnum(int? optionset)
{
if (optionset == null) return null;
return Enum.Parse<ApplicationStatusEnum>(Enum.GetName(typeof(ApplicationStatusOptionSet), optionset));
}
}
Loading