mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
port query: set w2l template mod approval
This commit is contained in:
1 parent
d182f800f7
commit
96b80b35a5
3 files changed
+44
-18
No files matched your search
@@ -1,4 +1,5 @@
|
||||
pub mod delete_w2l_template_various_scopes;
|
||||
pub mod get_w2l_template;
|
||||
pub mod list_pending_w2l_templates;
|
||||
pub mod list_w2l_templates;
|
||||
pub mod list_w2l_templates;
|
||||
pub mod set_w2l_template_mod_approval;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
use anyhow::anyhow;
|
||||
use errors::AnyhowResult;
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
pub async fn set_w2l_template_mod_approval(
|
||||
w2l_template_token: &str,
|
||||
mod_user_token: &str,
|
||||
is_approved: bool,
|
||||
mysql_pool: &MySqlPool,
|
||||
) -> AnyhowResult<()> {
|
||||
|
||||
let query_result = sqlx::query!(
|
||||
r#"
|
||||
UPDATE w2l_templates
|
||||
SET
|
||||
is_public_listing_approved = ?,
|
||||
maybe_mod_user_token = ?
|
||||
WHERE
|
||||
token = ?
|
||||
LIMIT 1
|
||||
"#,
|
||||
|
||||
is_approved,
|
||||
mod_user_token,
|
||||
w2l_template_token,
|
||||
)
|
||||
.execute(mysql_pool)
|
||||
.await;
|
||||
|
||||
match query_result {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(anyhow!("error setting w2l mod approval status: {:?}", err)),
|
||||
}
|
||||
}
|
||||
+8
-17
@@ -18,6 +18,7 @@ use sqlx::error::Error::Database;
|
||||
use sqlx::mysql::MySqlDatabaseError;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use database_queries::queries::w2l::w2l_templates::set_w2l_template_mod_approval::set_w2l_template_mod_approval;
|
||||
|
||||
/// For the URL PathInfo
|
||||
#[derive(Deserialize)]
|
||||
@@ -117,23 +118,12 @@ pub async fn set_w2l_template_mod_approval_handler(
|
||||
|
||||
let ip_address = get_request_ip(&http_request);
|
||||
|
||||
let query_result = sqlx::query!(
|
||||
r#"
|
||||
UPDATE w2l_templates
|
||||
SET
|
||||
is_public_listing_approved = ?,
|
||||
maybe_mod_user_token = ?
|
||||
WHERE
|
||||
token = ?
|
||||
LIMIT 1
|
||||
"#,
|
||||
|
||||
&request.is_approved,
|
||||
&user_session.user_token,
|
||||
&path.token,
|
||||
)
|
||||
.execute(&server_state.mysql_pool)
|
||||
.await;
|
||||
let query_result = set_w2l_template_mod_approval(
|
||||
&path.token,
|
||||
&user_session.user_token,
|
||||
request.is_approved,
|
||||
&server_state.mysql_pool,
|
||||
).await;
|
||||
|
||||
match query_result {
|
||||
Ok(_) => {},
|
||||
@@ -142,6 +132,7 @@ LIMIT 1
|
||||
return Err(SetW2lTemplateModApprovalError::ServerError);
|
||||
}
|
||||
};
|
||||
|
||||
let response = SetW2lTemplateModApprovalSuccessResponse {
|
||||
success: true,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user