init
This commit is contained in:
25
app/api/users/route.ts
Normal file
25
app/api/users/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { userService } from '@/lib/database'
|
||||
|
||||
// GET - 獲取所有用戶
|
||||
export async function GET() {
|
||||
try {
|
||||
const users = await userService.getAllUsers()
|
||||
return NextResponse.json(users)
|
||||
} catch (error) {
|
||||
console.error('獲取用戶列表失敗:', error)
|
||||
return NextResponse.json({ error: '獲取用戶列表失敗' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
// POST - 創建新用戶
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const user = await userService.createUser(body)
|
||||
return NextResponse.json(user, { status: 201 })
|
||||
} catch (error) {
|
||||
console.error('創建用戶失敗:', error)
|
||||
return NextResponse.json({ error: '創建用戶失敗' }, { status: 500 })
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user