Skip to content

Commit 47a3f57

Browse files
committed
Refactor RPC
1 parent 737ab53 commit 47a3f57

File tree

4 files changed

+33
-49
lines changed

4 files changed

+33
-49
lines changed

src/rpc/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ pub async fn handle(
432432
),
433433
RpcMethod::SetAreaTag => RpcResponse::from(
434434
req.id.clone(),
435-
super::set_area_tag::run(params(req.params)?, &user.unwrap(), &pool, &conf).await?,
435+
super::set_area_tag::run(params(req.params)?, &pool).await?,
436436
),
437437
RpcMethod::RemoveAreaTag => RpcResponse::from(
438438
req.id.clone(),

src/rpc/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub mod handler;
2222
pub mod import;
2323
pub mod invoice;
2424
pub mod matrix;
25-
pub mod model;
2625
pub mod paywall_add_element_comment;
2726
pub mod paywall_boost_element;
2827
pub mod paywall_get_add_element_comment_quote;

src/rpc/model.rs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/rpc/set_area_tag.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use super::model::RpcArea;
21
use crate::{
3-
db::{conf::schema::Conf, user::schema::User},
4-
service::{self, discord},
2+
db::area::schema::Area,
3+
service::{self},
54
Result,
65
};
76
use deadpool_sqlite::Pool;
8-
use serde::Deserialize;
7+
use serde::{Deserialize, Serialize};
98
use serde_json::{Map, Value};
9+
use time::OffsetDateTime;
1010

1111
#[derive(Deserialize)]
1212
pub 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

Comments
 (0)