-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
132 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::{admin, discord, user::User, Result}; | ||
use deadpool_sqlite::Pool; | ||
use jsonrpc_v2::{Data, Params}; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::{Map, Value}; | ||
use std::sync::Arc; | ||
use tracing::info; | ||
|
||
const NAME: &str = "remove_user_tag"; | ||
|
||
#[derive(Deserialize, Clone)] | ||
pub struct Args { | ||
pub password: String, | ||
pub user_name: String, | ||
pub tag_name: String, | ||
} | ||
|
||
#[derive(Serialize)] | ||
pub struct Res { | ||
pub id: i64, | ||
pub tags: Map<String, Value>, | ||
} | ||
|
||
pub async fn run(Params(args): Params<Args>, pool: Data<Arc<Pool>>) -> Result<Res> { | ||
let admin = admin::service::check_rpc(&args.password, NAME, &pool).await?; | ||
let cloned_args = args.clone(); | ||
let user = pool | ||
.get() | ||
.await? | ||
.interact(move |conn| User::select_by_name(&cloned_args.user_name, conn)) | ||
.await?? | ||
.ok_or(format!("There is no user with name = {}", args.user_name))?; | ||
let user = pool | ||
.get() | ||
.await? | ||
.interact(move |conn| User::remove_tag(user.id, &cloned_args.tag_name, conn)) | ||
.await?? | ||
.ok_or(format!("There is no user with name = {}", args.user_name))?; | ||
let log_message = format!( | ||
"{} removed tag {} for user {} https://api.btcmap.org/v3/users/{}", | ||
admin.name, args.tag_name, args.user_name, user.id, | ||
); | ||
info!(log_message); | ||
discord::send_message_to_channel(&log_message, discord::CHANNEL_API).await; | ||
Ok(Res { | ||
id: user.id, | ||
tags: user.tags, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::{admin, discord, user::User, Result}; | ||
use deadpool_sqlite::Pool; | ||
use jsonrpc_v2::{Data, Params}; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::{Map, Value}; | ||
use std::sync::Arc; | ||
use tracing::info; | ||
|
||
const NAME: &str = "set_user_tag"; | ||
|
||
#[derive(Deserialize, Clone)] | ||
pub struct Args { | ||
pub password: String, | ||
pub user_name: String, | ||
pub tag_name: String, | ||
pub tag_value: Value, | ||
} | ||
|
||
#[derive(Serialize)] | ||
pub struct Res { | ||
pub id: i64, | ||
pub tags: Map<String, Value>, | ||
} | ||
|
||
pub async fn run(Params(args): Params<Args>, pool: Data<Arc<Pool>>) -> Result<Res> { | ||
let admin = admin::service::check_rpc(&args.password, NAME, &pool).await?; | ||
let cloned_args = args.clone(); | ||
let user = pool | ||
.get() | ||
.await? | ||
.interact(move |conn| User::select_by_name(&cloned_args.user_name, conn)) | ||
.await?? | ||
.ok_or(format!("There is no user with name = {}", args.user_name))?; | ||
let user = pool | ||
.get() | ||
.await? | ||
.interact(move |conn| { | ||
User::set_tag(user.id, &cloned_args.tag_name, &cloned_args.tag_value, conn) | ||
}) | ||
.await??; | ||
let log_message = format!( | ||
"{} set tag {} = {} for user {} https://api.btcmap.org/v3/users/{}", | ||
admin.name, | ||
args.tag_name, | ||
serde_json::to_string(&args.tag_value)?, | ||
args.user_name, | ||
user.id, | ||
); | ||
info!(log_message); | ||
discord::send_message_to_channel(&log_message, discord::CHANNEL_API).await; | ||
Ok(Res { | ||
id: user.id, | ||
tags: user.tags, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters