From 579dfc10ffc95ed686f8fb8cdb7efe83fefb12b7 Mon Sep 17 00:00:00 2001 From: MCMichinator Date: Fri, 29 Aug 2025 22:07:18 +0200 Subject: [PATCH] =?UTF-8?q?Gro=C3=9Fe=20Anpassung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/BookService.js | 153 ++-- src/pages/buchdetailseite/[id].vue | 18 +- src/pages/buecher-eintragen.vue | 1121 ++++++++++++++-------------- src/pages/buechersuche.vue | 142 ++-- 4 files changed, 705 insertions(+), 729 deletions(-) diff --git a/src/pages/BookService.js b/src/pages/BookService.js index 26ed099..c8cf7e4 100644 --- a/src/pages/BookService.js +++ b/src/pages/BookService.js @@ -1,82 +1,105 @@ -// VERSION 1: -/*import axios from 'axios' +// BookService.js -const baseUrl = 'http://localhost:8001/api/v1/book/registration/search/isbn/' // Passe die URL an - -export default { - getBookByIsbn(isbn) { - return axios.get(`${baseUrl}${isbn}`, { - headers: { - 'accept': 'application/json', - }, - }) - .catch(error => { - // Detailliertere Fehlerbehandlung - console.error('Fehler beim Abrufen des Buches:', error) - - // Zeige dem Benutzer eine informative Fehlermeldung an - }) - }, -}*/ - -// ******************************** -// VERSION 2: import axios from 'axios' -const baseUrl = 'http://localhost:8001/api/v1/book/registration/search/isbn/' +// const baseUrl = 'http://localhost:8001/api/v1/book/suggestion' +// const baseUrl = 'http://h2983688.stratoserver.net:8001/api/v1/book/suggestion' +// const baseUrl= 'https://skoutz-backend.it-tomaschko.de/api/v1/book/suggestion' + + + +const suggestionBase = 'http://localhost:8001/api/v1/book/suggestion' +const registrationBase = 'http://localhost:8001/api/v1/book/registration' export default { async getBookByIsbn(isbn) { + const { data } = await axios.get(`${suggestionBase}/search/isbn/${encodeURIComponent(isbn)}`, { + timeout: 5000, headers: { Accept: 'application/json' }, + }) + + return data + }, + + async getBookByTitle(title) { + const { data } = await axios.get(`${suggestionBase}/search/title`, { + params: { title }, timeout: 5000, headers: { Accept: 'application/json' }, + }) + + return data // Array von Vorschlägen + }, + + async registerBook(payload) { + // 1) Versuch: JSON-Body (das ist in modernen Spring-Stacks Standard) try { - const response = await axios.get(`${baseUrl}${isbn}`, { - timeout: 5000, // Adjust timeout as needed - }) + const { data } = await axios.post( + `${registrationBase}`, + payload, // <-- reines JSON, kein Wrapper + { + headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, + timeout: 8000, + }, + ) - return response.data - } catch (error) { - console.error('Fehler beim Abrufen des Buches:', error) - console.error('Antwort vom Server:', error.response) + return data + } catch (errJson) { + // Heuristiken, wann wir auf die 'book=' Variante zurückfallen sollten + const msg = (errJson?.response?.data && JSON.stringify(errJson.response.data)) || `${errJson}` - // Detailliertere Fehlerbehandlung basierend auf dem Fehlertyp - if (error.response && error.response.status === 404) { - console.error('Buch nicht gefunden') - } else if (error.code === 'ECONNABORTED') { - console.error('Verbindungsabbruch') - } else if (error.response && error.response.status === 500) { - console.error('Interner Serverfehler') - } else { - console.error('Unbekannter Fehler') + const shouldRetryAsForm = + /Required request parameter 'book'|MissingServletRequestParameter/i.test(msg) || + /Failed to read request|HTTP message not readable/i.test(msg) || + + // manche Backends antworten schlicht 500, wenn sie query-param erwarten + (/Failed to convert value of type 'java\.lang\.String' to required type 'de\.skoutz\.backend\.book\.Book'/i.test(msg)) + + if (!shouldRetryAsForm) { + throw errJson } - // Zeige dem Benutzer eine benutzerfreundliche Fehlermeldung an - throw new Error('Ein Fehler ist beim Abrufen des Buchs aufgetreten.') + // 2) Fallback: form-url-encoded mit 'book=' + try { + const body = new URLSearchParams() + + body.set('book', JSON.stringify(payload)) + + const { data } = await axios.post( + `${registrationBase}`, + body, + { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + Accept: 'application/json', + }, + timeout: 8000, + }, + ) + + return data + } catch (errForm) { + // schöner Fehlertext + const status = errForm?.response?.status + const backendMsg = errForm?.response?.data?.message || errForm?.response?.data?.error + + const msg2 = + backendMsg ? `${status ?? ''} ${backendMsg}`.trim() : + status === 400 ? 'Ungültige Daten (400).' : + status === 409 ? 'ISBN bereits registriert (409).' : + status === 500 ? 'Serverfehler (500).' : + 'Unbekannter Fehler beim Registrieren.' + + const e = new Error(msg2) + + e.response = errForm?.response; throw e + } } }, -} + async isIsbnRegistered(isbn) { + const { data } = await axios.get(`${registrationBase}/isIsbnRegistered/${encodeURIComponent(isbn)}`, { + timeout: 5000, headers: { Accept: 'application/json' }, + }) -// ******************************** -// VERSION 3: -/*const axios = require('axios') - -export default { - getBookByIsbn(isbn) { - // Make a request for a user with a given ID - console.log(isbn) - axios.get('http://localhost:8001/api/v1/book/registration/search/isbn/9783898798822') - .then(function (response) { - // handle success - console.log("hi", response) - }) - .catch(function (error) { - // handle error - console.log(error) - console.log("hi") - }) - .finally(function () { - // always executed - console.log("hi") - }) + return data === true || data === 'true' }, -}*/ +} diff --git a/src/pages/buchdetailseite/[id].vue b/src/pages/buchdetailseite/[id].vue index 4cd2823..2d37f71 100644 --- a/src/pages/buchdetailseite/[id].vue +++ b/src/pages/buchdetailseite/[id].vue @@ -4,7 +4,9 @@ -
+
@@ -164,3 +166,17 @@ const genreIcon = genre => { return icons[genre] || 'tabler-book' } + + + diff --git a/src/pages/buecher-eintragen.vue b/src/pages/buecher-eintragen.vue index 58c446e..c2a98ed 100644 --- a/src/pages/buecher-eintragen.vue +++ b/src/pages/buecher-eintragen.vue @@ -1,623 +1,586 @@ - + + diff --git a/src/pages/buechersuche.vue b/src/pages/buechersuche.vue index 2417b88..62f6e41 100644 --- a/src/pages/buechersuche.vue +++ b/src/pages/buechersuche.vue @@ -14,10 +14,14 @@ @update:values="updateFieberkurveValues" @filter-by-row="filterByRow" /> +
+ + Fieberkurve zurücksetzen + +

-
- - - - Alle Genres Zurücksetzen - +
+ + Genres zurücksetzen + +
-
+
+
+ + Alles zurücksetzen + +
- - - {{ resetFeedback ? 'Zurückgesetzt!' : 'Alle Einstellungen zurücksetzen' }} - - -
+
+ - {{ filteredBooks.length }} {{ filteredBooks.length === 1 ? 'Buch' : 'Bücher' }} gefunden - + @@ -88,90 +88,64 @@ + +