Add Review Table to Rust Backend and migrated

Co-authored-by: Reimar <mail@reim.ar>
This commit is contained in:
Sandertp 2024-09-03 10:38:55 +02:00
parent 9a0757922d
commit f8b3c3e1fc
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,12 @@
CREATE TABLE reviews (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id TEXT NOT NULL,
lat REAL NOT NULL,
lng REAL NOT NULL,
place_name TEXT NOT NULL,
place_description TEXT NOT NULL,
title TEXT NOT NULL,
content TEXT NOT NULL,
rating REAL NOT NULL
);

View File

@ -25,3 +25,32 @@ impl Favorite {
} }
} }
#[derive(Serialize)]
pub struct Review {
pub id: i64,
pub user_id: String,
pub lat: f64,
pub lng: f64,
pub place_name: String,
pub place_description: String,
pub title: String,
pub content: String,
pub rating: i64,
}
impl Review {
pub fn from_row(row: &Row) -> Result<Self, Error> {
Ok(Review {
id: row.get("id")?,
user_id: row.get("user_id")?,
lat: row.get("lat")?,
lng: row.get("lng")?,
place_name: row.get("place_name")?,
place_description: row.get("place_description")?,
title: row.get("title")?,
content: row.get("content")?,
rating: row.get("rating")?,
})
}
}