< Summary

Information
Class: RoleRadar.Application.Notes.Queries.NoteSearchResponseDto
Assembly: RoleRadar.Application
File(s): /home/runner/work/roleradar/roleradar/src/RoleRadar.Application/Notes/Queries/SearchNotesQuery.cs
Line coverage
100%
Covered lines: 2
Uncovered lines: 0
Coverable lines: 2
Total lines: 91
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

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
 18420public sealed record NoteSearchResponseDto(
 37021    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
 35    public SearchNotesQueryHandler(INoteRepository repository)
 36    {
 37        ArgumentNullException.ThrowIfNull(repository);
 38        _repository = repository;
 39    }
 40
 41    public async Task<Result<NoteSearchResponseDto>> HandleAsync(
 42        SearchNotesQuery query,
 43        CancellationToken cancellationToken = default)
 44    {
 45        ArgumentNullException.ThrowIfNull(query);
 46
 47        var ownerId = string.IsNullOrWhiteSpace(query.OwnerId)
 48            ? OwnerId.Default.Value
 49            : new OwnerId(query.OwnerId).Value;
 50
 51        var readiness = await _repository.CheckReadinessAsync(cancellationToken);
 52        if (!readiness.IsSuccess)
 53        {
 54            return Result<NoteSearchResponseDto>.Failure(readiness.Error!.Value);
 55        }
 56
 57        var clampedLimit = Math.Clamp(query.Limit <= 0 ? 20 : query.Limit, 1, 100);
 58        var criteria = new NoteSearchCriteria(
 59            OwnerId: ownerId,
 60            Query: string.IsNullOrWhiteSpace(query.Query) ? null : query.Query.Trim(),
 61            Tags: query.Tags,
 62            Area: string.IsNullOrWhiteSpace(query.Area) ? null : query.Area.Trim(),
 63            IncludeArchived: query.IncludeArchived,
 64            Limit: clampedLimit);
 65
 66        var hitsResult = await _repository.SearchAsync(criteria, cancellationToken);
 67        if (!hitsResult.IsSuccess)
 68        {
 69            return Result<NoteSearchResponseDto>.Failure(hitsResult.Error!.Value);
 70        }
 71
 72        var items = hitsResult.Value!
 73            .Select(h => new NoteSearchItemDto(
 74                Id: h.Note.Id,
 75                Title: h.Note.Title,
 76                Area: h.Note.Area,
 77                Tags: h.Note.Tags,
 78                Provenance: new ProvenanceDto(
 79                    h.Note.Provenance.Kind.ToWireString(),
 80                    h.Note.Provenance.Date,
 81                    h.Note.Provenance.Qualifier),
 82                Status: h.Note.Status.ToWireString(),
 83                VersionToken: h.Note.VersionToken,
 84                Snippet: h.Snippet,
 85                Score: h.Score,
 86                UpdatedAtUtc: h.Note.UpdatedAtUtc))
 87            .ToArray();
 88
 89        return Result<NoteSearchResponseDto>.Success(new NoteSearchResponseDto(items));
 90    }
 91}