Beta #2
This commit is contained in:
parent
5e0a3cfabe
commit
6492b4c171
3 changed files with 2 additions and 10 deletions
|
@ -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<i32, AppError> {
|
||||
// Pobierz ciasteczko
|
||||
let cookie = req.cookie("auth_token")
|
||||
.ok_or_else(|| AppError::Unauthorized("Unauthorized".to_string()))?;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -77,5 +77,5 @@ pub struct CartQuantityUpdate {
|
|||
pub struct CheckoutRequest {
|
||||
pub items: Vec<CartItem>,
|
||||
pub total: f64,
|
||||
pub delivery_type: String, // "shipping" lub "local"
|
||||
pub delivery_type: String,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue