Files

45 lines
1.2 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { AppService } from '@/lib/services/database-service'
const appService = new AppService()
// 獲取用戶收藏列表
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url)
const userId = searchParams.get('userId')
const page = parseInt(searchParams.get('page') || '1')
const limit = parseInt(searchParams.get('limit') || '20')
if (!userId) {
return NextResponse.json(
{ success: false, error: '用戶ID不能為空' },
{ status: 400 }
)
}
const offset = (page - 1) * limit
const result = await appService.getUserFavorites(userId, limit, offset)
return NextResponse.json({
success: true,
data: {
apps: result.apps,
pagination: {
page,
limit,
total: result.total,
totalPages: Math.ceil(result.total / limit)
}
}
})
} catch (error) {
console.error('獲取用戶收藏列表錯誤:', error)
return NextResponse.json(
{ success: false, error: '獲取收藏列表時發生錯誤' },
{ status: 500 }
)
}
}