use crate::infrastructure::db::DbPool; use serde::{Deserialize, Serialize}; use uuid::Uuid; #[derive(Debug, Serialize, Deserialize, sqlx::FromRow)] pub struct ProductFeedback { pub id: Uuid, pub transaction_id: String, pub product_id: String, pub rating: i32, pub comment: Option, pub created_at: Option, } impl ProductFeedback { pub async fn create(pool: &DbPool, feedback: &Self) -> sqlx::Result<()> { sqlx::query( "INSERT INTO product_feedback (id, transaction_id, product_id, rating, comment) VALUES ($1, $2, $3, $4, $5)" ) .bind(feedback.id) .bind(&feedback.transaction_id) .bind(&feedback.product_id) .bind(feedback.rating) .bind(&feedback.comment) .execute(pool) .await?; Ok(()) } pub async fn get_for_merchant(pool: &DbPool, merchant_id: &str) -> sqlx::Result> { sqlx::query_as::<_, Self>( "SELECT f.* FROM product_feedback f JOIN orders o ON f.transaction_id = o.transaction_id WHERE o.merchant_id = $1 ORDER BY f.created_at DESC" ) .bind(merchant_id) .fetch_all(pool) .await } }