diff --git a/src/area/model.rs b/src/area/model.rs index f9475f1..7374fa9 100644 --- a/src/area/model.rs +++ b/src/area/model.rs @@ -1,7 +1,6 @@ use crate::{Error, Result}; use geojson::{GeoJson, Geometry}; use rusqlite::{named_params, Connection, OptionalExtension, Row}; -use serde::Serialize; use serde_json::{Map, Value}; use std::{ thread::sleep, @@ -10,15 +9,12 @@ use std::{ use time::{format_description::well_known::Rfc3339, OffsetDateTime}; use tracing::{debug, error, info}; -#[derive(Debug, Eq, PartialEq, Serialize)] +#[derive(Debug, Eq, PartialEq)] pub struct Area { pub id: i64, pub tags: Map, - #[serde(with = "time::serde::rfc3339")] pub created_at: OffsetDateTime, - #[serde(with = "time::serde::rfc3339")] pub updated_at: OffsetDateTime, - #[serde(with = "time::serde::rfc3339::option")] pub deleted_at: Option, } diff --git a/src/rpc/add_area.rs b/src/rpc/add_area.rs index 715716c..0d71aa4 100644 --- a/src/rpc/add_area.rs +++ b/src/rpc/add_area.rs @@ -1,6 +1,7 @@ +use super::model::RpcArea; +use crate::auth::Token; use crate::Result; use crate::{area, discord}; -use crate::{area::Area, auth::Token}; use deadpool_sqlite::Pool; use jsonrpc_v2::{Data, Params}; use serde::Deserialize; @@ -14,7 +15,7 @@ pub struct Args { pub tags: Map, } -pub async fn run(Params(args): Params, pool: Data>) -> Result { +pub async fn run(Params(args): Params, pool: Data>) -> Result { let token = pool .get() .await? @@ -34,5 +35,5 @@ pub async fn run(Params(args): Params, pool: Data>) -> Result, pool: Data>) -> Result { +pub async fn run(Params(args): Params, pool: Data>) -> Result { pool.get() .await? .interact(move |conn| Token::select_by_secret(&args.token, conn)) @@ -22,5 +23,5 @@ pub async fn run(Params(args): Params, pool: Data>) -> Result, + #[serde(with = "time::serde::rfc3339")] + pub created_at: OffsetDateTime, + #[serde(with = "time::serde::rfc3339")] + pub updated_at: OffsetDateTime, + #[serde(with = "time::serde::rfc3339::option")] + pub deleted_at: Option, +} + +impl Into for Area { + fn into(self) -> RpcArea { + RpcArea { + id: self.id, + tags: self.tags, + created_at: self.created_at, + updated_at: self.updated_at, + deleted_at: self.deleted_at, + } + } +} diff --git a/src/rpc/remove_area.rs b/src/rpc/remove_area.rs index 49052e0..72da003 100644 --- a/src/rpc/remove_area.rs +++ b/src/rpc/remove_area.rs @@ -1,4 +1,4 @@ -use crate::area::Area; +use super::model::RpcArea; use crate::Result; use crate::{area, auth::Token, discord}; use deadpool_sqlite::Pool; @@ -13,7 +13,7 @@ pub struct Args { pub id: String, } -pub async fn run(Params(args): Params, pool: Data>) -> Result { +pub async fn run(Params(args): Params, pool: Data>) -> Result { let token = pool .get() .await? @@ -33,5 +33,5 @@ pub async fn run(Params(args): Params, pool: Data>) -> Result, pool: Data>) -> Result { +pub async fn run(Params(args): Params, pool: Data>) -> Result { let token = pool .get() .await? @@ -38,5 +39,5 @@ pub async fn run(Params(args): Params, pool: Data>) -> Result, pool: Data>) -> Result { +pub async fn run(Params(args): Params, pool: Data>) -> Result { let token = pool .get() .await? @@ -42,5 +43,5 @@ pub async fn run(Params(args): Params, pool: Data>) -> Result