< Summary

Information
Class: ClutterStock.Domain.Features.Locations.UpdateLocation.UpdateLocationCommandHandler
Assembly: Domain
File(s): /home/runner/work/ClutterStock/ClutterStock/backend/src/Domain/Features/Locations/UpdateLocation/UpdateLocationCommandHandler.cs
Tag: 58_25416222083
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 32
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
HandleAsync()100%22100%

File(s)

/home/runner/work/ClutterStock/ClutterStock/backend/src/Domain/Features/Locations/UpdateLocation/UpdateLocationCommandHandler.cs

#LineLine coverage
 1using ClutterStock.Contracts.Locations;
 2using ClutterStock.Domain.Abstractions;
 3using ClutterStock.Domain.Extensions;
 4using Microsoft.AspNetCore.Http;
 5using Microsoft.AspNetCore.Http.HttpResults;
 6using Microsoft.EntityFrameworkCore;
 7
 8namespace ClutterStock.Domain.Features.Locations.UpdateLocation;
 9
 10public interface IUpdateLocationCommandHandler : ICommandHandler
 11{
 12    Task<Results<Ok<LocationResponse>, NotFound>> HandleAsync(Command command, CancellationToken cancellationToken = def
 13
 14    record Command(int Id, string Name, string? Description);
 15}
 16
 217public class UpdateLocationCommandHandler(IAppDbContext context) : IUpdateLocationCommandHandler
 18{
 19    public async Task<Results<Ok<LocationResponse>, NotFound>> HandleAsync(IUpdateLocationCommandHandler.Command command
 20    {
 221        var location = await context.Locations.FirstOrDefaultAsync(l => l.Id == command.Id, cancellationToken);
 222        if (location is null)
 123            return TypedResults.NotFound();
 24
 125        location.Name = command.Name;
 126        location.Description = command.Description;
 127        location.UpdatedAtUtc = DateTimeOffset.UtcNow;
 28
 129        await context.SaveChangesAsync(cancellationToken);
 130        return TypedResults.Ok(location.ToResponse());
 231    }
 32}