← back to ClawCoder
src/app/api/marketplace/route.ts
40 lines
import { NextResponse } from 'next/server'
import {
MARKETPLACE_LISTINGS,
getListingsByCategory,
getListingsForProfile,
searchListings,
} from '@/lib/marketplace/data'
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const category = searchParams.get('category')
const profile = searchParams.get('profile')
const query = searchParams.get('q')
// Search takes priority
if (query) {
const results = searchListings(query)
// Optionally filter search results by category
if (category) {
return NextResponse.json(results.filter((l) => l.category === category))
}
return NextResponse.json(results)
}
// Filter by category
if (category) {
return NextResponse.json(getListingsByCategory(category))
}
// Filter by profile
if (profile) {
return NextResponse.json(getListingsForProfile(profile))
}
// Return all listings
return NextResponse.json(MARKETPLACE_LISTINGS)
}