From 100bda3baba872377a81c6680c2f8439dabf6902 Mon Sep 17 00:00:00 2001 From: Lheorvine Date: Sat, 24 May 2025 19:23:52 +0200 Subject: [PATCH] dodano book.html --- src/main.rs | 10 +++++++--- static/book.html | 2 ++ static/css/styles.css | 45 ++++++++++++++++++++++++++++++------------- static/index.html | 1 + static/js/book.js | 27 +++++++++++++++++++------- 5 files changed, 62 insertions(+), 23 deletions(-) diff --git a/src/main.rs b/src/main.rs index 11141f7..a686221 100644 --- a/src/main.rs +++ b/src/main.rs @@ -106,7 +106,7 @@ async fn get_ksiazka( autor, cena, COALESCE('/images/' || obraz_url, '/images/placeholder.jpg') as obraz_url, - opis + COALESCE(opis, 'Brak opisu') as opis FROM ksiazki WHERE id = $1 "#, @@ -116,8 +116,11 @@ async fn get_ksiazka( .await { Ok(Some(book)) => HttpResponse::Ok().json(book), - Ok(None) => HttpResponse::NotFound().finish(), - Err(e) => HttpResponse::InternalServerError().body(format!("Błąd: {}", e)), + Ok(None) => HttpResponse::NotFound().json(json!({"error": "Książka nie znaleziona"})), + Err(e) => { + log::error!("Błąd bazy danych: {}", e); + HttpResponse::InternalServerError().json(json!({"error": "Błąd serwera"})) + } } } @@ -162,6 +165,7 @@ async fn main() -> std::io::Result<()> { .wrap(cors) .wrap(actix_web::middleware::Logger::default()) .service(get_ksiazki) + .service(get_ksiazka) .service(auth::rejestracja) .service(auth::login) .service( diff --git a/static/book.html b/static/book.html index dd02a63..8c567a9 100644 --- a/static/book.html +++ b/static/book.html @@ -78,6 +78,8 @@ + + diff --git a/static/css/styles.css b/static/css/styles.css index 1958863..d0e730e 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -66,31 +66,50 @@ footer { } #books-container { - grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); + display: grid; + grid-template-columns: repeat(auto-fill, minmax(450px, 1fr)); + gap: 1rem; + padding: 1rem; } .book-card { - max-width: none; - width: 100%; -} - -.book-cover { - height: 360px; + aspect-ratio: 5/8; + position: relative; + transition: transform 0.3s; } .book-cover img { - object-fit: contain; - padding: 15px; + width: 100%; + height: 100%; + object-fit: cover; + border-radius: 5px; +} + +.book-cover { + height: 100%; + width: 100%; + border-radius: 2px; + overflow: hidden; +} + +.book-card:hover { + transform: scale(1.05); + z-index: 1; } .book-overlay { - background: linear-gradient(0deg, rgba(7,44,36,0.9) 0%, rgba(7,44,36,0.7) 100%); - padding: 20px; + position: absolute; + bottom: 0; + left: 0; + right: 0; + padding: 1rem; + background: linear-gradient(0deg, rgba(7,44,36,0.9) 0%, rgba(0,0,0,0) 100%); } .book-title { - font-size: 1.2rem; - line-height: 1.4; + font-size: 1rem; + margin: 0; + color: #E3CB9A; } .book-cover:hover .book-overlay { diff --git a/static/index.html b/static/index.html index 436d7e6..7040c86 100644 --- a/static/index.html +++ b/static/index.html @@ -76,6 +76,7 @@ + diff --git a/static/js/book.js b/static/js/book.js index e6cd2f1..7eee6a4 100644 --- a/static/js/book.js +++ b/static/js/book.js @@ -1,23 +1,36 @@ document.addEventListener('DOMContentLoaded', async () => { const urlParams = new URLSearchParams(window.location.search); const bookId = urlParams.get('id'); + const bookDetails = document.getElementById('book-details'); + + if (!bookId) { + bookDetails.innerHTML = ` +
+

Nieprawidłowe ID książki

+ Powrót do strony głównej +
+ `; + return; + } try { const response = await fetch(`/api/ksiazki/${bookId}`); - if (!response.ok) throw new Error('Książka nie znaleziona'); - + if (!response.ok) { + throw new Error(`Status: ${response.status}`); + } const book = await response.json(); document.getElementById('book-title').textContent = book.tytul; document.getElementById('book-author').textContent = `Autor: ${book.autor}`; document.getElementById('book-price').textContent = `Cena: ${book.cena} PLN`; - document.getElementById('book-description').textContent = book.opis || 'Brak opisu'; - document.getElementById('book-cover').src = book.obraz_url || 'https://via.placeholder.com/400x600'; + document.getElementById('book-description').textContent = book.opis; + document.getElementById('book-cover').src = book.obraz_url; } catch (error) { console.error('Błąd:', error); - document.getElementById('book-details').innerHTML = ` -
-

Książka nie znaleziona

+ bookDetails.innerHTML = ` +
+

Błąd ładowania książki

+

${error.message}

Powrót do strony głównej
`;