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:
2026-02-22 02:53:23 +05:00
parent ce018da271
commit 1a6e754e4b
41 changed files with 2093 additions and 2 deletions

View 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 })
}

View File

@@ -0,0 +1,119 @@
import { NextRequest, NextResponse } from 'next/server'
import { auth } from '@/lib/auth'
import { prisma } from '@/lib/db'
export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url)
const appId = searchParams.get('appId')
const userOnly = searchParams.get('userOnly') === 'true'
const limit = parseInt(searchParams.get('limit') || '20')
const session = await auth()
const userId = session?.user?.id
const where: Record<string, unknown> = {}
if (appId) {
where.app_id = parseInt(appId)
}
const reviews = await prisma.review.findMany({
where,
include: {
user: {
select: {
username: true,
steamAvatar: true
}
},
votes: true,
game: {
select: {
name: true
}
}
},
orderBy: {
created_at: 'desc'
},
take: limit
})
const formattedReviews = reviews.map(review => {
const upvotes = review.votes.filter(v => v.vote_type === 1).length
const downvotes = review.votes.filter(v => v.vote_type === -1).length
const userVote = userId
? review.votes.find(v => v.user_id === userId)?.vote_type || null
: null
return {
id: review.id,
username: review.user.username,
avatar_url: review.user.steamAvatar,
content: review.content,
rating: review.rating,
playtime_hours: review.playtime_hours,
upvotes,
downvotes,
user_vote: userVote,
created_at: review.created_at.toISOString(),
game_name: review.game?.name
}
})
return NextResponse.json(formattedReviews)
}
export async function POST(request: NextRequest) {
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
if (!session.user.steamId) {
return NextResponse.json(
{ error: 'Steam account required to post reviews' },
{ status: 403 }
)
}
const { appId, content, rating, playtimeHours } = await request.json()
if (!appId || !content || !rating) {
return NextResponse.json(
{ error: 'Missing required fields' },
{ status: 400 }
)
}
const existingReview = await prisma.review.findFirst({
where: {
user_id: session.user.id,
app_id: appId
}
})
if (existingReview) {
return NextResponse.json(
{ error: 'You have already reviewed this game' },
{ status: 400 }
)
}
const game = await prisma.game.findUnique({
where: { app_id: appId }
})
const review = await prisma.review.create({
data: {
user_id: session.user.id,
app_id: appId,
content,
rating,
playtime_hours: playtimeHours || null
}
})
return NextResponse.json(review)
}