RTIX / src /domain /models /feedback.rs
github-actions
deploy: clean backend production release
7856e60
Raw
History Blame Contribute Delete
1.22 kB
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<String>,
pub created_at: Option<chrono::NaiveDateTime>,
}
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<Vec<Self>> {
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
}
}