feat: widget partner system with JS embed, isHidden toggle, category/neighborhood filters
This commit is contained in:
@@ -4,29 +4,33 @@ import { mockDb } from '@/lib/mockDb'
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url)
|
||||
const neighborhoodSlug = searchParams.get('neighborhood')
|
||||
|
||||
if (!neighborhoodSlug) {
|
||||
return NextResponse.json({ error: 'Neighborhood is required' }, { status: 400 })
|
||||
const categorySlug = searchParams.get('category')
|
||||
|
||||
const filters: Parameters<typeof mockDb.getListings>[0] = {}
|
||||
|
||||
// Neighborhood filtresi (opsiyonel - boşsa tüm Marmaris)
|
||||
if (neighborhoodSlug) {
|
||||
const neighborhood = await mockDb.getNeighborhoodBySlug(neighborhoodSlug)
|
||||
if (neighborhood) {
|
||||
filters.neighborhoodId = neighborhood.id
|
||||
}
|
||||
}
|
||||
|
||||
// Get neighborhood
|
||||
const neighborhood = await mockDb.getNeighborhoodBySlug(neighborhoodSlug)
|
||||
if (!neighborhood) {
|
||||
return NextResponse.json({ listings: [] }, {
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
}
|
||||
})
|
||||
// Category filtresi (opsiyonel)
|
||||
if (categorySlug) {
|
||||
const categories = await mockDb.getCategories()
|
||||
const cat = categories.find(c => c.slug === categorySlug)
|
||||
if (cat) {
|
||||
filters.categoryId = cat.id
|
||||
}
|
||||
}
|
||||
|
||||
// Get listings in that neighborhood
|
||||
const listings = await mockDb.getListings({
|
||||
neighborhoodId: neighborhood.id
|
||||
})
|
||||
const listings = await mockDb.getListings(filters)
|
||||
|
||||
// Format response matching widget needs
|
||||
const formattedListings = listings.map(l => ({
|
||||
// Shuffle for variety, limit to 5
|
||||
const shuffled = listings.sort(() => 0.5 - Math.random()).slice(0, 5)
|
||||
|
||||
const formattedListings = shuffled.map(l => ({
|
||||
id: l.id,
|
||||
name: l.nameTr,
|
||||
nameEn: l.nameEn,
|
||||
@@ -36,8 +40,10 @@ export async function GET(req: NextRequest) {
|
||||
categoryName: l.category?.nameTr || '',
|
||||
neighborhoodName: l.neighborhood?.nameTr || '',
|
||||
rating: l.rating,
|
||||
priceSymbols: '₺'.repeat(l.priceRange),
|
||||
coverImage: l.images && l.images.length > 0 ? l.images[0].url : 'https://images.unsplash.com/photo-1555396273-367ea4eb4db5?w=800&auto=format&fit=crop&q=80'
|
||||
priceSymbols: '₺'.repeat(l.priceRange || 1),
|
||||
coverImage: l.images && l.images.length > 0
|
||||
? l.images[0].url
|
||||
: 'https://images.unsplash.com/photo-1555396273-367ea4eb4db5?w=800&auto=format&fit=crop&q=80'
|
||||
}))
|
||||
|
||||
return NextResponse.json({ listings: formattedListings }, {
|
||||
|
||||
Reference in New Issue
Block a user