- Updated card detail page to fetch real data from API - Added ownership tracking with quantity management - Added favorite system for cards - Added collection and deck management functionality - Created API endpoints for ownership, favorites, collections, and decks - Added database columns for quantity and favorited status - Shows current collections and decks the card belongs to - Added proper error handling and loading states - Integrated with real card data from database - Added purchase links to TCGPlayer and eBay
32 lines
No EOL
807 B
JavaScript
32 lines
No EOL
807 B
JavaScript
import { sql } from '@vercel/postgres';
|
|
|
|
export default async function handler(req, res) {
|
|
if (req.method !== 'POST') {
|
|
return res.status(405).json({ error: 'Method not allowed' });
|
|
}
|
|
|
|
const { id } = req.query;
|
|
const { favorited } = req.body;
|
|
|
|
try {
|
|
// Update the card's favorite status
|
|
const result = await sql`
|
|
UPDATE cards
|
|
SET favorited = ${favorited}
|
|
WHERE id = ${id}
|
|
RETURNING id, name, favorited
|
|
`;
|
|
|
|
if (result.rows.length === 0) {
|
|
return res.status(404).json({ error: 'Card not found' });
|
|
}
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
card: result.rows[0]
|
|
});
|
|
} catch (error) {
|
|
console.error('Error updating favorite status:', error);
|
|
res.status(500).json({ error: 'Failed to update favorite status' });
|
|
}
|
|
}
|