Sync
This commit is contained in:
@@ -16,7 +16,8 @@ public sealed record GetCardsRequest(
|
||||
string? NameFilter = null,
|
||||
string? CardTypeFilter = null,
|
||||
string? AffinityFilter = null,
|
||||
int? TierFilter = null);
|
||||
int? TierFilter = null,
|
||||
bool GroupByDefinition = false);
|
||||
|
||||
/// <summary>Returns all decks for the authenticated player (summaries only).</summary>
|
||||
public sealed record GetDecksRequest; // no fields — identity from connection
|
||||
@@ -80,7 +81,8 @@ public sealed record PlayerCardDto(
|
||||
bool IsFoil,
|
||||
int? SerialNumber,
|
||||
DateTimeOffset AcquiredAt,
|
||||
bool IsTradeable = true);
|
||||
bool IsTradeable = true,
|
||||
int OwnedCount = 1);
|
||||
|
||||
public sealed record GetDecksResponse(IEnumerable<DeckSummaryDto> Decks);
|
||||
|
||||
|
||||
@@ -67,9 +67,45 @@ internal sealed class CollectionGetCardsHandler : CollectionHandlerBase, IMessag
|
||||
defQuery = defQuery.Where(cd =>
|
||||
cd.Tier == req.TierFilter.Value
|
||||
|| (req.TierFilter.Value == 1 && cd.Tier == null));
|
||||
|
||||
var matchingIds = await defQuery.Select(cd => cd.Id).ToListAsync(cancellationToken);
|
||||
query = query.Where(pc => matchingIds.Contains(pc.CardDefinitionId));
|
||||
if (req.GroupByDefinition)
|
||||
{
|
||||
var grouped = query
|
||||
.GroupBy(pc => pc.CardDefinitionId)
|
||||
.Select(g => new
|
||||
{
|
||||
CardDefinitionId = g.Key,
|
||||
OwnedCount = g.Count(),
|
||||
// representative row fields for compatibility
|
||||
PlayerCardId = g.Min(x => x.Id),
|
||||
AcquiredAt = g.Min(x => x.AcquiredAt),
|
||||
IsFoil = g.Any(x => x.IsFoil),
|
||||
IsTradeable = g.Any(x => x.IsTradeable),
|
||||
});
|
||||
|
||||
int total = await grouped.CountAsync(cancellationToken);
|
||||
|
||||
var pageRows = await grouped
|
||||
.OrderBy(x => x.CardDefinitionId) // or by AcquiredAt if you prefer
|
||||
.Skip(skip)
|
||||
.Take(pageSize)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = pageRows.Select(x => new PlayerCardDto(
|
||||
PlayerCardId: x.PlayerCardId,
|
||||
CardDefinitionId: x.CardDefinitionId,
|
||||
IsFoil: x.IsFoil,
|
||||
SerialNumber: null,
|
||||
AcquiredAt: x.AcquiredAt,
|
||||
IsTradeable: x.IsTradeable,
|
||||
OwnedCount: x.OwnedCount));
|
||||
|
||||
return ServerMessage.Reply(
|
||||
"collection.get_cards.ack",
|
||||
message.Seq,
|
||||
new GetCardsResponse(dtos, total, page, pageSize));
|
||||
}
|
||||
}
|
||||
|
||||
int total = await query.CountAsync(cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user