1- use super :: model:: RpcArea ;
2- use crate :: { db, Result } ;
1+ use crate :: {
2+ db:: { self , area:: schema:: Area } ,
3+ Result ,
4+ } ;
35use base64:: prelude:: * ;
46use deadpool_sqlite:: Pool ;
5- use serde:: Deserialize ;
7+ use geojson:: JsonObject ;
8+ use serde:: { Deserialize , Serialize } ;
69use serde_json:: Map ;
710use std:: { fs:: OpenOptions , io:: Write } ;
11+ use time:: OffsetDateTime ;
812
913#[ derive( Deserialize ) ]
1014pub struct Params {
@@ -13,7 +17,31 @@ pub struct Params {
1317 pub icon_ext : String ,
1418}
1519
16- pub async fn run ( params : Params , pool : & Pool ) -> Result < RpcArea > {
20+ #[ derive( Debug , Eq , PartialEq , Serialize ) ]
21+ pub struct Res {
22+ pub id : i64 ,
23+ pub tags : JsonObject ,
24+ #[ serde( with = "time::serde::rfc3339" ) ]
25+ pub created_at : OffsetDateTime ,
26+ #[ serde( with = "time::serde::rfc3339" ) ]
27+ pub updated_at : OffsetDateTime ,
28+ #[ serde( with = "time::serde::rfc3339::option" ) ]
29+ pub deleted_at : Option < OffsetDateTime > ,
30+ }
31+
32+ impl From < Area > for Res {
33+ fn from ( val : Area ) -> Self {
34+ Res {
35+ id : val. id ,
36+ tags : val. tags ,
37+ created_at : val. created_at ,
38+ updated_at : val. updated_at ,
39+ deleted_at : val. deleted_at ,
40+ }
41+ }
42+ }
43+
44+ pub async fn run ( params : Params , pool : & Pool ) -> Result < Res > {
1745 let area = db:: area:: queries:: select_by_id_or_alias ( & params. id , pool) . await ?;
1846 let file_name = format ! ( "{}.{}" , area. id, params. icon_ext) ;
1947 let bytes = BASE64_STANDARD . decode ( params. icon_base64 ) ?;
0 commit comments