mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
refactor(database): update seed pipeline to use dapper (#277)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Features.Locations.Commands.CreateCity;
|
||||
|
||||
public record CreateCityCommand(string CityName, Guid StateProvinceId) : IRequest<Guid>;
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Features.Locations.Commands.CreateCountry;
|
||||
|
||||
public record CreateCountryCommand(string CountryName, string IsoCode) : IRequest<Guid>;
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Features.Locations.Commands.CreateStateProvince;
|
||||
|
||||
public record CreateStateProvinceCommand(string StateProvinceName, string IsoCode, Guid CountryId)
|
||||
: IRequest<Guid>;
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
@@ -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>;
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user