Skip to content

Commit

Permalink
Merge pull request #443 from bcgov/yj
Browse files Browse the repository at this point in the history
Yj
  • Loading branch information
ychung-mot authored Jun 28, 2024
2 parents e0ddca0 + dd0cfbe commit 5ff44c6
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
18 changes: 14 additions & 4 deletions server/StrDss.Api/Controllers/RentalListingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,21 @@ public async Task<ActionResult> GetRentalListing(long listingId)
}

//[ApiAuthorize(Permissions.ListingRead)]
//[HttpGet("exports/lastupdate")]
//public async Task<ActionResult> Export()
//[HttpGet("exports/lg/{lgId}")]
//public async Task<ActionResult> RentalListingExportForLg(long lgId)
//{
// await _listingService.CreateRentalListingExportFiles();
// return Ok();
// if (_currentUser.OrganizationType == OrganizationTypes.LG && _currentUser.OrganizationId != lgId)
// {
// return Unauthorized();
// }

// var source = await _listingService.GetRentalListingExportFileForLg(lgId);
// if (source == null)
// {
// return NotFound();
// }

// return File(source!, "application/zip", $"export-{lgId}.zip");
//}
}
}
5 changes: 5 additions & 0 deletions server/StrDss.Data/Repositories/PhysicalAddressRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IPhysicalAddressRepository
Task AddPhysicalAddressAsync(DssPhysicalAddress address);
Task<DssPhysicalAddress?> GetPhysicalAdderssFromMasterListingAsync(long offeringOrgId, string listingId, string address);
Task<List<DssPhysicalAddress>> GetPhysicalAddressesToCleanUpAsync();
Task ReloadAddressAsync(DssPhysicalAddress address);
}
public class PhysicalAddressRepository : RepositoryBase<DssPhysicalAddress>, IPhysicalAddressRepository
{
Expand Down Expand Up @@ -50,5 +51,9 @@ public async Task<List<DssPhysicalAddress>> GetPhysicalAddressesToCleanUpAsync()
.Take(300)
.ToListAsync();
}
public async Task ReloadAddressAsync(DssPhysicalAddress address)
{
await _dbContext.Entry(address).ReloadAsync();
}
}
}
44 changes: 44 additions & 0 deletions server/StrDss.Service/RentalListingReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,15 @@ public async Task CleaupAddressAsync()

stopwatchForGeocoder.Stop();

var validationErrors = ValidateStringLengths(address);
if (validationErrors.Any())
{
_logger.LogWarning($"Address Cleanup: {address.OriginalAddressTxt} - Address validation errors: {string.Join(", ", validationErrors)}");

await _addressRepo.ReloadAddressAsync(address);
address.IsSystemProcessing = false;
}

_logger.LogInformation($"Address Cleanup (geocoder): {stopwatchForGeocoder.Elapsed.TotalMilliseconds} milliseconds - {processedCount}/{totalCount}");

_unitOfWork.Commit();
Expand All @@ -697,5 +706,40 @@ public async Task CleaupAddressAsync()
stopwatch.Stop();
_logger.LogInformation($"Address Cleanup Finished: {stopwatch.Elapsed.TotalSeconds} seconds");
}

private static List<string> ValidateStringLengths(DssPhysicalAddress address)
{
var errors = new List<string>();
var maxLengths = new Dictionary<string, int>
{
{ nameof(DssPhysicalAddress.OriginalAddressTxt), 250 },
{ nameof(DssPhysicalAddress.MatchAddressTxt), 250 },
{ nameof(DssPhysicalAddress.SiteNo), 50 },
{ nameof(DssPhysicalAddress.BlockNo), 50 },
{ nameof(DssPhysicalAddress.UnitNo), 50 },
{ nameof(DssPhysicalAddress.CivicNo), 50 },
{ nameof(DssPhysicalAddress.StreetNm), 50 },
{ nameof(DssPhysicalAddress.StreetTypeDsc), 50 },
{ nameof(DssPhysicalAddress.StreetDirectionDsc), 50 },
{ nameof(DssPhysicalAddress.LocalityNm), 50 },
{ nameof(DssPhysicalAddress.LocalityTypeDsc), 50 },
{ nameof(DssPhysicalAddress.ProvinceCd), 5 }
};

foreach (var property in address.GetType().GetProperties())
{
if (property.PropertyType == typeof(string))
{
var value = property.GetValue(address) as string;
if (value != null && maxLengths.ContainsKey(property.Name) && value.Length > maxLengths[property.Name])
{
errors.Add($"{property.Name} exceeds maximum length of {maxLengths[property.Name]} characters.");
}
}
}

return errors;
}

}
}
8 changes: 8 additions & 0 deletions server/StrDss.Service/RentalListingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface IRentalListingService
Task<PagedDto<RentalListingViewDto>> GetRentalListings(string? all, string? address, string? url, string? listingId, string? hostName, string? businessLicense, int pageSize, int pageNumber, string orderBy, string direction);
Task<RentalListingViewDto?> GetRentalListing(long rentalListingId);
Task CreateRentalListingExportFiles();
Task<byte[]?> GetRentalListingExportFileForLg(long lgId);
}
public class RentalListingService : ServiceBase, IRentalListingService
{
Expand Down Expand Up @@ -300,5 +301,12 @@ private static string FormatCsvField(object? field)

return fieldString;
}

public async Task<byte[]?> GetRentalListingExportFileForLg(long lgId)
{
var extract = await _listingRepo.GetRentalListingExtractByOrgId(lgId);

return extract.SourceBin;
}
}
}

0 comments on commit 5ff44c6

Please sign in to comment.