Skip to content

Commit

Permalink
return latest expired or valid licence (#1197)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

- When user do search licence for licence number, we just return the
latest licence no matter it is expired or valid. (but not suspended or
inactive status)
  • Loading branch information
peggy-quartech authored Jul 5, 2024
1 parent 9ccbb79 commit 9d56791
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Spd.Manager.Licence/LicenceContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public record LicenceResponse : LicenceBasicResponse
public IEnumerable<Document> RationalDocumentInfos { get; set; } = [];
};

public record LicenceQuery(string? LicenceNumber, string? AccessCode, bool isLatestInactive = true) : IRequest<LicenceResponse>;
public record LicenceQuery(string? LicenceNumber, string? AccessCode) : IRequest<LicenceResponse>;
public record LicenceByIdQuery(Guid LicenceId) : IRequest<LicenceResponse>;
public record LicenceListQuery(Guid? ApplicantId, Guid? BizId) : IRequest<IEnumerable<LicenceBasicResponse>>;
public record LicencePhotoQuery(Guid LicenceId) : IRequest<FileResponse>;
2 changes: 1 addition & 1 deletion src/Spd.Manager.Licence/LicenceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task<LicenceResponse> Handle(LicenceByIdQuery query, CancellationTo
{
LicenceNumber = query.LicenceNumber,
AccessCode = query.AccessCode,
IncludeInactive = query.isLatestInactive,
IncludeInactive = true,
}, cancellationToken);

if (!response.Items.Any())
Expand Down
11 changes: 5 additions & 6 deletions src/Spd.Presentation.Licensing/Controllers/LicenceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,19 @@ public async Task<IEnumerable<LicenceBasicResponse>> GetApplicantLicences([FromR
}

/// <summary>
/// Get licence by licence number.
/// If isLatestInactive = true, it means return the latest inactive licence. If isLatestInactive=false, it will return the active licence.
/// Get latest licence by licence number.
/// There should be only one active licence for each licenceNumber.
/// Example: http://localhost:5114/api/licence-lookup/TEST-02?accessCode=TEST&isLatestInactive=false
/// Example: http://localhost:5114/api/licence-lookup/TEST-02?accessCode=TEST
/// </summary>
/// <param name="licenceNumber"></param>
/// <param name="accessCode"></param>
/// <returns></returns>
[Route("api/licence-lookup/{licenceNumber}")]
[HttpGet]
[Authorize(Policy = "BcscBCeID")]
public async Task<LicenceResponse?> GetLicenceLookup([FromRoute][Required] string licenceNumber, [FromQuery] string? accessCode = null, [FromQuery] bool isLatestInactive = true)
public async Task<LicenceResponse?> GetLicenceLookup([FromRoute][Required] string licenceNumber, [FromQuery] string? accessCode = null)
{
return await _mediator.Send(new LicenceQuery(licenceNumber, accessCode, isLatestInactive));
return await _mediator.Send(new LicenceQuery(licenceNumber, accessCode));
}

/// <summary>
Expand All @@ -90,7 +89,7 @@ public async Task<IEnumerable<LicenceBasicResponse>> GetApplicantLicences([FromR
{
await VerifyGoogleRecaptchaAsync(recaptcha, ct);

LicenceResponse response = await _mediator.Send(new LicenceQuery(licenceNumber, accessCode, isLatestInactive));
LicenceResponse response = await _mediator.Send(new LicenceQuery(licenceNumber, accessCode));
Guid latestAppId;
if (response.WorkerLicenceTypeCode == WorkerLicenceTypeCode.SecurityWorkerLicence)
latestAppId = await _mediator.Send(new GetLatestWorkerLicenceApplicationIdQuery((Guid)response.LicenceHolderId));
Expand Down
3 changes: 3 additions & 0 deletions src/Spd.Resource.Repository/Licence/LicenceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public async Task<LicenceListResp> QueryAsync(LicenceQry qry, CancellationToken
if (!qry.IncludeInactive)
lics = lics.Where(d => d.statecode != DynamicsConstants.StateCode_Inactive);

if (qry.IncludeInactive)
lics = lics.Where(d => d.statuscode != (int)LicenceStatusOptionSet.Inactive && d.statuscode != (int)LicenceStatusOptionSet.Suspended);

if (qry.LicenceId != null)
{
lics = lics.Where(a => a.spd_licenceid == qry.LicenceId);
Expand Down

0 comments on commit 9d56791

Please sign in to comment.