2025-12-08 16:31:30 +03:00

30 lines
944 B
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { redis } from '@/lib/redis'
export async function POST(req: NextRequest, { params }: { params: { id: string } }) {
try {
const { id: pollId } = params
await redis.incr(`poll:${pollId}:shares`)
const shares = await redis.get(`poll:${pollId}:shares`)
return NextResponse.json({ shares: parseInt(shares as string) || 1 })
} catch (error) {
console.error('Share tracking error:', error)
return NextResponse.json({ error: 'Failed to track share' }, { status: 500 })
}
}
export async function GET(req: NextRequest, { params }: { params: { id: string } }) {
try {
const { id: pollId } = params
const shares = await redis.get(`poll:${pollId}:shares`)
return NextResponse.json({ shares: parseInt(shares as string) || 0 })
} catch (error) {
console.error('Share count error:', error)
return NextResponse.json({ shares: 0 })
}
}