feat: add public seller directory
This commit is contained in:
@@ -11,6 +11,7 @@ import { registerPublicListingRoutes } from '../modules/listings/routes/public-l
|
||||
import { registerAdminProductRoutes } from '../modules/products/routes/admin-product-routes.js';
|
||||
import { registerPublicProductRoutes } from '../modules/products/routes/public-product-routes.js';
|
||||
import { registerPublicSearchRoutes } from '../modules/search/routes/public-search-routes.js';
|
||||
import { registerPublicSellerRoutes } from '../modules/sellers/routes/public-seller-routes.js';
|
||||
|
||||
export function buildApp(dependencies) {
|
||||
const app = Fastify();
|
||||
@@ -70,6 +71,10 @@ export function buildApp(dependencies) {
|
||||
...dependencies,
|
||||
prefix: '/api/v1',
|
||||
});
|
||||
app.register(registerPublicSellerRoutes, {
|
||||
...dependencies,
|
||||
prefix: '/api/v1',
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
||||
@@ -28,6 +28,8 @@ import { createProductRepository } from '../modules/products/repositories/produc
|
||||
import { createProductService } from '../modules/products/services/product-service.js';
|
||||
import { createPublicProductService } from '../modules/products/services/public-product-service.js';
|
||||
import { createSearchService } from '../modules/search/services/search-service.js';
|
||||
import { createSellerRepository } from '../modules/sellers/repositories/seller-repository.js';
|
||||
import { createPublicSellerService } from '../modules/sellers/services/public-seller-service.js';
|
||||
|
||||
function parsePort(value) {
|
||||
const port = Number.parseInt(value ?? '3000', 10);
|
||||
@@ -46,6 +48,7 @@ async function startServer() {
|
||||
const inventoryItemRepository = createInventoryItemRepository(database.db);
|
||||
const inventoryImageRepository = createInventoryImageRepository(database.db);
|
||||
const listingRepository = createListingRepository(database.db);
|
||||
const sellerRepository = createSellerRepository(database.db);
|
||||
const conditionRepository = createConditionRepository(database.db);
|
||||
const userRepository = createUserRepository(database.db);
|
||||
const sessionRepository = createSessionRepository(database.db);
|
||||
@@ -93,6 +96,7 @@ async function startServer() {
|
||||
productService: createProductService({ productRepository }),
|
||||
publicProductService: createPublicProductService({ productRepository }),
|
||||
searchService: createSearchService({ listingRepository }),
|
||||
publicSellerService: createPublicSellerService({ sellerRepository }),
|
||||
});
|
||||
|
||||
app.addHook('onClose', async () => {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { and, asc, eq, inArray } from 'drizzle-orm';
|
||||
|
||||
import {
|
||||
inventoryItems,
|
||||
listings,
|
||||
products,
|
||||
sellers,
|
||||
} from '../../../infrastructure/database/schema.js';
|
||||
|
||||
export function createSellerRepository(db) {
|
||||
return {
|
||||
async listPublic() {
|
||||
return db
|
||||
.select({
|
||||
id: sellers.id,
|
||||
displayName: sellers.displayName,
|
||||
createdAt: sellers.createdAt,
|
||||
updatedAt: sellers.updatedAt,
|
||||
})
|
||||
.from(sellers)
|
||||
.innerJoin(products, eq(products.sellerId, sellers.id))
|
||||
.innerJoin(inventoryItems, eq(inventoryItems.productId, products.id))
|
||||
.innerJoin(listings, eq(listings.inventoryItemId, inventoryItems.id))
|
||||
.where(and(
|
||||
eq(inventoryItems.status, 'ACTIVE'),
|
||||
inArray(listings.status, ['AVAILABLE', 'PENDING']),
|
||||
))
|
||||
.groupBy(sellers.id, sellers.displayName, sellers.createdAt, sellers.updatedAt)
|
||||
.orderBy(asc(sellers.displayName));
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { toPublicSellerDto } from '@pokemon-inventory/contracts/public-seller';
|
||||
|
||||
export async function registerPublicSellerRoutes(app, options) {
|
||||
const { publicSellerService } = options;
|
||||
|
||||
app.get('/public/sellers', async () => ({
|
||||
data: (await publicSellerService.list()).map(toPublicSellerDto),
|
||||
}));
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export function createPublicSellerService({ sellerRepository }) {
|
||||
return {
|
||||
async list() {
|
||||
return sellerRepository.listPublic();
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user