實作個人收藏、個人活動紀錄
This commit is contained in:
44
app/api/user/favorites/route.ts
Normal file
44
app/api/user/favorites/route.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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 }
|
||||
)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user