Skip to content

Commit

Permalink
biz search
Browse files Browse the repository at this point in the history
  • Loading branch information
peggy-quartech committed Dec 6, 2024
1 parent 3c7c511 commit a2dfab2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/Spd.Manager.Licence/LicenceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public async Task<IEnumerable<LicenceBasicResponse>> Handle(LicenceListSearch se
throw new ApiException(HttpStatusCode.BadRequest, "Not enough parameter");
if ((!string.IsNullOrWhiteSpace(search.LicenceNumber) && !string.IsNullOrWhiteSpace(search.FirstName))
|| (!string.IsNullOrWhiteSpace(search.LicenceNumber) && !string.IsNullOrWhiteSpace(search.LastName)))
throw new ApiException(HttpStatusCode.BadRequest, "Cannot input name and licence number together.");
throw new ApiException(HttpStatusCode.BadRequest, "Cannot search name and licence number together.");
response = await _licenceRepository.QueryAsync(
new LicenceQry
{
Expand All @@ -171,6 +171,10 @@ public async Task<IEnumerable<LicenceBasicResponse>> Handle(LicenceListSearch se
{
if (string.IsNullOrWhiteSpace(search.LicenceNumber) && string.IsNullOrWhiteSpace(search.BizName))
throw new ApiException(HttpStatusCode.BadRequest, "Not enough parameter");
if (!string.IsNullOrWhiteSpace(search.LicenceNumber) && !string.IsNullOrWhiteSpace(search.BizName))
throw new ApiException(HttpStatusCode.BadRequest, "Cannot search biz name and licence number together.");
if (!string.IsNullOrWhiteSpace(search.BizName) && search.BizName.Length < 3)
throw new ApiException(HttpStatusCode.BadRequest, "Business name must have at least 3 chars.");

response = await _licenceRepository.QueryAsync(
new LicenceQry
Expand Down
24 changes: 17 additions & 7 deletions src/Spd.Presentation.Licensing/Controllers/LicenceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,28 @@ public async Task<LicenceResponse> GetLicence([FromRoute] Guid licenceId, Cancel
}

/// <summary>
/// Get latest secure worker licence by licence number and/or firstname, lastname
/// Example: http://localhost:5114/api/licences/security-worker-licence?licenceNumber=E123&firstName=fn&lastName=ln
/// Get latest secure worker licence by licence number or firstname, lastname
/// Example: http://localhost:5114/api/licences/security-worker-licence?licenceNumber=E123
/// http://localhost:5114/api/licences/security-worker-licence?firstName=XXX&lastName=yyy
/// </summary>
/// <param name="licenceNumber"></param>
/// <param name="accessCode"></param>
/// <returns></returns>
[Route("api/licences/security-worker-licence")]
[HttpGet]
[AllowAnonymous]
public async Task<IEnumerable<LicenceBasicResponse>> GetSecureWorkerLicence([FromQuery] string? licenceNumber, [FromQuery] string? firstName = null, [FromQuery] string? lastName = null)
public async Task<IEnumerable<LicenceBasicResponse>> SearchSecureWorkerLicence([FromQuery] string? licenceNumber, [FromQuery] string? firstName = null, [FromQuery] string? lastName = null)
{
return await _mediator.Send(new LicenceListSearch(licenceNumber?.Trim(), firstName?.Trim(), lastName?.Trim(), null, ServiceTypeCode.SecurityWorkerLicence));
}

/// <summary>
/// Get latest secure business licence by licence number or at least the first 3 letters of biz name (for either legal name or trade name)
/// Example: http://localhost:5114/api/licences/business-licence?licenceNumber=B123
/// </summary>
[Route("api/licences/business-licence")]
[HttpGet]
[AllowAnonymous]
public async Task<IEnumerable<LicenceBasicResponse>> SearchBizLicence([FromQuery] string? licenceNumber, [FromQuery] string? businessName = null)
{
return await _mediator.Send(new LicenceListSearch(licenceNumber, firstName, lastName, null, ServiceTypeCode.SecurityWorkerLicence));
return await _mediator.Send(new LicenceListSearch(licenceNumber, null, null, businessName, ServiceTypeCode.SecurityBusinessLicence));
}
}
}
2 changes: 1 addition & 1 deletion src/Spd.Resource.Repository/Licence/LicenceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public async Task<LicenceListResp> QueryAsync(LicenceQry qry, CancellationToken
}
if (qry.BizName != null)
{
lics = lics.Where(a => a.spd_LicenceHolder_account.name == qry.BizName || a.spd_LicenceHolder_account.spd_organizationlegalname == qry.BizName);
lics = lics.Where(a => a.spd_LicenceHolder_account.name.StartsWith(qry.BizName) || a.spd_LicenceHolder_account.spd_organizationlegalname.StartsWith(qry.BizName));
}
return new LicenceListResp()
{
Expand Down

0 comments on commit a2dfab2

Please sign in to comment.