Sync
This commit is contained in:
@@ -10,7 +10,7 @@ extends VBoxContainer
|
|||||||
|
|
||||||
signal back_pressed()
|
signal back_pressed()
|
||||||
|
|
||||||
const PAGE_SIZE := 50
|
const PAGE_SIZE := 100
|
||||||
|
|
||||||
# ── Node refs (created in _setup_ui) ─────────────────────────────────────────
|
# ── Node refs (created in _setup_ui) ─────────────────────────────────────────
|
||||||
|
|
||||||
@@ -350,6 +350,7 @@ func _fetch_coll_page(page: int) -> void:
|
|||||||
var req_gen := _coll_req_gen
|
var req_gen := _coll_req_gen
|
||||||
|
|
||||||
var payload := { "page": page, "pageSize": PAGE_SIZE }
|
var payload := { "page": page, "pageSize": PAGE_SIZE }
|
||||||
|
payload["groupByDefinition"] = true
|
||||||
var search := _search_input.text.strip_edges()
|
var search := _search_input.text.strip_edges()
|
||||||
if not search.is_empty():
|
if not search.is_empty():
|
||||||
payload["nameFilter"] = search
|
payload["nameFilter"] = search
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ public sealed record GetCardsRequest(
|
|||||||
string? NameFilter = null,
|
string? NameFilter = null,
|
||||||
string? CardTypeFilter = null,
|
string? CardTypeFilter = null,
|
||||||
string? AffinityFilter = null,
|
string? AffinityFilter = null,
|
||||||
int? TierFilter = null);
|
int? TierFilter = null,
|
||||||
|
bool GroupByDefinition = false);
|
||||||
|
|
||||||
/// <summary>Returns all decks for the authenticated player (summaries only).</summary>
|
/// <summary>Returns all decks for the authenticated player (summaries only).</summary>
|
||||||
public sealed record GetDecksRequest; // no fields — identity from connection
|
public sealed record GetDecksRequest; // no fields — identity from connection
|
||||||
@@ -80,7 +81,8 @@ public sealed record PlayerCardDto(
|
|||||||
bool IsFoil,
|
bool IsFoil,
|
||||||
int? SerialNumber,
|
int? SerialNumber,
|
||||||
DateTimeOffset AcquiredAt,
|
DateTimeOffset AcquiredAt,
|
||||||
bool IsTradeable = true);
|
bool IsTradeable = true,
|
||||||
|
int OwnedCount = 1);
|
||||||
|
|
||||||
public sealed record GetDecksResponse(IEnumerable<DeckSummaryDto> Decks);
|
public sealed record GetDecksResponse(IEnumerable<DeckSummaryDto> Decks);
|
||||||
|
|
||||||
|
|||||||
@@ -67,9 +67,45 @@ internal sealed class CollectionGetCardsHandler : CollectionHandlerBase, IMessag
|
|||||||
defQuery = defQuery.Where(cd =>
|
defQuery = defQuery.Where(cd =>
|
||||||
cd.Tier == req.TierFilter.Value
|
cd.Tier == req.TierFilter.Value
|
||||||
|| (req.TierFilter.Value == 1 && cd.Tier == null));
|
|| (req.TierFilter.Value == 1 && cd.Tier == null));
|
||||||
|
|
||||||
var matchingIds = await defQuery.Select(cd => cd.Id).ToListAsync(cancellationToken);
|
var matchingIds = await defQuery.Select(cd => cd.Id).ToListAsync(cancellationToken);
|
||||||
query = query.Where(pc => matchingIds.Contains(pc.CardDefinitionId));
|
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);
|
int total = await query.CountAsync(cancellationToken);
|
||||||
|
|||||||
Reference in New Issue
Block a user