應用 APP 功能實作
This commit is contained in:
43
app/api/admin/apps/[id]/toggle-status/route.ts
Normal file
43
app/api/admin/apps/[id]/toggle-status/route.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { AppService } from '@/lib/services/database-service'
|
||||
|
||||
const appService = new AppService()
|
||||
|
||||
export async function POST(request: NextRequest, { params }: { params: { id: string } }) {
|
||||
try {
|
||||
const { id: appId } = await params
|
||||
|
||||
const result = await appService.toggleAppStatus(appId)
|
||||
|
||||
if (result.success) {
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: '應用狀態更新成功',
|
||||
data: {
|
||||
app: {
|
||||
...result.app,
|
||||
status: result.app?.is_active ? 'published' : 'draft',
|
||||
views: result.app?.views_count || 0,
|
||||
likes: result.app?.likes_count || 0,
|
||||
rating: result.app?.rating || 0,
|
||||
creator: result.app?.creator_name || '未知',
|
||||
department: result.app?.creator_department || '未知',
|
||||
createdAt: result.app?.created_at ? new Date(result.app.created_at).toLocaleDateString('zh-TW') : '-'
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
return NextResponse.json(
|
||||
{ success: false, error: result.error },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('切換應用狀態錯誤:', error)
|
||||
return NextResponse.json(
|
||||
{ success: false, error: '切換應用狀態時發生錯誤' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user