deckhearth/pages/api/cards/[id]/ownership.js
Randall Stillwell bb60b4f6b0 Enhanced card detail page with real data and functionality
- 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
2025-07-24 15:03:09 -05:00

32 lines
No EOL
784 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 { quantity } = req.body;
try {
// Update the card's quantity
const result = await sql`
UPDATE cards
SET quantity = ${quantity}
WHERE id = ${id}
RETURNING id, name, quantity
`;
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 ownership:', error);
res.status(500).json({ error: 'Failed to update ownership' });
}
}