Add comprehensive plant trading marketplace with: - Prisma schema with marketplace models (Listing, Offer, SellerProfile, WishlistItem) - Service layer for listings, offers, search, and matching - API endpoints for CRUD operations, search, and recommendations - Marketplace pages: home, listing detail, create, my-listings, my-offers - Reusable UI components: ListingCard, ListingGrid, OfferForm, SearchFilters, etc. Features: - Browse and search listings by category, price, tags - Create and manage listings (draft, active, sold, cancelled) - Make and manage offers on listings - Seller and buyer views with statistics - Featured and recommended listings - In-memory store (ready for database migration via Agent 2)
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
// API: My Listings
|
|
// GET /api/marketplace/my-listings - Get current user's listings
|
|
|
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import { listingService } from '@/lib/marketplace';
|
|
import { ListingStatus } from '@/lib/marketplace/types';
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
if (req.method !== 'GET') {
|
|
res.setHeader('Allow', ['GET']);
|
|
return res.status(405).json({ error: `Method ${req.method} Not Allowed` });
|
|
}
|
|
|
|
try {
|
|
const sellerId = req.headers['x-user-id'] as string;
|
|
|
|
if (!sellerId) {
|
|
return res.status(401).json({ error: 'Authentication required' });
|
|
}
|
|
|
|
const { status } = req.query;
|
|
|
|
let listings = await listingService.getListingsBySeller(sellerId);
|
|
|
|
// Filter by status if provided
|
|
if (status && typeof status === 'string') {
|
|
listings = listings.filter(l => l.status === status as ListingStatus);
|
|
}
|
|
|
|
// Get statistics
|
|
const stats = await listingService.getSellerStats(sellerId);
|
|
|
|
// Sort by most recent first
|
|
listings.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
|
|
return res.status(200).json({
|
|
listings,
|
|
total: listings.length,
|
|
stats,
|
|
});
|
|
} catch (error) {
|
|
console.error('My listings API error:', error);
|
|
return res.status(500).json({
|
|
error: 'Internal server error',
|
|
message: error instanceof Error ? error.message : 'Unknown error',
|
|
});
|
|
}
|
|
}
|