78 lines
2.0 KiB
TypeScript
78 lines
2.0 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, { params }: { params: { id: string } }) {
|
|
try {
|
|
const { id: appId } = await params
|
|
const { searchParams } = new URL(request.url)
|
|
const page = parseInt(searchParams.get('page') || '1')
|
|
const limit = parseInt(searchParams.get('limit') || '10')
|
|
const offset = (page - 1) * limit
|
|
|
|
// 獲取應用評價列表
|
|
const reviews = await appService.getAppReviews(appId, limit, offset)
|
|
|
|
// 獲取評價總數
|
|
const totalReviews = await appService.getAppReviewCount(appId)
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
data: {
|
|
reviews,
|
|
pagination: {
|
|
page,
|
|
limit,
|
|
total: totalReviews,
|
|
totalPages: Math.ceil(totalReviews / limit)
|
|
}
|
|
}
|
|
})
|
|
|
|
} catch (error) {
|
|
console.error('獲取應用評價錯誤:', error)
|
|
return NextResponse.json(
|
|
{ success: false, error: '獲取評價時發生錯誤' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|
|
export async function DELETE(request: NextRequest, { params }: { params: { id: string } }) {
|
|
try {
|
|
const { id: appId } = await params
|
|
const body = await request.json()
|
|
const { reviewId } = body
|
|
|
|
if (!reviewId) {
|
|
return NextResponse.json(
|
|
{ success: false, error: '缺少評價ID' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
// 刪除評價
|
|
const result = await appService.deleteReview(reviewId, appId)
|
|
|
|
if (result.success) {
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: '評價刪除成功'
|
|
})
|
|
} else {
|
|
return NextResponse.json(
|
|
{ success: false, error: result.error },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('刪除評價錯誤:', error)
|
|
return NextResponse.json(
|
|
{ success: false, error: '刪除評價時發生錯誤' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|