From 6492b4c17175aa03a4bfaf7650f172032ba6cd88 Mon Sep 17 00:00:00 2001 From: Lheorvine Date: Sun, 1 Jun 2025 18:27:15 +0200 Subject: [PATCH] Beta #2 --- src/auth.rs | 4 ---- src/cart.rs | 6 +----- src/models.rs | 2 +- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index e629ea6..abf13ae 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -59,7 +59,6 @@ pub async fn login( if verify(&form.haslo, &user.haslo).map_err(|_| AppError::InternalServerError("Błąd serwera".to_string()))? { let token = format!("user-{}-token", user.id); - // Utwórz ciasteczko let cookie = Cookie::build("auth_token", &token) .path("/") .max_age(actix_web::cookie::time::Duration::days(7)) @@ -73,7 +72,6 @@ pub async fn login( imie: user.imie, }); - // Poprawiona obsługa błędów dla add_cookie response.add_cookie(&cookie) .map_err(|e| { log::error!("Błąd ustawiania ciasteczka: {}", e); @@ -88,7 +86,6 @@ pub async fn login( #[post("/logout")] pub async fn logout() -> impl Responder { - // Utwórz ciasteczko z datą wygaśnięcia w przeszłości let cookie = Cookie::build("auth_token", "") .path("/") .max_age(actix_web::cookie::time::Duration::seconds(0)) @@ -105,7 +102,6 @@ pub async fn logout() -> impl Responder { } pub async fn validate_token(req: &HttpRequest) -> Result { - // Pobierz ciasteczko let cookie = req.cookie("auth_token") .ok_or_else(|| AppError::Unauthorized("Unauthorized".to_string()))?; diff --git a/src/cart.rs b/src/cart.rs index 7e0b795..61aef38 100644 --- a/src/cart.rs +++ b/src/cart.rs @@ -6,7 +6,7 @@ use crate::auth::validate_token; use bigdecimal::BigDecimal; use serde_json::json; use log; -use std::str::FromStr; // Dodane +use std::str::FromStr; use crate::models::CartQuantityUpdate; #[get("/api/cart")] @@ -106,12 +106,10 @@ pub async fn checkout( AppError::InternalServerError("Błąd serwera".to_string()) })?; - // Konwersja f64 na BigDecimal let total_str = format!("{:.2}", data.total); let total_bigdecimal = BigDecimal::from_str(&total_str) .map_err(|_| AppError::BadRequest("Invalid total value".to_string()))?; - // 1. Utwórz zamówienie z typem dostawy let order_record = sqlx::query!( "INSERT INTO zamowienia (user_id, suma_totalna, typ_dostawy) VALUES ($1, $2, $3) RETURNING id", @@ -128,7 +126,6 @@ pub async fn checkout( let order_id = order_record.id; - // 2. Dodaj pozycje zamówienia for item in &data.items { let book = sqlx::query!( "SELECT cena FROM ksiazki WHERE id = $1", @@ -157,7 +154,6 @@ pub async fn checkout( })?; } - // 3. Wyczyść koszyk sqlx::query!( "DELETE FROM koszyk WHERE user_id = $1", user_id diff --git a/src/models.rs b/src/models.rs index a8b50e3..063afbe 100644 --- a/src/models.rs +++ b/src/models.rs @@ -77,5 +77,5 @@ pub struct CartQuantityUpdate { pub struct CheckoutRequest { pub items: Vec, pub total: f64, - pub delivery_type: String, // "shipping" lub "local" + pub delivery_type: String, }