< Summary

Information
Class: RoleRadar.Application.Notes.Queries.SearchNotesQueryHandler
Assembly: RoleRadar.Application
File(s): /home/runner/work/roleradar/roleradar/src/RoleRadar.Application/Notes/Queries/SearchNotesQuery.cs
Line coverage
95%
Covered lines: 38
Uncovered lines: 2
Coverable lines: 40
Total lines: 91
Line coverage: 95%
Branch coverage
58%
Covered branches: 7
Total branches: 12
Branch coverage: 58.3%
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()58.33%121290.9%

File(s)

/home/runner/work/roleradar/roleradar/src/RoleRadar.Application/Notes/Queries/SearchNotesQuery.cs

#LineLine coverage
 1using RoleRadar.Application.Abstractions;
 2using RoleRadar.Application.Notes.Commands;
 3using RoleRadar.Domain.Common;
 4using RoleRadar.Domain.Notes;
 5
 6namespace RoleRadar.Application.Notes.Queries;
 7
 8public sealed record NoteSearchItemDto(
 9    Guid Id,
 10    string Title,
 11    string Area,
 12    IReadOnlyList<string> Tags,
 13    ProvenanceDto Provenance,
 14    string Status,
 15    Guid VersionToken,
 16    string Snippet,
 17    double Score,
 18    DateTime UpdatedAtUtc);
 19
 20public sealed record NoteSearchResponseDto(
 21    IReadOnlyList<NoteSearchItemDto> Results);
 22
 23public sealed record SearchNotesQuery(
 24    string? Query = null,
 25    IReadOnlyList<string>? Tags = null,
 26    string? Area = null,
 27    bool IncludeArchived = false,
 28    int Limit = 20,
 29    string? OwnerId = null) : IQuery<NoteSearchResponseDto>;
 30
 31public sealed class SearchNotesQueryHandler : IQueryHandler<SearchNotesQuery, NoteSearchResponseDto>
 32{
 33    private readonly INoteRepository _repository;
 34
 11035    public SearchNotesQueryHandler(INoteRepository repository)
 36    {
 11037        ArgumentNullException.ThrowIfNull(repository);
 11038        _repository = repository;
 11039    }
 40
 41    public async Task<Result<NoteSearchResponseDto>> HandleAsync(
 42        SearchNotesQuery query,
 43        CancellationToken cancellationToken = default)
 44    {
 18245        ArgumentNullException.ThrowIfNull(query);
 46
 18247        var ownerId = string.IsNullOrWhiteSpace(query.OwnerId)
 18248            ? OwnerId.Default.Value
 18249            : new OwnerId(query.OwnerId).Value;
 50
 18251        var readiness = await _repository.CheckReadinessAsync(cancellationToken);
 18252        if (!readiness.IsSuccess)
 53        {
 054            return Result<NoteSearchResponseDto>.Failure(readiness.Error!.Value);
 55        }
 56
 18257        var clampedLimit = Math.Clamp(query.Limit <= 0 ? 20 : query.Limit, 1, 100);
 18258        var criteria = new NoteSearchCriteria(
 18259            OwnerId: ownerId,
 18260            Query: string.IsNullOrWhiteSpace(query.Query) ? null : query.Query.Trim(),
 18261            Tags: query.Tags,
 18262            Area: string.IsNullOrWhiteSpace(query.Area) ? null : query.Area.Trim(),
 18263            IncludeArchived: query.IncludeArchived,
 18264            Limit: clampedLimit);
 65
 18266        var hitsResult = await _repository.SearchAsync(criteria, cancellationToken);
 18267        if (!hitsResult.IsSuccess)
 68        {
 069            return Result<NoteSearchResponseDto>.Failure(hitsResult.Error!.Value);
 70        }
 71
 18272        var items = hitsResult.Value!
 165273            .Select(h => new NoteSearchItemDto(
 165274                Id: h.Note.Id,
 165275                Title: h.Note.Title,
 165276                Area: h.Note.Area,
 165277                Tags: h.Note.Tags,
 165278                Provenance: new ProvenanceDto(
 165279                    h.Note.Provenance.Kind.ToWireString(),
 165280                    h.Note.Provenance.Date,
 165281                    h.Note.Provenance.Qualifier),
 165282                Status: h.Note.Status.ToWireString(),
 165283                VersionToken: h.Note.VersionToken,
 165284                Snippet: h.Snippet,
 165285                Score: h.Score,
 165286                UpdatedAtUtc: h.Note.UpdatedAtUtc))
 18287            .ToArray();
 88
 18289        return Result<NoteSearchResponseDto>.Success(new NoteSearchResponseDto(items));
 18290    }
 91}