Skip to content

Commit

Permalink
Merge pull request #2064 from bcgov/bug/TCVP-3173
Browse files Browse the repository at this point in the history
TCVP-3173 fix and simplify look ups
  • Loading branch information
pbolduc authored Feb 5, 2025
2 parents 5bb5d5c + d4583eb commit 8f2d17d
Show file tree
Hide file tree
Showing 27 changed files with 239 additions and 469 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ namespace TrafficCourts.Citizen.Service.Features.Lookups.Languages;

public class Handler : IRequestHandler<Request, Response>
{
private readonly ICachedLookupService<Language> _service;
public Handler(ICachedLookupService<Language> service)
private readonly ILanguageRepository _repository;
public Handler(ILanguageRepository repository)
{
_service = service ?? throw new ArgumentNullException(nameof(service));
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
}

public async Task<Response> Handle(Request request, CancellationToken cancellationToken)
{
var key = Caching.Cache.Api.Languages(2);

var items = await _service.GetListAsync(key, TimeSpan.FromDays(1), cancellationToken);
var items = await _repository.GetListAsync(cancellationToken);

var models = items.Select(item => item.ToDomainModel())
.ToList();

return new Response(models);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ namespace TrafficCourts.Citizen.Service.Features.Lookups.Statutes;
public class Handler : IRequestHandler<Request, Response>
{
private readonly IStatuteLookupService _service;

public Handler(IStatuteLookupService service)
{
_service = service ?? throw new ArgumentNullException(nameof(service));
}
public async Task<Response> Handle(Request request, CancellationToken cancellationToken)
{
var key = Caching.Cache.Api.Languages(2);
var key = Caching.Cache.Api.Statutes(3);

IEnumerable<Domain.Models.Statute> models = await _service.GetListAsync(cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ namespace TrafficCourts.Citizen.Service.Services.Lookups;

public class StatuteLookupService : IStatuteLookupService
{
private readonly ICachedLookupService<Statute> _repository;
private readonly IStatuteRepository _repository;

public StatuteLookupService(ICachedLookupService<Statute> repository)
public StatuteLookupService(IStatuteRepository repository)
{
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
}

public async Task<TrafficCourts.Domain.Models.Statute?> GetBySectionAsync(string section, CancellationToken cancellationToken)
{
var items = await GetAsync(cancellationToken);
var items = await _repository.GetListAsync(cancellationToken);

var buffer = new StringBuilder();
var models = items.Select(_ => _.ToDomainModel(buffer)).ToList();
Expand All @@ -25,7 +25,7 @@ public StatuteLookupService(ICachedLookupService<Statute> repository)

public async Task<TrafficCourts.Domain.Models.Statute?> GetByIdAsync(int statuteId, CancellationToken cancellationToken)
{
var items = await GetAsync(cancellationToken);
var items = await _repository.GetListAsync(cancellationToken);

var index = items.BinarySearch(
new Statute { stat_id = statuteId },
Expand All @@ -41,19 +41,12 @@ public StatuteLookupService(ICachedLookupService<Statute> repository)

public async Task<IList<TrafficCourts.Domain.Models.Statute>> GetListAsync(CancellationToken cancellationToken)
{
var items = await GetAsync(cancellationToken);
var items = await _repository.GetListAsync(cancellationToken);

var buffer = new StringBuilder();

var models = items.Select(x => x.ToDomainModel(buffer)).ToList();

return models;
}

private async Task<List<Statute>> GetAsync(CancellationToken cancellationToken)
{
var key = Caching.Cache.Api.Statutes(2);
var items = await _repository.GetListAsync(key, TimeSpan.FromHours(2), cancellationToken);
return items;
}
}
23 changes: 0 additions & 23 deletions src/backend/TrafficCourts/Staff.Service/Caching/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,4 @@ public static class OracleData
/// <param name="version">The version of the data structure. If new data structure is used, defined a new version. Defaults to 1.</param>
public static string DisputeListItems(int version = 1) => $"oracle:v{version}:all:dispute-list-items";
}

/// <summary>
/// Api named cache. Stores data cached queried returned fro the API, primarily code tables.
/// </summary>
public static class Api
{
public static string Agencies(int version = 1) => $"staff-api:v{version}:agencies";
public static string Agencies(string type, int version = 1) => $"staff-api:v{version}:agencies:{type}";

public static string Countries(int version = 1) => $"staff-api:v{version}:countries";

public static string Languages(int version = 1) => $"staff-api:v{version}:languages";
public static string Provinces(int version = 1) => $"staff-api:v{version}:provinces";

public static string DisputeCaseFileStatusTypes(int version = 1) => $"staff-api:v{version}:tco:dispute-status_types";

/// <summary>
/// Stores the list of statutues
/// </summary>
/// <param name="version">The version of the data structure. If new data structure is used, defined a new version. Defaults to 1.</param>
public static string Statutes(int version = 1) => $"staff-api:v{version}:statutes";

}
}
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);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

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;
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
using MediatR;
using TrafficCourts.Domain.Models;
using TrafficCourts.OrdsDataService.Tco;
using ZiggyCreatures.Caching.Fusion;

namespace TrafficCourts.Staff.Service.Features.Lookups.DisputeCaseFileStatusTypes;

public class Handler : IRequestHandler<Request, Response>
{
private readonly IDisputeStatusTypeRepository _repository;
private readonly IFusionCache _cache;
private readonly ILogger<Handler> _logger;

public Handler(IDisputeStatusTypeRepository repository, IFusionCache cache, ILogger<Handler> logger)
public Handler(IDisputeStatusTypeRepository repository)
{
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
_cache = cache ?? throw new ArgumentNullException(nameof(cache));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

public async Task<Response> Handle(Request request, CancellationToken cancellationToken)
{
var key = Caching.Cache.Api.DisputeCaseFileStatusTypes(2);

var items = await _cache.GetOrSetAsync<List<DisputeCaseFileStatus>> (
key,
GetItems,
options => options.SetDuration(TimeSpan.FromMinutes(60)),
token: cancellationToken);

return new Response(items);
}

private async Task<List<DisputeCaseFileStatus>> GetItems(CancellationToken cancellationToken)
{
var items = await _repository.GetListAsync(cancellationToken);

Expand All @@ -41,6 +23,6 @@ private async Task<List<DisputeCaseFileStatus>> GetItems(CancellationToken cance
Description = item.dispute_status_type_dsc
}).ToList();

return models;
return new Response(models);
}
}
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;
}
}
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);
}
}
Loading

0 comments on commit 8f2d17d

Please sign in to comment.