mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-07-16 17:47:22 +00:00
code style cleanup
This commit is contained in:
@@ -4,7 +4,7 @@ using MediatR;
|
||||
namespace Features.Breweries.Commands.CreateBrewery;
|
||||
|
||||
/// <summary>
|
||||
/// Location data required to create a new brewery post, supplied as part of <see cref="CreateBreweryCommand"/>.
|
||||
/// Location data required to create a new brewery post, supplied as part of <see cref="CreateBreweryCommand" />.
|
||||
/// </summary>
|
||||
public record CreateBreweryLocation(
|
||||
Guid CityId,
|
||||
@@ -15,11 +15,11 @@ public record CreateBreweryLocation(
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new brewery post. Bound directly from the request body of <c>POST /api/brewery</c>.
|
||||
/// Creates a new brewery post. Bound directly from the request body of <c>POST /api/brewery</c>.
|
||||
/// </summary>
|
||||
public record CreateBreweryCommand(
|
||||
Guid PostedById,
|
||||
string BreweryName,
|
||||
string Description,
|
||||
CreateBreweryLocation Location
|
||||
) : IRequest<BreweryDto>;
|
||||
) : IRequest<BreweryDto>;
|
||||
@@ -6,21 +6,21 @@ using MediatR;
|
||||
namespace Features.Breweries.Commands.CreateBrewery;
|
||||
|
||||
/// <summary>
|
||||
/// Handles <see cref="CreateBreweryCommand"/> by persisting a new brewery post and its location.
|
||||
/// Handles <see cref="CreateBreweryCommand" /> by persisting a new brewery post and its location.
|
||||
/// </summary>
|
||||
/// <param name="repository">Repository used to persist the new brewery post.</param>
|
||||
public class CreateBreweryHandler(IBreweryRepository repository)
|
||||
: IRequestHandler<CreateBreweryCommand, BreweryDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new brewery post, generating new identifiers for the post and its location.
|
||||
/// Creates a new brewery post, generating new identifiers for the post and its location.
|
||||
/// </summary>
|
||||
/// <param name="request">The details of the brewery post to create.</param>
|
||||
/// <param name="cancellationToken">A token to observe for cancellation requests.</param>
|
||||
/// <returns>The newly created brewery post.</returns>
|
||||
public async Task<BreweryDto> Handle(CreateBreweryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = new BreweryPost
|
||||
BreweryPost entity = new()
|
||||
{
|
||||
BreweryPostId = Guid.NewGuid(),
|
||||
PostedById = request.PostedById,
|
||||
@@ -34,11 +34,11 @@ public class CreateBreweryHandler(IBreweryRepository repository)
|
||||
AddressLine1 = request.Location.AddressLine1,
|
||||
AddressLine2 = request.Location.AddressLine2,
|
||||
PostalCode = request.Location.PostalCode,
|
||||
Coordinates = request.Location.Coordinates,
|
||||
},
|
||||
Coordinates = request.Location.Coordinates
|
||||
}
|
||||
};
|
||||
|
||||
await repository.CreateAsync(entity);
|
||||
return entity.ToDto();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,15 @@ using FluentValidation;
|
||||
namespace Features.Breweries.Commands.CreateBrewery;
|
||||
|
||||
/// <summary>
|
||||
/// Validates <see cref="CreateBreweryCommand"/> instances before they are processed.
|
||||
/// Validates <see cref="CreateBreweryCommand" /> instances before they are processed.
|
||||
/// </summary>
|
||||
public class CreateBreweryValidator : AbstractValidator<CreateBreweryCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures validation rules requiring <see cref="CreateBreweryCommand.PostedById"/>,
|
||||
/// <see cref="CreateBreweryCommand.BreweryName"/>, <see cref="CreateBreweryCommand.Description"/>, and
|
||||
/// <see cref="CreateBreweryCommand.Location"/> to be present, with length limits on the name, description,
|
||||
/// address line 1, and postal code fields.
|
||||
/// Configures validation rules requiring <see cref="CreateBreweryCommand.PostedById" />,
|
||||
/// <see cref="CreateBreweryCommand.BreweryName" />, <see cref="CreateBreweryCommand.Description" />, and
|
||||
/// <see cref="CreateBreweryCommand.Location" /> to be present, with length limits on the name, description,
|
||||
/// address line 1, and postal code fields.
|
||||
/// </summary>
|
||||
public CreateBreweryValidator()
|
||||
{
|
||||
@@ -56,4 +56,4 @@ public class CreateBreweryValidator : AbstractValidator<CreateBreweryCommand>
|
||||
.When(x => x.Location is not null)
|
||||
.WithMessage("Postal code cannot exceed 20 characters.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user