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 = [
"byteorder",
"diesel",
"serde",
]
[[package]]
@ -1039,6 +1040,8 @@ dependencies = [
"dotenvy",
"http",
"postgis_diesel",
"serde",
"serde_json",
"tokio",
]

View file

@ -16,5 +16,7 @@ diesel = { version = "2.1.6", features = ["postgres"] }
diesel-derive-enum = { version = "2.1.0", features = ["postgres"] }
dotenvy = "0.15.7"
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"]}

View file

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