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.UpdateBrewery;
|
||||
|
||||
/// <summary>
|
||||
/// Location data for an existing brewery post, supplied as part of <see cref="UpdateBreweryCommand"/>.
|
||||
/// Location data for an existing brewery post, supplied as part of <see cref="UpdateBreweryCommand" />.
|
||||
/// </summary>
|
||||
public record UpdateBreweryLocation(
|
||||
Guid BreweryPostLocationId,
|
||||
@@ -16,8 +16,8 @@ public record UpdateBreweryLocation(
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing brewery post. Bound directly from the request body of <c>PUT /api/brewery/{id}</c>.
|
||||
/// A <c>null</c> <see cref="Location"/> clears the brewery's location.
|
||||
/// Updates an existing brewery post. Bound directly from the request body of <c>PUT /api/brewery/{id}</c>.
|
||||
/// A <c>null</c> <see cref="Location" /> clears the brewery's location.
|
||||
/// </summary>
|
||||
public record UpdateBreweryCommand(
|
||||
Guid BreweryPostId,
|
||||
@@ -25,4 +25,4 @@ public record UpdateBreweryCommand(
|
||||
string BreweryName,
|
||||
string Description,
|
||||
UpdateBreweryLocation? Location
|
||||
) : IRequest<BreweryDto>;
|
||||
) : IRequest<BreweryDto>;
|
||||
@@ -6,41 +6,43 @@ using MediatR;
|
||||
namespace Features.Breweries.Commands.UpdateBrewery;
|
||||
|
||||
/// <summary>
|
||||
/// Handles <see cref="UpdateBreweryCommand"/> by persisting changes to an existing brewery post.
|
||||
/// Handles <see cref="UpdateBreweryCommand" /> by persisting changes to an existing brewery post.
|
||||
/// </summary>
|
||||
/// <param name="repository">Repository used to persist the updated brewery post.</param>
|
||||
public class UpdateBreweryHandler(IBreweryRepository repository)
|
||||
: IRequestHandler<UpdateBreweryCommand, BreweryDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Updates an existing brewery post. If <paramref name="request"/> has no <c>Location</c>,
|
||||
/// the brewery's location is cleared.
|
||||
/// Updates an existing brewery post. If <paramref name="request" /> has no <c>Location</c>,
|
||||
/// the brewery's location is cleared.
|
||||
/// </summary>
|
||||
/// <param name="request">The updated details of the brewery post.</param>
|
||||
/// <param name="cancellationToken">A token to observe for cancellation requests.</param>
|
||||
/// <returns>The updated brewery post.</returns>
|
||||
public async Task<BreweryDto> Handle(UpdateBreweryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = new BreweryPost
|
||||
BreweryPost entity = new()
|
||||
{
|
||||
BreweryPostId = request.BreweryPostId,
|
||||
PostedById = request.PostedById,
|
||||
BreweryName = request.BreweryName,
|
||||
Description = request.Description,
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
Location = request.Location is null ? null : new BreweryPostLocation
|
||||
{
|
||||
BreweryPostLocationId = request.Location.BreweryPostLocationId,
|
||||
BreweryPostId = request.BreweryPostId,
|
||||
CityId = request.Location.CityId,
|
||||
AddressLine1 = request.Location.AddressLine1,
|
||||
AddressLine2 = request.Location.AddressLine2,
|
||||
PostalCode = request.Location.PostalCode,
|
||||
Coordinates = request.Location.Coordinates,
|
||||
},
|
||||
Location = request.Location is null
|
||||
? null
|
||||
: new BreweryPostLocation
|
||||
{
|
||||
BreweryPostLocationId = request.Location.BreweryPostLocationId,
|
||||
BreweryPostId = request.BreweryPostId,
|
||||
CityId = request.Location.CityId,
|
||||
AddressLine1 = request.Location.AddressLine1,
|
||||
AddressLine2 = request.Location.AddressLine2,
|
||||
PostalCode = request.Location.PostalCode,
|
||||
Coordinates = request.Location.Coordinates
|
||||
}
|
||||
};
|
||||
|
||||
await repository.UpdateAsync(entity);
|
||||
return entity.ToDto();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user