120 lines
3 KiB
Rust
120 lines
3 KiB
Rust
|
|
/// Models
|
||
|
|
use serde::{Deserialize, Serialize};
|
||
|
|
|
||
|
|
/// Place can be any place of interest we want to mark in a map
|
||
|
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||
|
|
pub struct Place {
|
||
|
|
pub id: i64,
|
||
|
|
/// Name
|
||
|
|
pub name: String,
|
||
|
|
/// Address
|
||
|
|
pub address: String,
|
||
|
|
/// Opening Hours
|
||
|
|
pub open_hours: String,
|
||
|
|
/// Icon name
|
||
|
|
pub icon: String,
|
||
|
|
/// Description
|
||
|
|
pub description: String,
|
||
|
|
/// Longitude of the place
|
||
|
|
pub longitude: f64,
|
||
|
|
/// latitude of the place
|
||
|
|
pub latitude: f64,
|
||
|
|
/// URL for the place website
|
||
|
|
pub url: Option<String>,
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Insert Place payload
|
||
|
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||
|
|
pub struct PlaceInsert {
|
||
|
|
/// Name
|
||
|
|
pub name: String,
|
||
|
|
/// Address
|
||
|
|
pub address: String,
|
||
|
|
/// Opening Hours
|
||
|
|
pub open_hours: String,
|
||
|
|
/// Icon name
|
||
|
|
pub icon: String,
|
||
|
|
/// Description
|
||
|
|
pub description: String,
|
||
|
|
/// Longitude of the place
|
||
|
|
pub longitude: f64,
|
||
|
|
/// latitude of the place
|
||
|
|
pub latitude: f64,
|
||
|
|
/// URL for the place website
|
||
|
|
pub url: Option<String>,
|
||
|
|
}
|
||
|
|
|
||
|
|
/// UpsertPlace payload
|
||
|
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||
|
|
pub struct PlaceUpsert {
|
||
|
|
pub id: Option<i64>,
|
||
|
|
/// Name
|
||
|
|
pub name: String,
|
||
|
|
/// Address
|
||
|
|
pub address: String,
|
||
|
|
/// Opening Hours
|
||
|
|
pub open_hours: String,
|
||
|
|
/// Icon name
|
||
|
|
pub icon: String,
|
||
|
|
/// Description
|
||
|
|
pub description: String,
|
||
|
|
/// Longitude of the place
|
||
|
|
pub longitude: f64,
|
||
|
|
/// latitude of the place
|
||
|
|
pub latitude: f64,
|
||
|
|
/// URL for the place website
|
||
|
|
pub url: Option<String>,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl From<(PlaceInsert, i64)> for Place {
|
||
|
|
fn from((place, id): (PlaceInsert, i64)) -> Self {
|
||
|
|
Self {
|
||
|
|
id,
|
||
|
|
name: place.name,
|
||
|
|
address: place.address,
|
||
|
|
open_hours: place.open_hours,
|
||
|
|
icon: place.icon,
|
||
|
|
description: place.description,
|
||
|
|
longitude: place.longitude,
|
||
|
|
latitude: place.latitude,
|
||
|
|
url: place.url,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl From<PlaceUpsert> for (PlaceInsert, Option<i64>) {
|
||
|
|
fn from(place: PlaceUpsert) -> Self {
|
||
|
|
(
|
||
|
|
PlaceInsert {
|
||
|
|
name: place.name,
|
||
|
|
address: place.address,
|
||
|
|
open_hours: place.open_hours,
|
||
|
|
icon: place.icon,
|
||
|
|
description: place.description,
|
||
|
|
longitude: place.longitude,
|
||
|
|
latitude: place.latitude,
|
||
|
|
url: place.url,
|
||
|
|
},
|
||
|
|
place.id,
|
||
|
|
)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl From<Place> for (PlaceInsert, i64) {
|
||
|
|
fn from(place: Place) -> Self {
|
||
|
|
(
|
||
|
|
PlaceInsert {
|
||
|
|
name: place.name,
|
||
|
|
address: place.address,
|
||
|
|
open_hours: place.open_hours,
|
||
|
|
icon: place.icon,
|
||
|
|
description: place.description,
|
||
|
|
longitude: place.longitude,
|
||
|
|
latitude: place.latitude,
|
||
|
|
url: place.url,
|
||
|
|
},
|
||
|
|
place.id,
|
||
|
|
)
|
||
|
|
}
|
||
|
|
}
|