Files

42 lines
1.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 }
)
}
// 直接查詢收藏的應用ID不依賴 apps 表的 is_active 狀態)
const favoriteAppIds = await appService.getUserFavoriteAppIds(userId)
console.log('用戶收藏的應用ID列表:', favoriteAppIds)
// 獲取用戶的按讚列表
const likedAppIds = await appService.getUserLikedApps(userId)
console.log('用戶按讚的應用ID列表:', likedAppIds)
return NextResponse.json({
success: true,
data: {
favorites: favoriteAppIds,
likes: likedAppIds
}
})
} catch (error) {
console.error('獲取用戶互動狀態錯誤:', error)
return NextResponse.json(
{ success: false, error: '獲取用戶互動狀態時發生錯誤' },
{ status: 500 }
)
}
}