Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
import { sql } from '@vercel/postgres';
|
2025-07-25 09:34:28 -04:00
|
|
|
import { withCollectionPermission, getUserFromRequest, logCollectionActivity } from '../../../lib/permission-middleware';
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
|
2025-07-25 09:34:28 -04:00
|
|
|
async function handler(req, res) {
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
// Set CORS headers
|
|
|
|
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
|
|
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
|
|
|
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
|
|
|
|
|
|
|
|
// Handle preflight requests
|
|
|
|
|
if (req.method === 'OPTIONS') {
|
|
|
|
|
res.status(200).end();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { id } = req.query;
|
|
|
|
|
|
|
|
|
|
if (req.method === 'GET') {
|
2025-07-25 09:34:28 -04:00
|
|
|
// GET requests use the permission from middleware
|
|
|
|
|
const collection = req.permission.collection;
|
|
|
|
|
const userRole = req.permission.role;
|
|
|
|
|
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
try {
|
2025-07-25 09:34:28 -04:00
|
|
|
// Get detailed collection info with creator
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
const collectionResult = await sql`
|
|
|
|
|
SELECT
|
|
|
|
|
c.*,
|
|
|
|
|
u.email as creator_email
|
|
|
|
|
FROM collections c
|
|
|
|
|
LEFT JOIN users u ON c.user_id = u.id
|
|
|
|
|
WHERE c.id = ${id}
|
|
|
|
|
`;
|
|
|
|
|
|
2025-07-25 09:34:28 -04:00
|
|
|
const collectionDetails = collectionResult.rows[0];
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
|
|
|
|
|
// Get cards in the collection
|
|
|
|
|
const cardsResult = await sql`
|
|
|
|
|
SELECT
|
|
|
|
|
cc.*,
|
|
|
|
|
cards.name,
|
|
|
|
|
cards.set_name,
|
|
|
|
|
cards.rarity,
|
|
|
|
|
cards.type,
|
|
|
|
|
cards.image_url,
|
|
|
|
|
cards.market_price
|
|
|
|
|
FROM collection_cards cc
|
|
|
|
|
JOIN cards ON cc.card_id = cards.id
|
|
|
|
|
WHERE cc.collection_id = ${id}
|
|
|
|
|
ORDER BY cc.created_at ASC
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const cards = cardsResult.rows;
|
|
|
|
|
|
|
|
|
|
// Calculate collection stats
|
|
|
|
|
const totalCards = cards.reduce((sum, card) => sum + card.quantity, 0);
|
|
|
|
|
const totalValue = cards.reduce((sum, card) => sum + (card.market_price * card.quantity), 0);
|
|
|
|
|
|
|
|
|
|
res.status(200).json({
|
|
|
|
|
collection: {
|
2025-07-25 09:34:28 -04:00
|
|
|
...collectionDetails,
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
totalCards,
|
2025-07-25 09:34:28 -04:00
|
|
|
totalValue,
|
|
|
|
|
userRole
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
},
|
|
|
|
|
cards
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error fetching collection:', error);
|
|
|
|
|
res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
}
|
|
|
|
|
} else if (req.method === 'PUT') {
|
2025-07-25 09:34:28 -04:00
|
|
|
// Update collection - requires editor permissions
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
try {
|
2025-07-25 11:29:45 -04:00
|
|
|
const { name, description, isPublic } = req.body;
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
|
|
|
|
|
const result = await sql`
|
|
|
|
|
UPDATE collections
|
|
|
|
|
SET
|
|
|
|
|
name = ${name},
|
|
|
|
|
description = ${description},
|
2025-07-25 11:29:45 -04:00
|
|
|
is_public = ${isPublic},
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
updated_at = NOW()
|
|
|
|
|
WHERE id = ${id}
|
|
|
|
|
RETURNING *
|
|
|
|
|
`;
|
|
|
|
|
|
2025-07-25 09:34:28 -04:00
|
|
|
// Log activity
|
|
|
|
|
await logCollectionActivity(id, req.user.userId, 'collection_updated', {
|
|
|
|
|
name,
|
|
|
|
|
description,
|
2025-07-25 11:29:45 -04:00
|
|
|
isPublic
|
2025-07-25 09:34:28 -04:00
|
|
|
});
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
|
|
|
|
|
res.status(200).json(result.rows[0]);
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error updating collection:', error);
|
|
|
|
|
res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
}
|
|
|
|
|
} else if (req.method === 'DELETE') {
|
2025-07-25 09:34:28 -04:00
|
|
|
// Delete collection - requires owner permissions
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
try {
|
2025-07-25 09:34:28 -04:00
|
|
|
// Log activity before deletion
|
|
|
|
|
await logCollectionActivity(id, req.user.userId, 'collection_deleted', {});
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
|
2025-07-25 09:34:28 -04:00
|
|
|
// Delete collection (cascade will handle related records)
|
Enhanced collections with detailed view and card management
- Created comprehensive collection detail page (/collection/[id]) with:
* Hero section with collection metadata (name, creator, format, cost)
* Action buttons (copy link, share, print proxies, save deck)
* Collection statistics (total cards, value, views, favorites)
* Advanced filtering and search functionality
* Grid and list view modes for cards
* Real-time card filtering by rarity, type, and search terms
- Added complete API endpoints for collection management:
* GET/PUT/DELETE /api/collections/[id] - collection CRUD operations
* POST/PUT/DELETE /api/collections/[id]/cards - card management
* Enhanced /api/collections with database integration
- Features matching deck builder interface from image:
* Beautiful hero section with background image
* Metadata display (creator, format, cost, play guide)
* Copy/share/save functionality
* Comprehensive filtering system
* Responsive card grid and list views
* Real-time statistics and card counting
- Updated collections listing page to link to detailed views
- Proper error handling and loading states throughout
- Mobile-responsive design with modern UI/UX
2025-07-25 08:44:23 -04:00
|
|
|
const result = await sql`DELETE FROM collections WHERE id = ${id} RETURNING *`;
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ message: 'Collection deleted successfully' });
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error deleting collection:', error);
|
|
|
|
|
res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
res.status(405).json({ error: 'Method not allowed' });
|
|
|
|
|
}
|
2025-07-25 09:34:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply permission middleware based on method
|
|
|
|
|
export default async function(req, res) {
|
|
|
|
|
let requiredPermission = 'viewer'; // Default for GET
|
|
|
|
|
|
|
|
|
|
if (req.method === 'PUT') {
|
|
|
|
|
requiredPermission = 'editor';
|
|
|
|
|
} else if (req.method === 'DELETE') {
|
|
|
|
|
requiredPermission = 'owner';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return withCollectionPermission(requiredPermission)(handler)(req, res);
|
|
|
|
|
};
|