✅ How can I improve this code?
It seems that I should change the way tags are stored. Or should I not?
public async Task<GetNotesByTagsQueryResult> Handle(GetNotesByTagsQuery query, CancellationToken ct)
{
var notes = new List<GetNotesByTagsQueryResultItem>();
foreach (var excludedTag in query.ExcludedTags)
{
foreach (var includedTag in query.IncludedTags)
{
notes = await _db.Notes
.Where(n => n.Tags.Contains(includedTag) && !n.Tags.Contains(excludedTag))
.ProjectToType<GetNotesByTagsQueryResultItem>()
.Distinct()
.ToListAsync(ct);
}
}
return new GetNotesByTagsQueryResult { Notes = notes };
}public async Task<GetNotesByTagsQueryResult> Handle(GetNotesByTagsQuery query, CancellationToken ct)
{
var notes = new List<GetNotesByTagsQueryResultItem>();
foreach (var excludedTag in query.ExcludedTags)
{
foreach (var includedTag in query.IncludedTags)
{
notes = await _db.Notes
.Where(n => n.Tags.Contains(includedTag) && !n.Tags.Contains(excludedTag))
.ProjectToType<GetNotesByTagsQueryResultItem>()
.Distinct()
.ToListAsync(ct);
}
}
return new GetNotesByTagsQueryResult { Notes = notes };
}