-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2064 from bcgov/bug/TCVP-3173
TCVP-3173 fix and simplify look ups
- Loading branch information
Showing
27 changed files
with
239 additions
and
469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 10 additions & 26 deletions
36
src/backend/TrafficCourts/Staff.Service/Features/Lookups/Agencies/Handler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,26 @@ | ||
using MassTransit.Initializers; | ||
using MediatR; | ||
using TrafficCourts.OrdsDataService.Justin; | ||
using MediatR; | ||
using TrafficCourts.Staff.Service.Services; | ||
|
||
namespace TrafficCourts.Staff.Service.Features.Lookups.Agencies; | ||
|
||
public class Handler : IRequestHandler<Request, Response> | ||
{ | ||
private readonly ICachedLookupService<Agency> _service; | ||
private readonly ILogger<Handler> _logger; | ||
private readonly IAgencyLookupService _service; | ||
|
||
public Handler(ICachedLookupService<Agency> service, ILogger<Handler> logger) | ||
public Handler(IAgencyLookupService service) | ||
{ | ||
_service = service ?? throw new ArgumentNullException(nameof(service)); | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
} | ||
|
||
public async Task<Response> Handle(Request request, CancellationToken cancellationToken) | ||
{ | ||
var key = Caching.Cache.Api.Agencies(2); | ||
var items = await _service.GetListAsync(cancellationToken); | ||
|
||
List<Agency> items = await _service.GetListAsync(key, TimeSpan.FromHours(1), cancellationToken); | ||
if (!string.IsNullOrWhiteSpace(request.Type)) | ||
{ | ||
items = items.Where(_ => _.TypeCode == request.Type).ToList(); | ||
} | ||
|
||
List<Domain.Models.Agency> models = request.Type is not null | ||
? items.Where(_ => _.cdat_agency_type_cd == request.Type).Select(ToDomainModel).ToList() | ||
: items.Select(ToDomainModel).ToList(); | ||
|
||
return new Response(models); | ||
} | ||
|
||
private Domain.Models.Agency ToDomainModel(Agency item) | ||
{ | ||
var model = new Domain.Models.Agency | ||
( | ||
item.agen_id.ToString(), | ||
item.agen_agency_nm, | ||
item.cdat_agency_type_cd | ||
); | ||
|
||
return model; | ||
return new Response(items); | ||
} | ||
} |
6 changes: 0 additions & 6 deletions
6
src/backend/TrafficCourts/Staff.Service/Features/Lookups/Cities/Handler.cs
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
src/backend/TrafficCourts/Staff.Service/Features/Lookups/Cities/Request.cs
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
src/backend/TrafficCourts/Staff.Service/Features/Lookups/Cities/Response.cs
This file was deleted.
Oops, something went wrong.
36 changes: 6 additions & 30 deletions
36
src/backend/TrafficCourts/Staff.Service/Features/Lookups/Countries/Handler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,20 @@ | ||
using MediatR; | ||
using TrafficCourts.OrdsDataService.Justin; | ||
using ZiggyCreatures.Caching.Fusion; | ||
using TrafficCourts.Staff.Service.Services; | ||
|
||
namespace TrafficCourts.Staff.Service.Features.Lookups.Countries; | ||
|
||
public class Handler : IRequestHandler<Request, Response> | ||
{ | ||
private readonly ICountryRepository _repository; | ||
private readonly IFusionCache _cache; | ||
private readonly ILogger<Handler> _handler; | ||
private readonly ICountryLookupService _service; | ||
|
||
public Handler(ICountryRepository repository, IFusionCache cache, ILogger<Handler> handler) | ||
public Handler(ICountryLookupService service) | ||
{ | ||
_repository = repository ?? throw new ArgumentNullException(nameof(repository)); | ||
_cache = cache ?? throw new ArgumentNullException(nameof(cache)); | ||
_handler = handler ?? throw new ArgumentNullException(nameof(handler)); | ||
_service = service ?? throw new ArgumentNullException(nameof(service)); | ||
} | ||
|
||
public async Task<Response> Handle(Request request, CancellationToken cancellationToken) | ||
{ | ||
var key = Caching.Cache.Api.Countries(2); | ||
|
||
var items = await _cache.GetOrSetAsync<List<Domain.Models.Country>>( | ||
key, | ||
ct => GetItems(ct), | ||
options => options.SetDuration(TimeSpan.FromMinutes(10)), | ||
token: cancellationToken); | ||
|
||
var items = await _service.GetListAsync(cancellationToken); | ||
return new Response(items); | ||
} | ||
|
||
private async Task<List<Domain.Models.Country>> GetItems(CancellationToken cancellationToken) | ||
{ | ||
var items = await _repository.GetListAsync(cancellationToken); | ||
|
||
var models = items.Select(_ => new Domain.Models.Country | ||
( | ||
_.ctry_id.ToString(), | ||
_.ctry_long_nm | ||
)).ToList(); | ||
|
||
return models; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 6 additions & 29 deletions
35
src/backend/TrafficCourts/Staff.Service/Features/Lookups/Languages/Handler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,21 @@ | ||
using MediatR; | ||
using TrafficCourts.OrdsDataService.Justin; | ||
using ZiggyCreatures.Caching.Fusion; | ||
using TrafficCourts.Staff.Service.Services; | ||
|
||
namespace TrafficCourts.Staff.Service.Features.Lookups.Languages; | ||
|
||
public class Handler : IRequestHandler<Request, Response> | ||
{ | ||
private readonly ILanguageRepository _repository; | ||
private readonly IFusionCache _cache; | ||
private readonly ILogger<Handler> _handler; | ||
private readonly ILanguageLookupService _service; | ||
|
||
public Handler(ILanguageRepository repository, IFusionCache cache, ILogger<Handler> handler) | ||
public Handler(ILanguageLookupService service) | ||
{ | ||
_repository = repository ?? throw new ArgumentNullException(nameof(repository)); | ||
_cache = cache ?? throw new ArgumentNullException(nameof(cache)); | ||
_handler = handler ?? throw new ArgumentNullException(nameof(handler)); | ||
_service = service ?? throw new ArgumentNullException(nameof(service)); | ||
} | ||
|
||
public async Task<Response> Handle(Request request, CancellationToken cancellationToken) | ||
{ | ||
var key = Caching.Cache.Api.Languages(2); | ||
|
||
var items = await _cache.GetOrSetAsync<List<Domain.Models.Language>>( | ||
key, | ||
ct => GetItems(ct), | ||
options => options.SetDuration(TimeSpan.FromMinutes(10)), | ||
token: cancellationToken); | ||
|
||
var items = await _service.GetListAsync(cancellationToken); | ||
return new Response(items); | ||
} | ||
|
||
private async Task<List<Domain.Models.Language>> GetItems(CancellationToken cancellationToken) | ||
{ | ||
var items = await _repository.GetListAsync(cancellationToken); | ||
|
||
var models = items.Select(_ => new Domain.Models.Language | ||
( | ||
_.cdln_language_cd, | ||
_.cdln_language_dsc | ||
)).ToList(); | ||
|
||
return models; | ||
} | ||
} |
20 changes: 14 additions & 6 deletions
20
src/backend/TrafficCourts/Staff.Service/Features/Lookups/Provinces/Handler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
using MediatR; | ||
using TrafficCourts.Staff.Service.Services; | ||
using TrafficCourts.OrdsDataService.Justin; | ||
|
||
namespace TrafficCourts.Staff.Service.Features.Lookups.Provinces; | ||
|
||
public class Handler : IRequestHandler<Request, Response> | ||
{ | ||
private readonly IProvinceLookupService _lookupService; | ||
private readonly IProvinceRepository _repository; | ||
|
||
public Handler(IProvinceLookupService lookupService) | ||
public Handler(IProvinceRepository repository) | ||
{ | ||
_lookupService = lookupService ?? throw new ArgumentNullException(nameof(lookupService)); | ||
_repository = repository ?? throw new ArgumentNullException(nameof(repository)); | ||
} | ||
|
||
public async Task<Response> Handle(Request request, CancellationToken cancellationToken) | ||
{ | ||
var items = await _lookupService.GetListAsync(cancellationToken); | ||
var items = await _repository.GetListAsync(cancellationToken); | ||
|
||
return new Response(items); | ||
var models = items.Select(_ => new Domain.Models.Province | ||
( | ||
_.ctry_id.ToString(), | ||
_.prov_seq_no.ToString(), | ||
_.prov_nm, | ||
_.prov_abbreviation_cd | ||
)).ToList(); | ||
|
||
return new Response(models); | ||
} | ||
} |
Oops, something went wrong.