Add basic geojson serialization capabilities

This commit is contained in:
GHOSCHT 2024-05-20 00:01:33 +02:00
parent 07c1051cde
commit ceaef9ca68
Signed by: ghoscht
GPG key ID: 2C2C1C62A5388E82
3 changed files with 12 additions and 6 deletions

3
Cargo.lock generated
View file

@ -847,6 +847,7 @@ checksum = "d69a45c13765c7c6dce8e0fc3d976e669d4de545529c769f44e55b59a4d76c69"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"diesel", "diesel",
"serde",
] ]
[[package]] [[package]]
@ -1039,6 +1040,8 @@ dependencies = [
"dotenvy", "dotenvy",
"http", "http",
"postgis_diesel", "postgis_diesel",
"serde",
"serde_json",
"tokio", "tokio",
] ]

View file

@ -16,5 +16,7 @@ diesel = { version = "2.1.6", features = ["postgres"] }
diesel-derive-enum = { version = "2.1.0", features = ["postgres"] } diesel-derive-enum = { version = "2.1.0", features = ["postgres"] }
dotenvy = "0.15.7" dotenvy = "0.15.7"
http = "1.1.0" http = "1.1.0"
postgis_diesel = "2.3.1" postgis_diesel = { version = "2.3.1", features = ["serde_geojson"] }
serde = { version = "1.0.202", features = ["derive"] }
serde_json = "1.0.117"
tokio = {version = "1.37.0", features = ["full"]} tokio = {version = "1.37.0", features = ["full"]}

View file

@ -1,15 +1,16 @@
use crate::schema::{nodes, restaurants}; use crate::schema::{nodes, restaurants};
use diesel::prelude::*; use diesel::prelude::*;
use postgis_diesel::types::Point; use postgis_diesel::types::Point;
use serde::{Deserialize, Serialize};
#[derive(diesel_derive_enum::DbEnum, Debug)] #[derive(diesel_derive_enum::DbEnum, Debug, Serialize, Deserialize)]
#[ExistingTypePath = "crate::schema::sql_types::NodeType"] #[ExistingTypePath = "crate::schema::sql_types::NodeType"]
pub enum NodeType { pub enum NodeType {
Marker, Marker,
Restaurant, Restaurant,
} }
#[derive(Insertable)] #[derive(Insertable, Serialize, Deserialize)]
#[diesel(table_name = nodes)] #[diesel(table_name = nodes)]
pub struct NewNode<'a> { pub struct NewNode<'a> {
pub name: &'a str, pub name: &'a str,
@ -17,7 +18,7 @@ pub struct NewNode<'a> {
pub coordinates: Point, pub coordinates: Point,
} }
#[derive(Debug, Queryable, AsChangeset)] #[derive(Debug, Queryable, AsChangeset, Deserialize)]
pub struct Node { pub struct Node {
pub id: i32, pub id: i32,
pub name: String, pub name: String,
@ -25,7 +26,7 @@ pub struct Node {
pub coordinates: Point, pub coordinates: Point,
} }
#[derive(Insertable)] #[derive(Insertable, Deserialize)]
#[diesel(table_name = restaurants)] #[diesel(table_name = restaurants)]
pub struct NewRestaurant<'a> { pub struct NewRestaurant<'a> {
pub node_id: i32, pub node_id: i32,
@ -33,7 +34,7 @@ pub struct NewRestaurant<'a> {
pub price: i16, pub price: i16,
} }
#[derive(Debug, Queryable, AsChangeset)] #[derive(Debug, Queryable, AsChangeset, Deserialize)]
pub struct Restaurant { pub struct Restaurant {
pub id: i32, pub id: i32,
pub node_id: i32, pub node_id: i32,