1- use super :: model:: RpcArea ;
21use crate :: {
3- db:: { conf :: schema:: Conf , user :: schema :: User } ,
4- service:: { self , discord } ,
2+ db:: area :: schema:: Area ,
3+ service:: { self } ,
54 Result ,
65} ;
76use deadpool_sqlite:: Pool ;
8- use serde:: Deserialize ;
7+ use serde:: { Deserialize , Serialize } ;
98use serde_json:: { Map , Value } ;
9+ use time:: OffsetDateTime ;
1010
1111#[ derive( Deserialize ) ]
1212pub struct Params {
@@ -15,22 +15,35 @@ pub struct Params {
1515 pub value : Value ,
1616}
1717
18- pub async fn run ( params : Params , user : & User , pool : & Pool , conf : & Conf ) -> Result < RpcArea > {
18+ #[ derive( Debug , Eq , PartialEq , Serialize ) ]
19+ pub struct Res {
20+ pub id : i64 ,
21+ pub tags : Map < String , Value > ,
22+ #[ serde( with = "time::serde::rfc3339" ) ]
23+ pub created_at : OffsetDateTime ,
24+ #[ serde( with = "time::serde::rfc3339" ) ]
25+ pub updated_at : OffsetDateTime ,
26+ #[ serde( with = "time::serde::rfc3339::option" ) ]
27+ pub deleted_at : Option < OffsetDateTime > ,
28+ }
29+
30+ impl From < Area > for Res {
31+ fn from ( val : Area ) -> Self {
32+ Res {
33+ id : val. id ,
34+ tags : val. tags ,
35+ created_at : val. created_at ,
36+ updated_at : val. updated_at ,
37+ deleted_at : val. deleted_at ,
38+ }
39+ }
40+ }
41+
42+ pub async fn run ( params : Params , pool : & Pool ) -> Result < Res > {
1943 let patch_set = Map :: from_iter ( [ ( params. name . clone ( ) , params. value . clone ( ) ) ] . into_iter ( ) ) ;
20- let area = service:: area:: patch_tags ( & params. id , patch_set, pool) . await ?;
21- discord:: send (
22- format ! (
23- "{} set tag {} = {} for area {} ({})" ,
24- user. name,
25- params. name,
26- serde_json:: to_string( & params. value) ?,
27- area. name( ) ,
28- area. id,
29- ) ,
30- discord:: Channel :: Api ,
31- conf,
32- ) ;
33- Ok ( area. into ( ) )
44+ service:: area:: patch_tags ( & params. id , patch_set, pool)
45+ . await
46+ . map ( Into :: into)
3447}
3548
3649#[ cfg( test) ]
0 commit comments