Skip to content

Commit

Permalink
return the same set documents (#1445)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

-return the same set documents
  • Loading branch information
peggy-quartech authored Sep 28, 2024
1 parent 07e8fe8 commit e1ca270
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
12 changes: 2 additions & 10 deletions src/Spd.Manager.Licence/LicenceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IEnumerable<Document>>(docList.Items.Where(i => i.ApplicationId == appId).ToList());
}
lic.DogDocumentInfos = _mapper.Map<IEnumerable<Document>>(docList.Items);
}
}

Expand All @@ -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<IEnumerable<Document>>(docList.Items.Where(i => i.ApplicationId == appId).ToList());
}
lic.RestraintsDocumentInfos = _mapper.Map<IEnumerable<Document>>(docList.Items);
}
}
}
3 changes: 2 additions & 1 deletion src/Spd.Resource.Repository/Document/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public record DocumentQry(
Guid? LicenceId = null,
Guid? AccountId = null,
DocumentTypeEnum? FileType = null,
IEnumerable<DocumentTypeEnum>? MultiFileTypes = null);
IEnumerable<DocumentTypeEnum>? MultiFileTypes = null,
bool OnlyReturnLatestSet = true);
public record DocumentListResp
{
public IEnumerable<DocumentResp> Items { get; set; } = Array.Empty<DocumentResp>();
Expand Down
27 changes: 18 additions & 9 deletions src/Spd.Resource.Repository/Document/DocumentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,19 @@ public async Task<DocumentListResp> QueryAsync(DocumentQry qry, CancellationToke
}

var results = await documents.GetAllPagesAsync(ct);

IEnumerable<DocumentResp> resp = null;
if (qry.MultiFileTypes != null)
{
List<Guid> tagIds = qry.MultiFileTypes.Select(f => DynamicsContextLookupHelpers.BcGovTagDictionary.GetValueOrDefault(f.ToString())).ToList();
List<bcgov_documenturl> result = results.Where(d => tagIds.Contains(d._bcgov_tag1id_value.Value)).ToList();
return new DocumentListResp
{
Items = _mapper.Map<IEnumerable<DocumentResp>>(result.OrderByDescending(a => a.createdon))
};
resp = _mapper.Map<IEnumerable<DocumentResp>>(result.OrderByDescending(a => a.createdon));
}
else
{
results = results.OrderByDescending(a => a.createdon);
return new DocumentListResp
{
Items = _mapper.Map<IEnumerable<DocumentResp>>(results)
};
resp = _mapper.Map<IEnumerable<DocumentResp>>(results);
}
return qry.OnlyReturnLatestSet ? new DocumentListResp { Items = GetLatestSet(resp) } : new DocumentListResp { Items = resp };
}

public async Task<DocumentResp> ManageAsync(DocumentCmd cmd, CancellationToken ct)
Expand Down Expand Up @@ -112,6 +107,20 @@ private async Task<DocumentResp> DocumentReactivateAsync(ReactivateDocumentCmd c
return _mapper.Map<DocumentResp>(documenturl);
}

//if the documents are in the same application, then we use applicationId to indicate its set. Or we use uploadedDatetime
private IEnumerable<DocumentResp> GetLatestSet(IEnumerable<DocumentResp> 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<DocumentResp> DocumentCreateAsync(CreateDocumentCmd cmd, CancellationToken ct)
{
bcgov_documenturl documenturl = _mapper.Map<bcgov_documenturl>(cmd.TempFile);
Expand Down

0 comments on commit e1ca270

Please sign in to comment.