< Summary

Information
Class: FLP.Application.Handlers.Bugs.GetBugByIdHandler
Assembly: FLP.Application
File(s): /home/runner/work/FLP.AzureFunctions/FLP.AzureFunctions/FLP.Application/Handlers/Bugs/GetBugByIdHandler.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 49
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
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%
Handle()100%44100%

File(s)

/home/runner/work/FLP.AzureFunctions/FLP.AzureFunctions/FLP.Application/Handlers/Bugs/GetBugByIdHandler.cs

#LineLine coverage
 1using AutoMapper;
 2using FLP.Application.Requests.Bugs;
 3using FLP.Application.Responses.Bugs;
 4using FLP.Application.Validators.Bugs;
 5using FLP.Core.Context.Shared;
 6using FLP.Core.Exceptions;
 7using FLP.Core.Interfaces.Repository;
 8using MediatR;
 9using Microsoft.Extensions.Logging;
 10
 11namespace FLP.Application.Handlers.Bugs;
 12
 313public class GetBugByIdHandler(IUnitOfWork _uow, IMapper _mapper, ILogger<GetBugByIdHandler> _logger) : IRequestHandler<
 14{
 15    /// <summary>
 16    /// runs the GetBugByIdRequest handler to retrieve a bug by its ID.
 17    /// </summary>
 18    /// <param name="request"></param>
 19    /// <param name="cancellationToken"></param>
 20    /// <returns></returns>
 21    /// <exception cref="ArgumentException"></exception>
 22    /// <exception cref="NotFoundException"></exception>
 23    public async Task<BaseResponse<GetBugByIdResponse>> Handle(GetBugByIdRequest request, CancellationToken cancellation
 324    {
 325        cancellationToken.ThrowIfCancellationRequested();
 326        _logger.LogInformation("Handling GetBugByIdRequest for Id: {Id}", request.Id);
 27
 28        // Validate the request
 329        var validator = new GetBugByIdValidator();
 330        var validationResult = validator.Validate(request);
 331        if (!validationResult.IsValid)
 132        {
 133            _logger.LogWarning("Validation failed for GetBugByIdRequest: {Errors}", validationResult.Errors);
 134            return new BaseResponse<GetBugByIdResponse>(false, validationResult.Errors.Select(e => e.ErrorMessage));
 35        }
 36
 237        var bug = await _uow.BugRepository.GetByIdAsync(request.Id, cancellationToken);
 38
 239        if (bug == null)
 140        {
 141            return new BaseResponse<GetBugByIdResponse>(false, "Bug not found");
 42        }
 43
 144        _logger.LogInformation("Bug found with Id: {Id}", request.Id);
 45        // Map the bug entity to a response DTO
 146        var response = _mapper.Map<GetBugByIdResponse>(bug);
 147        return new BaseResponse<GetBugByIdResponse>(response);
 348    }
 49}