diff --git a/src/Spd.Manager.Licence/LicenceManager.cs b/src/Spd.Manager.Licence/LicenceManager.cs index 82517b01c..1342c0cb1 100644 --- a/src/Spd.Manager.Licence/LicenceManager.cs +++ b/src/Spd.Manager.Licence/LicenceManager.cs @@ -193,11 +193,7 @@ private async Task GetDogRestraintsInfoAsync(LicenceResponse lic, CancellationTo FileType = DocumentTypeEnum.DogCertificate }, cancellationToken); - if (docList.Items.Any()) - { - Guid appId = docList.Items.OrderByDescending(i => i.UploadedDateTime).FirstOrDefault().ApplicationId.Value; - lic.DogDocumentInfos = _mapper.Map>(docList.Items.Where(i => i.ApplicationId == appId).ToList()); - } + lic.DogDocumentInfos = _mapper.Map>(docList.Items); } } @@ -211,11 +207,7 @@ private async Task GetDogRestraintsInfoAsync(LicenceResponse lic, CancellationTo MultiFileTypes = new[] { DocumentTypeEnum.ASTCertificate, DocumentTypeEnum.UseForceEmployerLetter, DocumentTypeEnum.UseForceEmployerLetterASTEquivalent } }, cancellationToken); - if (docList.Items.Any()) - { - Guid appId = docList.Items.OrderByDescending(i => i.UploadedDateTime).FirstOrDefault().ApplicationId.Value; - lic.RestraintsDocumentInfos = _mapper.Map>(docList.Items.Where(i => i.ApplicationId == appId).ToList()); - } + lic.RestraintsDocumentInfos = _mapper.Map>(docList.Items); } } } diff --git a/src/Spd.Resource.Repository/Document/Contract.cs b/src/Spd.Resource.Repository/Document/Contract.cs index 088c84ce7..3759707fc 100644 --- a/src/Spd.Resource.Repository/Document/Contract.cs +++ b/src/Spd.Resource.Repository/Document/Contract.cs @@ -18,7 +18,8 @@ public record DocumentQry( Guid? LicenceId = null, Guid? AccountId = null, DocumentTypeEnum? FileType = null, - IEnumerable? MultiFileTypes = null); + IEnumerable? MultiFileTypes = null, + bool OnlyReturnLatestSet = true); public record DocumentListResp { public IEnumerable Items { get; set; } = Array.Empty(); diff --git a/src/Spd.Resource.Repository/Document/DocumentRepository.cs b/src/Spd.Resource.Repository/Document/DocumentRepository.cs index c4f33fe6f..cf8948cf6 100644 --- a/src/Spd.Resource.Repository/Document/DocumentRepository.cs +++ b/src/Spd.Resource.Repository/Document/DocumentRepository.cs @@ -67,24 +67,19 @@ public async Task QueryAsync(DocumentQry qry, CancellationToke } var results = await documents.GetAllPagesAsync(ct); - + IEnumerable resp = null; if (qry.MultiFileTypes != null) { List tagIds = qry.MultiFileTypes.Select(f => DynamicsContextLookupHelpers.BcGovTagDictionary.GetValueOrDefault(f.ToString())).ToList(); List result = results.Where(d => tagIds.Contains(d._bcgov_tag1id_value.Value)).ToList(); - return new DocumentListResp - { - Items = _mapper.Map>(result.OrderByDescending(a => a.createdon)) - }; + resp = _mapper.Map>(result.OrderByDescending(a => a.createdon)); } else { results = results.OrderByDescending(a => a.createdon); - return new DocumentListResp - { - Items = _mapper.Map>(results) - }; + resp = _mapper.Map>(results); } + return qry.OnlyReturnLatestSet ? new DocumentListResp { Items = GetLatestSet(resp) } : new DocumentListResp { Items = resp }; } public async Task ManageAsync(DocumentCmd cmd, CancellationToken ct) @@ -112,6 +107,20 @@ private async Task DocumentReactivateAsync(ReactivateDocumentCmd c return _mapper.Map(documenturl); } + //if the documents are in the same application, then we use applicationId to indicate its set. Or we use uploadedDatetime + private IEnumerable GetLatestSet(IEnumerable resp) + { + if (resp.Any()) + { + DocumentResp? doc = resp.FirstOrDefault(); + if (doc?.ApplicationId == null) + return resp.Where(i => i.UploadedDateTime == doc.UploadedDateTime).ToList(); + else + return resp.Where(i => i.ApplicationId == doc.ApplicationId).ToList(); + } + return resp; + } + private async Task DocumentCreateAsync(CreateDocumentCmd cmd, CancellationToken ct) { bcgov_documenturl documenturl = _mapper.Map(cmd.TempFile);