feat: implement market page with QueryProvider and dynamic listings

- wrap root layout with QueryProvider for React Query
- replace market UnderConstruction placeholder with MarketClient and real data fetching
- implement search, pagination, and sort via search params using getActiveListings
- add necessary client components and queries
- update dependencies (e.g., prisma, pkg-types)
This commit is contained in:
Evandro Fonseca Junior committed 2025-11-05 01:58:03 -03:00
1 parent 55eebde0ba
commit ab37b477df
106 files changed
+15261 -301

No files matched your search

+155
View File
@@ -0,0 +1,155 @@
/**
* Queries de itens usando Prisma
* Busca itens da tabela unificada items (PostgreSQL)
*/
import { prisma } from "../app";
import { Prisma } from "@prisma/client";
export interface Item {
item_id: number;
source_table_id: number;
source_table_name: string;
item_name: string;
category: string;
image_local_path: string | null;
image_url: string | null;
rarity: string | null;
level: number | null;
weight: number | null;
slots: number | null;
skill: string | null;
metadata: any;
created_at: Date;
updated_at: Date;
}
export interface SearchItemsParams {
q?: string;
category?: string;
rarity?: string;
page?: number;
pageSize?: number;
}
/**
* Busca um item por ID unificado
*/
export async function getItemById(itemId: number): Promise<Item | null> {
const item = await prisma.item.findUnique({
where: { item_id: itemId },
});
if (!item) {
return null;
}
return {
...item,
weight: item.weight ? Number(item.weight) : null,
metadata: item.metadata || {},
} as Item;
}
/**
* Busca um item por nome (exato ou similar)
*/
export async function getItemByName(itemName: string): Promise<Item | null> {
const item = await prisma.item.findFirst({
where: {
item_name: {
equals: itemName,
mode: "insensitive",
},
},
});
if (!item) {
return null;
}
return {
...item,
weight: item.weight ? Number(item.weight) : null,
metadata: item.metadata || {},
} as Item;
}
/**
* Busca itens com filtros
*/
export async function searchItems(
params: SearchItemsParams = {}
): Promise<{ items: Item[]; total: number }> {
const {
q = "",
category,
rarity,
page = 1,
pageSize = 24,
} = params;
const where: Prisma.ItemWhereInput = {};
if (q) {
where.item_name = {
contains: q,
mode: "insensitive",
};
}
if (category) {
where.category = category;
}
if (rarity) {
where.rarity = rarity;
}
const total = await prisma.item.count({ where });
const items = await prisma.item.findMany({
where,
orderBy: { item_name: "asc" },
skip: (page - 1) * pageSize,
take: pageSize,
});
return {
items: items.map((item) => ({
...item,
weight: item.weight ? Number(item.weight) : null,
metadata: item.metadata || {},
})) as Item[],
total,
};
}
/**
* Busca item por source_table_name e source_table_id
* (útil para migração ou compatibilidade com IDs antigos)
*/
export async function getItemBySource(
sourceTableName: string,
sourceTableId: number
): Promise<Item | null> {
const item = await prisma.item.findUnique({
where: {
source_table_name_source_table_id: {
source_table_name: sourceTableName,
source_table_id: sourceTableId,
},
},
});
if (!item) {
return null;
}
return {
...item,
weight: item.weight ? Number(item.weight) : null,
metadata: item.metadata || {},
} as Item;
}