Add queue APIs
This commit is contained in:
parent
4e74bbb443
commit
3775191fd1
4 changed files with 382 additions and 0 deletions
|
@ -72,6 +72,41 @@
|
|||
.btn-molinella:hover {
|
||||
background-color: #5D4037;
|
||||
}
|
||||
.btn-queue-add {
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
}
|
||||
.btn-queue-add:hover {
|
||||
background-color: #45a049;
|
||||
}
|
||||
.btn-queue-read {
|
||||
background-color: #2196F3;
|
||||
color: white;
|
||||
}
|
||||
.btn-queue-read:hover {
|
||||
background-color: #1976D2;
|
||||
}
|
||||
.btn-queue-vote-up {
|
||||
background-color: #FF9800;
|
||||
color: white;
|
||||
}
|
||||
.btn-queue-vote-up:hover {
|
||||
background-color: #F57C00;
|
||||
}
|
||||
.btn-queue-vote-down {
|
||||
background-color: #F44336;
|
||||
color: white;
|
||||
}
|
||||
.btn-queue-vote-down:hover {
|
||||
background-color: #D32F2F;
|
||||
}
|
||||
.btn-queue-delete {
|
||||
background-color: #9C27B0;
|
||||
color: white;
|
||||
}
|
||||
.btn-queue-delete:hover {
|
||||
background-color: #7B1FA2;
|
||||
}
|
||||
.result {
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #ddd;
|
||||
|
@ -112,6 +147,14 @@
|
|||
<button class="btn-molinella" onclick="sendMolinellaCoordinates()">🏘️ Send Molinella coordinates</button>
|
||||
</div>
|
||||
|
||||
<div class="button-group">
|
||||
<button class="btn-queue-add" onclick="addQueueItem()">🎵 Add Song</button>
|
||||
<button class="btn-queue-read" onclick="readQueue()">📋 Read Queue</button>
|
||||
<button class="btn-queue-vote-up" onclick="voteUp()">👍 Vote Up</button>
|
||||
<button class="btn-queue-vote-down" onclick="voteDown()">👎 Vote Down</button>
|
||||
<button class="btn-queue-delete" onclick="deleteQueueItem()">🗑️ Delete Item</button>
|
||||
</div>
|
||||
|
||||
<div id="status"></div>
|
||||
<div id="result" class="result" style="display: none;"></div>
|
||||
</div>
|
||||
|
|
|
@ -192,6 +192,176 @@ async function sendMolinellaCoordinates() {
|
|||
}
|
||||
}
|
||||
|
||||
// Queue CRUD Operations
|
||||
|
||||
// Add song to queue
|
||||
async function addQueueItem() {
|
||||
try {
|
||||
console.log('🎵 Aggiunta canzone alla queue...');
|
||||
showStatus('🎵 Aggiunta canzone alla queue...', true);
|
||||
|
||||
// Canzone hardcoded
|
||||
const song = {
|
||||
"titolo": "Bohemian Rhapsody",
|
||||
"coverUrl": "https://i.scdn.co/image/abc123",
|
||||
"color": "#3b5998",
|
||||
"artista": "Queen",
|
||||
"voti": 0
|
||||
};
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/queue/add`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(song)
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
showStatus('✅ Canzone aggiunta alla queue!', true);
|
||||
showResult(data);
|
||||
} else {
|
||||
showStatus(`❌ Errore: ${data.detail || 'Errore sconosciuto'}`, false);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Errore aggiunta canzone:', error);
|
||||
showStatus(`❌ Errore di connessione: ${error.message}`, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Read queue
|
||||
async function readQueue() {
|
||||
try {
|
||||
console.log('📋 Lettura queue...');
|
||||
showStatus('📋 Lettura queue...', true);
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/queue/read`);
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
showStatus(`✅ Queue letta! ${data.count} canzoni trovate`, true);
|
||||
showResult(data);
|
||||
} else {
|
||||
showStatus(`❌ Errore: ${data.detail || 'Errore sconosciuto'}`, false);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Errore lettura queue:', error);
|
||||
showStatus(`❌ Errore di connessione: ${error.message}`, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Vote up (incrementa voti)
|
||||
async function voteUp() {
|
||||
try {
|
||||
console.log('👍 Voto positivo...');
|
||||
showStatus('👍 Voto positivo...', true);
|
||||
|
||||
// Per semplicità, vota il primo item della queue
|
||||
const response = await fetch(`${API_BASE_URL}/queue/read`);
|
||||
const queueData = await response.json();
|
||||
|
||||
if (response.ok && queueData.data.length > 0) {
|
||||
const firstItemId = queueData.data[0].id;
|
||||
|
||||
const voteResponse = await fetch(`${API_BASE_URL}/queue/vote/${firstItemId}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ "increment": true })
|
||||
});
|
||||
|
||||
const voteData = await voteResponse.json();
|
||||
|
||||
if (voteResponse.ok) {
|
||||
showStatus('✅ Voto positivo aggiunto!', true);
|
||||
showResult(voteData);
|
||||
} else {
|
||||
showStatus(`❌ Errore: ${voteData.detail || 'Errore sconosciuto'}`, false);
|
||||
}
|
||||
} else {
|
||||
showStatus('❌ Nessuna canzone nella queue da votare', false);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Errore voto positivo:', error);
|
||||
showStatus(`❌ Errore di connessione: ${error.message}`, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Vote down (decrementa voti)
|
||||
async function voteDown() {
|
||||
try {
|
||||
console.log('👎 Voto negativo...');
|
||||
showStatus('👎 Voto negativo...', true);
|
||||
|
||||
// Per semplicità, vota il primo item della queue
|
||||
const response = await fetch(`${API_BASE_URL}/queue/read`);
|
||||
const queueData = await response.json();
|
||||
|
||||
if (response.ok && queueData.data.length > 0) {
|
||||
const firstItemId = queueData.data[0].id;
|
||||
|
||||
const voteResponse = await fetch(`${API_BASE_URL}/queue/vote/${firstItemId}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ "increment": false })
|
||||
});
|
||||
|
||||
const voteData = await voteResponse.json();
|
||||
|
||||
if (voteResponse.ok) {
|
||||
showStatus('✅ Voto negativo aggiunto!', true);
|
||||
showResult(voteData);
|
||||
} else {
|
||||
showStatus(`❌ Errore: ${voteData.detail || 'Errore sconosciuto'}`, false);
|
||||
}
|
||||
} else {
|
||||
showStatus('❌ Nessuna canzone nella queue da votare', false);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Errore voto negativo:', error);
|
||||
showStatus(`❌ Errore di connessione: ${error.message}`, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete item from queue
|
||||
async function deleteQueueItem() {
|
||||
try {
|
||||
console.log('🗑️ Eliminazione item dalla queue...');
|
||||
showStatus('🗑️ Eliminazione item dalla queue...', true);
|
||||
|
||||
// Per semplicità, elimina il primo item della queue
|
||||
const response = await fetch(`${API_BASE_URL}/queue/read`);
|
||||
const queueData = await response.json();
|
||||
|
||||
if (response.ok && queueData.data.length > 0) {
|
||||
const firstItemId = queueData.data[0].id;
|
||||
|
||||
const deleteResponse = await fetch(`${API_BASE_URL}/queue/delete/${firstItemId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
const deleteData = await deleteResponse.json();
|
||||
|
||||
if (deleteResponse.ok) {
|
||||
showStatus('✅ Item eliminato dalla queue!', true);
|
||||
showResult(deleteData);
|
||||
} else {
|
||||
showStatus(`❌ Errore: ${deleteData.detail || 'Errore sconosciuto'}`, false);
|
||||
}
|
||||
} else {
|
||||
showStatus('❌ Nessuna canzone nella queue da eliminare', false);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Errore eliminazione item:', error);
|
||||
showStatus(`❌ Errore di connessione: ${error.message}`, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Test di connessione all'avvio
|
||||
window.addEventListener('load', async () => {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue