Skip to content

Commit

Permalink
fix(dss-465)
Browse files Browse the repository at this point in the history
  • Loading branch information
ychung-mot committed Jun 4, 2024
1 parent 072d23e commit dfb54d7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
34 changes: 28 additions & 6 deletions server/StrDss.Data/Repositories/UploadDeliveryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public interface IUploadDeliveryRepository
Task<bool> IsDuplicateRentalReportUploadAsnyc(DateOnly periodYm, long orgId, string hashValue);
Task AddUploadDeliveryAsync(DssUploadDelivery upload);
Task<DssUploadDelivery?> GetRentalReportUploadToProcessAsync();
Task<DssUploadDelivery?> GetRentalListingErrorLines(long uploadId);
Task<DssUploadDelivery?> GetRentalListingUploadWithErrors(long uploadId);
Task<DssUploadLine?> GetUploadLineAsync(long uploadId, string orgCd, string listingId);
Task<List<UploadLineToProcess>> GetUploadLinesToProcessAsync(long uploadId);
Task<long[]> GetUploadLineIdsWithErrors(long uploadId);
Task<UploadLineError> GetUploadLineWithError(long lineId);
}

public class UploadDeliveryRepository : RepositoryBase<DssUploadDelivery>, IUploadDeliveryRepository
Expand Down Expand Up @@ -72,13 +74,33 @@ public async Task<List<UploadLineToProcess>> GetUploadLinesToProcessAsync(long u
.ToListAsync();
}

public async Task<DssUploadDelivery?> GetRentalListingErrorLines(long uploadId)
public async Task<DssUploadDelivery?> GetRentalListingUploadWithErrors(long uploadId)
{
//todo: data control
var query = _dbSet.AsNoTracking()
.Where(x => x.UploadDeliveryId == uploadId && x.DssUploadLines.Any(x => x.IsSystemFailure || x.IsValidationFailure));

if (_currentUser.OrganizationType == OrganizationTypes.Platform)
{
query = query.Where(x => x.ProvidingOrganizationId == _currentUser.OrganizationId);
}

return await _dbSet.AsNoTracking()
.Include(x => x.DssUploadLines)
.FirstOrDefaultAsync(x => x.UploadDeliveryId == uploadId);
return await query.FirstOrDefaultAsync();
}

public async Task<long[]> GetUploadLineIdsWithErrors(long uploadId)
{
return await _dbContext.DssUploadLines.AsNoTracking()
.Where(x => x.IncludingUploadDeliveryId == uploadId && (x.IsValidationFailure || x.IsSystemFailure))
.Select(x => x.UploadLineId)
.ToArrayAsync();
}

public async Task<UploadLineError> GetUploadLineWithError(long lineId)
{
return await _dbContext.DssUploadLines.AsNoTracking()
.Where(x => x.UploadLineId == lineId)
.Select(x => new UploadLineError { LineText = x.SourceLineTxt, ErrorText = x.ErrorTxt })
.FirstAsync();
}
}
}
8 changes: 8 additions & 0 deletions server/StrDss.Model/UploadLineError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace StrDss.Model
{
public class UploadLineError
{
public string LineText { get; set; } = "";
public string? ErrorText { get; set; } = "";
}
}
17 changes: 5 additions & 12 deletions server/StrDss.Service/RentalListingReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,17 +619,11 @@ public async Task<PagedDto<RentalUploadHistoryViewDto>> GetRentalListingUploadHi

public async Task<byte[]?> GetRentalListingErrorFile(long uploadId)
{
var upload = await _uploadRepo.GetRentalListingErrorLines(uploadId);
var upload = await _uploadRepo.GetRentalListingUploadWithErrors(uploadId);

if (upload == null) return null;

if (_currentUser.OrganizationType == OrganizationTypes.Platform)
{
if (upload.ProvidingOrganizationId != _currentUser.OrganizationId)
{
return null;
}
}
var linesWithError = await _uploadRepo.GetUploadLineIdsWithErrors(uploadId);

var memoryStream = new MemoryStream(upload.SourceBin!);
using TextReader textReader = new StreamReader(memoryStream, Encoding.UTF8);
Expand All @@ -646,11 +640,10 @@ public async Task<PagedDto<RentalUploadHistoryViewDto>> GetRentalListingUploadHi

contents.AppendLine(header);

foreach(var line in upload.DssUploadLines)
foreach (var lineId in linesWithError)
{
if (!line.IsValidationFailure && !line.IsSystemFailure) continue;

contents.AppendLine(line.SourceLineTxt.TrimEndNewLine() + $",\"{line.ErrorTxt}\"");
var line = await _uploadRepo.GetUploadLineWithError(lineId);
contents.AppendLine(line.LineText.TrimEndNewLine() + $",\"{line.ErrorText ?? ""}\"");
}

return Encoding.UTF8.GetBytes(contents.ToString());
Expand Down

0 comments on commit dfb54d7

Please sign in to comment.