a new start
This commit is contained in:
50
app/api/lists/[id]/route.ts
Normal file
50
app/api/lists/[id]/route.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getRepositoriesByList, getAwesomeLists } from '@/lib/db'
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const listId = parseInt(id, 10)
|
||||
|
||||
if (isNaN(listId)) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Invalid list ID' },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
// Get the list info
|
||||
const lists = getAwesomeLists()
|
||||
const list = lists.find(l => l.id === listId)
|
||||
|
||||
if (!list) {
|
||||
return NextResponse.json(
|
||||
{ error: 'List not found' },
|
||||
{ status: 404 }
|
||||
)
|
||||
}
|
||||
|
||||
// Parse pagination
|
||||
const searchParams = request.nextUrl.searchParams
|
||||
const page = parseInt(searchParams.get('page') || '1', 10)
|
||||
const limit = parseInt(searchParams.get('limit') || '50', 10)
|
||||
const offset = (page - 1) * limit
|
||||
|
||||
// Get repositories
|
||||
const repositories = getRepositoriesByList(listId, limit, offset)
|
||||
|
||||
return NextResponse.json({
|
||||
list,
|
||||
repositories
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('List detail API error:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
24
app/api/lists/route.ts
Normal file
24
app/api/lists/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getAwesomeLists, getCategories } from '@/lib/db'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const searchParams = request.nextUrl.searchParams
|
||||
const category = searchParams.get('category') || undefined
|
||||
|
||||
const lists = getAwesomeLists(category)
|
||||
const categories = getCategories()
|
||||
|
||||
return NextResponse.json({
|
||||
lists,
|
||||
categories,
|
||||
total: lists.length
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Lists API error:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user