refactor(database): update seed pipeline to use dapper (#277)

This commit is contained in:
Aaron Po
2026-09-05 00:37:14 -04:00
committed by GitHub
parent 78ad32e93a
commit d9411eb00e
43 changed files with 1023 additions and 735 deletions

View File

@@ -0,0 +1,5 @@
using MediatR;
namespace Features.Locations.Commands.CreateCity;
public record CreateCityCommand(string CityName, Guid StateProvinceId) : IRequest<Guid>;

View File

@@ -0,0 +1,11 @@
using Features.Locations.Repository;
using MediatR;
namespace Features.Locations.Commands.CreateCity;
public class CreateCityHandler(ILocationRepository repository)
: IRequestHandler<CreateCityCommand, Guid>
{
public Task<Guid> Handle(CreateCityCommand request, CancellationToken cancellationToken) =>
repository.CreateCityAsync(request.CityName, request.StateProvinceId);
}

View File

@@ -0,0 +1,5 @@
using MediatR;
namespace Features.Locations.Commands.CreateCountry;
public record CreateCountryCommand(string CountryName, string IsoCode) : IRequest<Guid>;

View File

@@ -0,0 +1,11 @@
using Features.Locations.Repository;
using MediatR;
namespace Features.Locations.Commands.CreateCountry;
public class CreateCountryHandler(ILocationRepository repository)
: IRequestHandler<CreateCountryCommand, Guid>
{
public Task<Guid> Handle(CreateCountryCommand request, CancellationToken cancellationToken) =>
repository.CreateCountryAsync(request.CountryName, request.IsoCode);
}

View File

@@ -0,0 +1,6 @@
using MediatR;
namespace Features.Locations.Commands.CreateStateProvince;
public record CreateStateProvinceCommand(string StateProvinceName, string IsoCode, Guid CountryId)
: IRequest<Guid>;

View File

@@ -0,0 +1,18 @@
using Features.Locations.Repository;
using MediatR;
namespace Features.Locations.Commands.CreateStateProvince;
public class CreateStateProvinceHandler(ILocationRepository repository)
: IRequestHandler<CreateStateProvinceCommand, Guid>
{
public Task<Guid> Handle(
CreateStateProvinceCommand request,
CancellationToken cancellationToken
) =>
repository.CreateStateProvinceAsync(
request.StateProvinceName,
request.IsoCode,
request.CountryId
);
}

View File

@@ -1,12 +0,0 @@
using Features.Locations.Dtos;
using MediatR;
namespace Features.Locations.Commands.GetOrCreateCity;
/// <summary>
/// Resolves <see cref="City" /> to a City ID, creating the Country, StateProvince, and/or City rows
/// if any part of the chain doesn't exist yet. Sent by other features' handlers (e.g. brewery
/// creation) rather than bound from a request directly, since this feature exposes no controller of
/// its own.
/// </summary>
public record GetOrCreateCityCommand(CityLocation City) : IRequest<Guid>;

View File

@@ -1,12 +0,0 @@
using Features.Locations.Repository;
using MediatR;
namespace Features.Locations.Commands.GetOrCreateCity;
/// <summary>Handles <see cref="GetOrCreateCityCommand" /> by delegating to <see cref="ILocationRepository" />.</summary>
public class GetOrCreateCityHandler(ILocationRepository repository)
: IRequestHandler<GetOrCreateCityCommand, Guid>
{
public Task<Guid> Handle(GetOrCreateCityCommand request, CancellationToken cancellationToken) =>
repository.GetOrCreateCityIdAsync(request.City);
}