Files
TeleWave/backend/src/TeleWave.Application/Library/Collections/Suggest/SuggestCollectionsQueryHandler.cs
T
Leonid Pershin ac41111fa0
ci / build-backend (push) Successful in 1m40s
ci / build-frontend (push) Successful in 53s
ci / tests (push) Successful in 1m46s
ci / sonar (push) Successful in 6m47s
Implement functionality to add shows to existing collections from suggestions
Added a new endpoint for adding shows to already assembled franchises based on the same suggestion key. Updated the CollectionSuggestion and CollectionSuggestionDto records to include a CollectionId for tracking existing collections. Enhanced the CollectionSuggestions component in the frontend to support this new functionality, allowing users to add missing parts to existing collections. Updated localization strings to reflect the new addition feature in both English and Russian, ensuring clarity for users. Adjusted tests to verify the correct behavior of the addition process and its integration with existing collection logic.
2026-07-28 14:49:27 +03:00

47 lines
1.6 KiB
C#

using LiteCqrs;
using Microsoft.EntityFrameworkCore;
using TeleWave.Application.Common.Interfaces;
namespace TeleWave.Application.Library.Collections.Suggest;
public sealed class SuggestCollectionsQueryHandler(
IAppDbContext dbContext,
CollectionSuggestionBuilder builder
) : IQueryHandler<SuggestCollectionsQuery, IReadOnlyList<CollectionSuggestionDto>>
{
public async Task<IReadOnlyList<CollectionSuggestionDto>> Handle(
SuggestCollectionsQuery query,
CancellationToken cancellationToken
)
{
var suggestions = await builder.BuildAsync(cancellationToken);
if (suggestions.Count == 0)
return [];
var names = await dbContext
.Collections.AsNoTracking()
.Select(c => c.Name)
.ToListAsync(cancellationToken);
var existing = names
.Select(n => n.Trim())
.ToHashSet(StringComparer.CurrentCultureIgnoreCase);
// У дополнения имя — это имя самой коллекции, и совпадение с ней ничего не значит: такое
// предложение и живёт ровно потому, что франшиза уже собрана.
bool AlreadyCreated(CollectionSuggestion s) =>
s.CollectionId is null && existing.Contains(s.Name);
return
[
.. suggestions.Select(s => new CollectionSuggestionDto(
s.Key,
s.Source,
s.Name,
s.Parts,
AlreadyCreated(s),
s.CollectionId
)),
];
}
}