Manage user's favorite chess openings with add/remove functionality and paginated retrieval.
All endpoints in this API require valid user authentication. Unauthenticated requests will receive 401 Unauthorized.
/api/user/favoritesAdds or removes an opening from the user's favorites list.
{
"openingId": "string (required)",
"action": "string (required, enum: ['add', 'remove'])"
}// Add to favorites
const response = await fetch('/api/user/favorites', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
openingId: 'clk9x8d4q0001vq2o6q7q8r9s',
action: 'add'
})
});
// Remove from favorites
const response = await fetch('/api/user/favorites', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
openingId: 'clk9x8d4q0001vq2o6q7q8r9s',
action: 'remove'
})
});{
"favorite": {
"id": "string",
"userId": "string",
"openingId": "string",
"createdAt": "string"
},
"action": "added"
}{
"action": "removed"
}{
"message": "Already in favorites"
}{
"error": "Missing openingId or action"
}/api/user/favoritesRetrieves a paginated list of the authenticated user's favorite openings.
pagelimit// Fetch first page with custom limit
const response = await fetch('/api/user/favorites?page=1&limit=10');
const data = await response.json();
console.log(data.favorites); // Array of opening objects
console.log(data.total); // Total number of favorites
console.log(data.page); // Current page number
console.log(data.totalPages); // Total number of pages{
"favorites": [
{
"id": "string",
"name": "Ruy Lopez",
"eco": "C60",
"fen": "string",
"pgn": "string",
"totalFavorites": 15,
"aliases": [
{
"id": "string",
"name": "Spanish Opening",
"openingId": "string"
}
]
}
],
"total": 45,
"page": 1,
"totalPages": 3
}totalFavorites counter on openings is automatically incremented/decremented