diff --git a/javascript/JS_Esercizi 11 - API/01_get_singolo_utente/script.js b/javascript/JS_Esercizi 11 - API/01_get_singolo_utente/script.js index 4548770..d5eb043 100644 --- a/javascript/JS_Esercizi 11 - API/01_get_singolo_utente/script.js +++ b/javascript/JS_Esercizi 11 - API/01_get_singolo_utente/script.js @@ -80,11 +80,12 @@ function handleError(message) { * 2. Controlla che l'ID sia valido, ovvero un numero tra 1 e 40 * In caso contrario, mostra un messaggio di errore (usa handleError()) e return * 3. Mostra lo spinner di caricamento (rimuovi la classe nascosto) - * 4. Fai una fetch GET a /users/{id} - * 5. Se la risposta non è OK, usa handleError() per mostrare un messaggio e return - * 6. Converti la risposta in JSON - * 7. Mostra i dati dell'utente chiamando createUserCard(user) - * 8. Nascondi lo spinner di caricamento (aggiungi la classe nascosto) + * 4. Apri un blocco try/catch + * 5. Fai una fetch GET a /users/{id} + * 6. Se la risposta non è OK, usa handleError() per mostrare un messaggio e return + * 7. Converti la risposta in JSON + * 8. Mostra i dati dell'utente chiamando createUserCard(user) + * 9. Nascondi lo spinner di caricamento (aggiungi la classe nascosto) */ async function fetchUser() { // TODO Rimuovi questa riga e completa la funzione diff --git a/javascript/JS_Esercizi 11 - API/02_get_lista_utenti/script.js b/javascript/JS_Esercizi 11 - API/02_get_lista_utenti/script.js index cc7e50b..a35c758 100644 --- a/javascript/JS_Esercizi 11 - API/02_get_lista_utenti/script.js +++ b/javascript/JS_Esercizi 11 - API/02_get_lista_utenti/script.js @@ -55,11 +55,12 @@ function handleError(message) { * * Passi: * 1. Mostra lo spinner di caricamento (rimuovi la classe nascosto) - * 2. Fai una fetch GET a /users - * 3. Se la risposta non è OK, usa handleError() per mostrare un messaggio e return - * 4. Converti la risposta da stringa JSON a oggetto JavaScript - * 5. Mostra i dati degli utenti chiamando mostraUtenti(users) - * 6. Nascondi lo spinner di caricamento (aggiungi la classe nascosto) + * 2. Apri un blocco try/catch + * 3. Fai una fetch GET a /users + * 4. Se la risposta non è OK, usa handleError() per mostrare un messaggio e return + * 5. Converti la risposta da stringa JSON a oggetto JavaScript + * 6. Mostra i dati degli utenti chiamando mostraUtenti(users) + * 7. Nascondi lo spinner di caricamento (aggiungi la classe nascosto) */ async function fetchAllUsers() { // TODO Rimuovi questa riga e completa la funzione diff --git a/javascript/JS_Esercizi 11 - API/03_utente_e_post/script.js b/javascript/JS_Esercizi 11 - API/03_utente_e_post/script.js index 98a0e86..f8d0f38 100644 --- a/javascript/JS_Esercizi 11 - API/03_utente_e_post/script.js +++ b/javascript/JS_Esercizi 11 - API/03_utente_e_post/script.js @@ -1,74 +1,30 @@ -// ⚠️ COMPILARE PRIMA DI INIZIARE +// ⚠️ COMPILARE E CONTROLLARE PRIMA DI INIZIARE ⚠️ const BASE_URL = 'http://localhost:3000/api'; +const userId = document.getElementById('userId'); +const loading = document.getElementById('loading'); +const userProfile = document.getElementById('userProfile'); +const postsContainer = document.getElementById('postsContainer'); +const btnFetch = document.getElementById('btnFetch'); + /** - * ESERCIZIO 3: Recupera un utente E tutti i suoi post + * FUNZIONE: Crea un utente card * - * Devi completare questa funzione: - * 1. Leggi l'ID dell'utente - * 2. Fai DUE fetch: - * - GET /users/{id} - * - GET /posts - * 3. Filtra i post per trovare solo quelli di questo utente (usando userId) - * 4. Mostra i risultati - * 5. Gestisci gli errori + * Crea la card completa dell'utente e la inserisce nell'elemento userProfile + * L'oggetto user ha questa struttura: + * { + * id: number, + * nome: string, + * cognome: string, + * email: string, + * avatar: string (url), + * dataNascita: string (formato YYYY-MM-DD), + * comune: string, + * attivo: boolean + * } */ -async function fetchUserAndPosts() { - const userId = document.getElementById('userId').value; - const loading = document.getElementById('loading'); - const userProfile = document.getElementById('userProfile'); - const postsContainer = document.getElementById('postsContainer'); - - if (!userId || userId < 1 || userId > 40) { - userProfile.innerHTML = '
${post.contenuto}
- -${post.contenuto}
+ +Esercizi Semplificati - Da Base a CRUD
+Esercizi Da Base a CRUD