From f8b3c3e1fc249c513553fb44cc10c4fa05eda6ee Mon Sep 17 00:00:00 2001 From: Sandertp Date: Tue, 3 Sep 2024 10:38:55 +0200 Subject: [PATCH] Add Review Table to Rust Backend and migrated Co-authored-by: Reimar --- .../migrations/V3__create_reviews_table.sql | 12 ++++++++ rust-backend/src/models.rs | 29 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 rust-backend/migrations/V3__create_reviews_table.sql diff --git a/rust-backend/migrations/V3__create_reviews_table.sql b/rust-backend/migrations/V3__create_reviews_table.sql new file mode 100644 index 0000000..6ab31b4 --- /dev/null +++ b/rust-backend/migrations/V3__create_reviews_table.sql @@ -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 +); + diff --git a/rust-backend/src/models.rs b/rust-backend/src/models.rs index 4892d0b..c4933ac 100644 --- a/rust-backend/src/models.rs +++ b/rust-backend/src/models.rs @@ -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 { + 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")?, + }) + } +} +