From f025ad2deb7ad43496b5aff46c94f83af1cccdf2 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 20 Sep 2023 22:18:39 +0200 Subject: [PATCH] Add imageurl column to locations table --- .gitignore | 1 + README.md | 1 - backend/.gitignore | 1 - backend/migrations/2023-09-20-194906_image_url/down.sql | 1 + backend/migrations/2023-09-20-194906_image_url/up.sql | 1 + backend/src/main.rs | 1 + backend/src/models.rs | 4 ++++ backend/src/schema.rs | 1 + frontend/src/models/schemas.ts | 1 + 9 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 backend/migrations/2023-09-20-194906_image_url/down.sql create mode 100644 backend/migrations/2023-09-20-194906_image_url/up.sql diff --git a/.gitignore b/.gitignore index 722d5e7..aafda3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .vscode +.idea diff --git a/README.md b/README.md index af62f9e..82c24a4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ ## TODO -- Export response schema to typescript using schemars -> jsonschema -> json-schema-to-typescript - Implement session based login using this example: https://github.com/SergioBenitez/Rocket/tree/master/examples/cookies ## System requirements diff --git a/backend/.gitignore b/backend/.gitignore index c507849..eb5a316 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,2 +1 @@ target -.idea diff --git a/backend/migrations/2023-09-20-194906_image_url/down.sql b/backend/migrations/2023-09-20-194906_image_url/down.sql new file mode 100644 index 0000000..8e6b547 --- /dev/null +++ b/backend/migrations/2023-09-20-194906_image_url/down.sql @@ -0,0 +1 @@ +ALTER TABLE locations DROP COLUMN ImageURL; diff --git a/backend/migrations/2023-09-20-194906_image_url/up.sql b/backend/migrations/2023-09-20-194906_image_url/up.sql new file mode 100644 index 0000000..e1ceaab --- /dev/null +++ b/backend/migrations/2023-09-20-194906_image_url/up.sql @@ -0,0 +1 @@ +ALTER TABLE locations ADD ImageURL TEXT; diff --git a/backend/src/main.rs b/backend/src/main.rs index 5a72a4c..905af9b 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -51,6 +51,7 @@ async fn add_bar(conn: Db, bar: Json) -> Json { description: bar.description.clone(), osm_node_id: bar.osm_node_id.clone(), google_place_id: bar.google_place_id.clone(), + imageurl: bar.imageurl.clone(), }; let in_db = conn diff --git a/backend/src/models.rs b/backend/src/models.rs index 2a2ce02..3fb4322 100644 --- a/backend/src/models.rs +++ b/backend/src/models.rs @@ -15,6 +15,7 @@ pub struct Location { pub description: Option, pub osm_node_id: Option, pub google_place_id: Option, + pub imageurl: Option, } #[derive(Deserialize, Serialize, JsonSchema)] @@ -29,6 +30,7 @@ pub struct LocationResponse { pub name: String, pub description: Option, pub coordinates: Coordinate, + pub imageurl: Option, } #[derive(Deserialize, Insertable)] @@ -40,6 +42,7 @@ pub struct NewLocation { pub description: Option, pub osm_node_id: Option, pub google_place_id: Option, + pub imageurl: Option, } // TODO: Implement traits for Serde and JsonSchema for Point type @@ -59,6 +62,7 @@ impl From<&Location> for LocationResponse { name: l.name.clone(), description: l.description.clone(), coordinates: Coordinate::from(l.coordinates), + imageurl: l.imageurl.clone(), } } } diff --git a/backend/src/schema.rs b/backend/src/schema.rs index 146903e..62c226b 100644 --- a/backend/src/schema.rs +++ b/backend/src/schema.rs @@ -12,6 +12,7 @@ diesel::table! { description -> Nullable, osm_node_id -> Nullable, google_place_id -> Nullable, + imageurl -> Nullable, } } diff --git a/frontend/src/models/schemas.ts b/frontend/src/models/schemas.ts index 2bfb9df..929878a 100644 --- a/frontend/src/models/schemas.ts +++ b/frontend/src/models/schemas.ts @@ -9,6 +9,7 @@ export interface LocationResponse { coordinates: Coordinate; description?: string | null; id: number; + imageurl?: string | null; name: string; } export interface Coordinate {