feat: add review writing page and integrate Steam account linking
- Implemented WriteReviewPage for users to submit reviews with ratings and playtime. - Created global CSS styles for consistent theming across the application. - Established RootLayout for metadata and global styles. - Developed LoginPage for user authentication with email/password and Steam login options. - Built Home page to display game search results and recent reviews. - Added LinkSteamPage for linking Steam accounts to user profiles. - Created ProfilePage to manage user information and display their reviews. - Developed GameCard and ReviewCard components for displaying games and reviews. - Implemented Header component for navigation and user session management. - Added Providers component to wrap the application with session context. - Integrated NextAuth for user authentication with Steam and credentials. - Set up Prisma client for database interactions. - Created Steam API utility functions for fetching game and user data. - Configured TypeScript settings for the project.
This commit is contained in:
61
src/app/api/reviews/[id]/vote/route.ts
Normal file
61
src/app/api/reviews/[id]/vote/route.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { auth } from '@/lib/auth'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
export async function POST(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const session = await auth()
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
const resolvedParams = await params
|
||||
const { voteType } = await request.json()
|
||||
|
||||
if (voteType !== 1 && voteType !== -1) {
|
||||
return NextResponse.json({ error: 'Invalid vote type' }, { status: 400 })
|
||||
}
|
||||
|
||||
const review = await prisma.review.findUnique({
|
||||
where: { id: resolvedParams.id }
|
||||
})
|
||||
|
||||
if (!review) {
|
||||
return NextResponse.json({ error: 'Review not found' }, { status: 404 })
|
||||
}
|
||||
|
||||
const existingVote = await prisma.vote.findUnique({
|
||||
where: {
|
||||
user_review_unique: {
|
||||
user_id: session.user.id,
|
||||
review_id: resolvedParams.id
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (existingVote) {
|
||||
if (existingVote.vote_type === voteType) {
|
||||
await prisma.vote.delete({
|
||||
where: { id: existingVote.id }
|
||||
})
|
||||
} else {
|
||||
await prisma.vote.update({
|
||||
where: { id: existingVote.id },
|
||||
data: { vote_type: voteType }
|
||||
})
|
||||
}
|
||||
} else {
|
||||
await prisma.vote.create({
|
||||
data: {
|
||||
user_id: session.user.id,
|
||||
review_id: resolvedParams.id,
|
||||
vote_type: voteType
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true })
|
||||
}
|
||||
Reference in New Issue
Block a user