From a2dfab2a584a12a8ab257579fe14eb8c073ae663 Mon Sep 17 00:00:00 2001 From: peggy-quartech Date: Thu, 5 Dec 2024 17:05:18 -0800 Subject: [PATCH] biz search --- src/Spd.Manager.Licence/LicenceManager.cs | 6 ++++- .../Controllers/LicenceController.cs | 24 +++++++++++++------ .../Licence/LicenceRepository.cs | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Spd.Manager.Licence/LicenceManager.cs b/src/Spd.Manager.Licence/LicenceManager.cs index 106c84504..dee66f6dd 100644 --- a/src/Spd.Manager.Licence/LicenceManager.cs +++ b/src/Spd.Manager.Licence/LicenceManager.cs @@ -155,7 +155,7 @@ public async Task> 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 { @@ -171,6 +171,10 @@ public async Task> 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 diff --git a/src/Spd.Presentation.Licensing/Controllers/LicenceController.cs b/src/Spd.Presentation.Licensing/Controllers/LicenceController.cs index 45330dc6b..dd7857be9 100644 --- a/src/Spd.Presentation.Licensing/Controllers/LicenceController.cs +++ b/src/Spd.Presentation.Licensing/Controllers/LicenceController.cs @@ -184,18 +184,28 @@ public async Task GetLicence([FromRoute] Guid licenceId, Cancel } /// - /// 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 /// - /// - /// - /// [Route("api/licences/security-worker-licence")] [HttpGet] [AllowAnonymous] - public async Task> GetSecureWorkerLicence([FromQuery] string? licenceNumber, [FromQuery] string? firstName = null, [FromQuery] string? lastName = null) + public async Task> 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)); + } + + /// + /// 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 + /// + [Route("api/licences/business-licence")] + [HttpGet] + [AllowAnonymous] + public async Task> 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)); } } } \ No newline at end of file diff --git a/src/Spd.Resource.Repository/Licence/LicenceRepository.cs b/src/Spd.Resource.Repository/Licence/LicenceRepository.cs index fa4d5ea78..c319bcdb0 100644 --- a/src/Spd.Resource.Repository/Licence/LicenceRepository.cs +++ b/src/Spd.Resource.Repository/Licence/LicenceRepository.cs @@ -91,7 +91,7 @@ public async Task 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() {