實作個人收藏、個人活動紀錄

This commit is contained in:
2025-09-11 17:40:07 +08:00
parent bc2104d374
commit 9c5dceb001
29 changed files with 3781 additions and 601 deletions

View File

@@ -0,0 +1,79 @@
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')
if (!userId) {
return NextResponse.json(
{ success: false, error: '用戶ID不能為空' },
{ status: 400 }
)
}
// 獲取用戶最近使用的應用
const recentApps = await appService.getUserRecentApps(userId, 10)
// 獲取用戶統計數據
const userStats = await appService.getUserActivityStats(userId)
// 獲取類別使用統計
const categoryStats = await appService.getUserCategoryStats(userId)
return NextResponse.json({
success: true,
data: {
recentApps,
userStats,
categoryStats
}
})
} catch (error) {
console.error('獲取用戶活動記錄錯誤:', error)
return NextResponse.json(
{ success: false, error: '獲取活動記錄時發生錯誤' },
{ status: 500 }
)
}
}
// 記錄用戶活動
export async function POST(request: NextRequest) {
try {
const { userId, action, resourceType, resourceId, details } = await request.json()
if (!userId || !action || !resourceType) {
return NextResponse.json(
{ success: false, error: '缺少必要參數' },
{ status: 400 }
)
}
// 記錄活動到資料庫
const activityId = await appService.logUserActivity({
userId,
action,
resourceType,
resourceId,
details
})
return NextResponse.json({
success: true,
data: { activityId }
})
} catch (error) {
console.error('記錄用戶活動錯誤:', error)
return NextResponse.json(
{ success: false, error: '記錄活動時發生錯誤' },
{ status: 500 }
)
}
}