實作前台 APP 呈現、APP 詳細頁面

This commit is contained in:
2025-09-10 00:27:26 +08:00
parent 900e33aefa
commit bc2104d374
17 changed files with 318 additions and 1565 deletions

71
app/api/apps/route.ts Normal file
View File

@@ -0,0 +1,71 @@
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 page = parseInt(searchParams.get('page') || '1')
const limit = parseInt(searchParams.get('limit') || '6')
const search = searchParams.get('search') || ''
const category = searchParams.get('category') || 'all'
const type = searchParams.get('type') || 'all'
const department = searchParams.get('department') || 'all'
// 獲取應用列表(只顯示已發布的應用)
const { apps, total } = await appService.getAllApps({
search,
category,
type,
status: 'published', // 只顯示已發布的應用
page,
limit
})
// 獲取部門列表用於篩選
const departments = await appService.getAppDepartments()
return NextResponse.json({
success: true,
data: {
apps: apps.map(app => ({
id: app.id,
name: app.name,
description: app.description,
category: app.category,
type: app.type,
views: app.views_count || 0,
likes: app.likes_count || 0,
rating: app.rating || 0,
reviewCount: app.reviewCount || 0,
creator: app.creator_name || '未知',
department: app.creator_department || '未知',
createdAt: app.created_at ? new Date(app.created_at).toLocaleDateString('zh-TW') : '-',
icon: app.icon || 'Bot',
iconColor: app.icon_color || 'from-blue-500 to-purple-500',
appUrl: app.app_url,
isActive: app.is_active
})),
pagination: {
page,
limit,
total,
totalPages: Math.ceil(total / limit)
},
departments: departments.map(dept => ({
value: dept.department,
label: dept.department,
count: dept.count
}))
}
})
} catch (error) {
console.error('獲取應用列表錯誤:', error)
return NextResponse.json(
{ success: false, error: '獲取應用列表時發生錯誤' },
{ status: 500 }
)
}
}