From d603da8a5c0389c4354a17619a5e7ff60f399f83 Mon Sep 17 00:00:00 2001 From: ayushtom Date: Sat, 22 Jun 2024 21:52:32 +0530 Subject: [PATCH] feat: add i64 formatting to code --- src/endpoints/admin/custom/create_custom.rs | 4 ++-- src/endpoints/admin/custom/update_custom.rs | 2 +- src/endpoints/admin/discord/create_discord.rs | 4 ++-- src/endpoints/admin/discord/update_discord.rs | 2 +- src/endpoints/admin/domain/create_domain.rs | 4 ++-- src/endpoints/admin/nft_uri/create_uri.rs | 4 ++-- src/endpoints/admin/quest_boost/create_boost.rs | 2 +- src/endpoints/admin/quest_boost/update_boost.rs | 2 +- src/endpoints/admin/quiz/create_question.rs | 2 +- src/endpoints/admin/quiz/create_quiz.rs | 4 ++-- src/endpoints/admin/quiz/update_question.rs | 2 +- src/endpoints/admin/twitter/create_twitter_fw.rs | 4 ++-- src/endpoints/admin/twitter/create_twitter_rw.rs | 4 ++-- src/endpoints/admin/twitter/update_twitter_fw.rs | 2 +- src/endpoints/admin/twitter/update_twitter_rw.rs | 2 +- src/endpoints/get_completed_quests.rs | 2 +- src/endpoints/quests/discord_fw_callback.rs | 2 +- src/models.rs | 4 ++-- src/utils.rs | 2 +- 19 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/endpoints/admin/custom/create_custom.rs b/src/endpoints/admin/custom/create_custom.rs index 1d80da55..97517a32 100644 --- a/src/endpoints/admin/custom/create_custom.rs +++ b/src/endpoints/admin/custom/create_custom.rs @@ -17,7 +17,7 @@ use jsonwebtoken::{Validation,Algorithm,decode,DecodingKey}; pub_struct!(Deserialize; CreateCustom { - quest_id: u32, + quest_id: i64, name: String, desc: String, cta: String, @@ -41,7 +41,7 @@ pub async fn handler( let quests_collection = state.db.collection::("quests"); - let res= verify_quest_auth(user, &quests_collection, &(body.quest_id as i32)).await; + let res= verify_quest_auth(user, &quests_collection, &(body.quest_id as i64)).await; if !res { return get_error("Error creating task".to_string()); }; diff --git a/src/endpoints/admin/custom/update_custom.rs b/src/endpoints/admin/custom/update_custom.rs index 4e40a635..294e269c 100644 --- a/src/endpoints/admin/custom/update_custom.rs +++ b/src/endpoints/admin/custom/update_custom.rs @@ -16,7 +16,7 @@ use jsonwebtoken::{Validation,Algorithm,decode,DecodingKey}; pub_struct!(Deserialize; CreateCustom { - id: u32, + id: i64, name: Option, desc: Option, cta: Option, diff --git a/src/endpoints/admin/discord/create_discord.rs b/src/endpoints/admin/discord/create_discord.rs index 56396e5d..1f7e97f8 100644 --- a/src/endpoints/admin/discord/create_discord.rs +++ b/src/endpoints/admin/discord/create_discord.rs @@ -18,7 +18,7 @@ use jsonwebtoken::{Validation,Algorithm,decode,DecodingKey}; pub_struct!(Deserialize; CreateCustom { - quest_id: u32, + quest_id: i64, name: String, desc: String, invite_link: String, @@ -41,7 +41,7 @@ pub async fn handler( let quests_collection = state.db.collection::("quests"); - let res= verify_quest_auth(user, &quests_collection, &(body.quest_id as i32)).await; + let res= verify_quest_auth(user, &quests_collection, &(body.quest_id as i64)).await; if !res { return get_error("Error creating task".to_string()); }; diff --git a/src/endpoints/admin/discord/update_discord.rs b/src/endpoints/admin/discord/update_discord.rs index ef6fd5a9..1b372ee4 100644 --- a/src/endpoints/admin/discord/update_discord.rs +++ b/src/endpoints/admin/discord/update_discord.rs @@ -16,7 +16,7 @@ use jsonwebtoken::{Validation,Algorithm,decode,DecodingKey}; pub_struct!(Deserialize; CreateCustom { - id: u32, + id: i64, name: Option, desc: Option, invite_link: Option, diff --git a/src/endpoints/admin/domain/create_domain.rs b/src/endpoints/admin/domain/create_domain.rs index 7638d536..99a0995a 100644 --- a/src/endpoints/admin/domain/create_domain.rs +++ b/src/endpoints/admin/domain/create_domain.rs @@ -20,7 +20,7 @@ use jsonwebtoken::{Validation,Algorithm,decode,DecodingKey}; pub_struct!(Deserialize; CreateTwitterFw { name: String, desc: String, - quest_id: i32, + quest_id: i64, }); #[route(post, "/admin/tasks/domain/create", crate::endpoints::admin::domain::create_domain)] @@ -53,7 +53,7 @@ pub async fn handler( name: body.name.clone(), desc: body.desc.clone(), href: "https://app.starknet.id/".to_string(), - quest_id: body.quest_id.clone() as u32, + quest_id: body.quest_id.clone(), id: next_id, verify_endpoint: "quests/verify_domain".to_string(), verify_endpoint_type: "default".to_string(), diff --git a/src/endpoints/admin/nft_uri/create_uri.rs b/src/endpoints/admin/nft_uri/create_uri.rs index c6cf18be..b94b3062 100644 --- a/src/endpoints/admin/nft_uri/create_uri.rs +++ b/src/endpoints/admin/nft_uri/create_uri.rs @@ -17,7 +17,7 @@ use crate::utils::verify_quest_auth; pub_struct!(Deserialize; CreateCustom { - quest_id: u32, + quest_id: i64, name: String, desc: String, image: String, @@ -35,7 +35,7 @@ pub async fn handler( let quests_collection = state.db.collection::("quests"); - let res= verify_quest_auth(user, &quests_collection, &(body.quest_id as i32)).await; + let res= verify_quest_auth(user, &quests_collection, &(body.quest_id as i64)).await; if !res { return get_error("Error creating task".to_string()); }; diff --git a/src/endpoints/admin/quest_boost/create_boost.rs b/src/endpoints/admin/quest_boost/create_boost.rs index eea84b42..1a307bcb 100644 --- a/src/endpoints/admin/quest_boost/create_boost.rs +++ b/src/endpoints/admin/quest_boost/create_boost.rs @@ -44,7 +44,7 @@ pub async fn handler( let quests_collection = state.db.collection::("quests"); - let res= verify_quest_auth(user, &quests_collection, &(body.quest_id as i32)).await; + let res= verify_quest_auth(user, &quests_collection, &(body.quest_id as i64)).await; if !res { return get_error("Error creating boost".to_string()); }; diff --git a/src/endpoints/admin/quest_boost/update_boost.rs b/src/endpoints/admin/quest_boost/update_boost.rs index d079328b..9a39c4f4 100644 --- a/src/endpoints/admin/quest_boost/update_boost.rs +++ b/src/endpoints/admin/quest_boost/update_boost.rs @@ -50,7 +50,7 @@ pub async fn handler( return get_error("boost does not exist".to_string()); } let quest_id = res.as_ref().unwrap().quests[0]; - let res = verify_quest_auth(user, &questcollection, &(quest_id as i32)).await; + let res = verify_quest_auth(user, &questcollection, &(quest_id as i64)).await; if !res { return get_error("Error updating boost".to_string()); diff --git a/src/endpoints/admin/quiz/create_question.rs b/src/endpoints/admin/quiz/create_question.rs index a9d2f878..60271268 100644 --- a/src/endpoints/admin/quiz/create_question.rs +++ b/src/endpoints/admin/quiz/create_question.rs @@ -50,7 +50,7 @@ pub async fn handler( } // get the quest id - let quest_id = res.as_ref().unwrap().id as i32; + let quest_id = res.as_ref().unwrap().id as i64; let res = verify_quest_auth(user, &quests_collection, &quest_id).await; if !res { diff --git a/src/endpoints/admin/quiz/create_quiz.rs b/src/endpoints/admin/quiz/create_quiz.rs index c88271d1..05c0ca12 100644 --- a/src/endpoints/admin/quiz/create_quiz.rs +++ b/src/endpoints/admin/quiz/create_quiz.rs @@ -23,7 +23,7 @@ pub_struct!(Deserialize; CreateQuiz { help_link: String, cta: String, intro: String, - quest_id: i32, + quest_id: i64, }); #[route(post, "/admin/tasks/quiz/create", crate::endpoints::admin::quiz::create_quiz)] @@ -83,7 +83,7 @@ pub async fn handler( desc: body.desc.clone(), href: body.help_link.clone(), cta: body.cta.clone(), - quest_id: body.quest_id.clone() as u32, + quest_id: body.quest_id.clone(), id: next_id.clone(), verify_endpoint: "/quests/verify_quiz".to_string(), verify_endpoint_type: "quiz".to_string(), diff --git a/src/endpoints/admin/quiz/update_question.rs b/src/endpoints/admin/quiz/update_question.rs index 5ac334df..5c3ddef8 100644 --- a/src/endpoints/admin/quiz/update_question.rs +++ b/src/endpoints/admin/quiz/update_question.rs @@ -54,7 +54,7 @@ pub async fn handler( } // get the quest id - let quest_id = res.as_ref().unwrap().id as i32; + let quest_id = res.as_ref().unwrap().id as i64; let res = verify_quest_auth(user, &quests_collection, &quest_id).await; if !res { diff --git a/src/endpoints/admin/twitter/create_twitter_fw.rs b/src/endpoints/admin/twitter/create_twitter_fw.rs index 52f0aead..133cc1b9 100644 --- a/src/endpoints/admin/twitter/create_twitter_fw.rs +++ b/src/endpoints/admin/twitter/create_twitter_fw.rs @@ -20,7 +20,7 @@ pub_struct!(Deserialize; CreateTwitterFw { name: String, desc: String, username: String, - quest_id: i32, + quest_id: i64, }); #[route(post, "/admin/tasks/twitter_fw/create", crate::endpoints::admin::twitter::create_twitter_fw)] @@ -55,7 +55,7 @@ pub async fn handler( desc: body.desc.clone(), verify_redirect: Some(format!("https://twitter.com/intent/user?screen_name={}", body.username.clone())), href: format!("https://twitter.com/{}", body.username.clone()), - quest_id: body.quest_id.clone() as u32, + quest_id: body.quest_id.clone(), id: next_id, verify_endpoint: "quests/verify_twitter_fw".to_string(), verify_endpoint_type: "default".to_string(), diff --git a/src/endpoints/admin/twitter/create_twitter_rw.rs b/src/endpoints/admin/twitter/create_twitter_rw.rs index cb60533b..77bdb98e 100644 --- a/src/endpoints/admin/twitter/create_twitter_rw.rs +++ b/src/endpoints/admin/twitter/create_twitter_rw.rs @@ -20,7 +20,7 @@ pub_struct!(Deserialize; CreateTwitterRw { name: String, desc: String, post_link: String, - quest_id: i32, + quest_id: i64, }); #[route(post, "/admin/tasks/twitter_rw/create", crate::endpoints::admin::twitter::create_twitter_rw)] @@ -55,7 +55,7 @@ pub async fn handler( desc: body.desc.clone(), verify_redirect: Some(body.post_link.clone()), href: body.post_link.clone(), - quest_id: body.quest_id.clone() as u32, + quest_id: body.quest_id.clone(), id: next_id, verify_endpoint: "quests/verify_twitter_rw".to_string(), verify_endpoint_type: "default".to_string(), diff --git a/src/endpoints/admin/twitter/update_twitter_fw.rs b/src/endpoints/admin/twitter/update_twitter_fw.rs index 41db85ac..d68dc893 100644 --- a/src/endpoints/admin/twitter/update_twitter_fw.rs +++ b/src/endpoints/admin/twitter/update_twitter_fw.rs @@ -23,7 +23,7 @@ pub_struct!(Deserialize; UpdateTwitterFw { }); #[route( -put, +post, "/admin/tasks/twitter_fw/update", crate::endpoints::admin::twitter::update_twitter_fw )] diff --git a/src/endpoints/admin/twitter/update_twitter_rw.rs b/src/endpoints/admin/twitter/update_twitter_rw.rs index 3a07ad05..61db091e 100644 --- a/src/endpoints/admin/twitter/update_twitter_rw.rs +++ b/src/endpoints/admin/twitter/update_twitter_rw.rs @@ -23,7 +23,7 @@ pub_struct!(Deserialize; UpdateTwitterRw { id: i32, }); -#[route(put, "/admin/tasks/twitter_rw/update", crate::endpoints::admin::twitter::update_twitter_rw)] +#[route(post, "/admin/tasks/twitter_rw/update", crate::endpoints::admin::twitter::update_twitter_rw)] pub async fn handler( State(state): State>, headers: HeaderMap, diff --git a/src/endpoints/get_completed_quests.rs b/src/endpoints/get_completed_quests.rs index 94482817..cca1debb 100644 --- a/src/endpoints/get_completed_quests.rs +++ b/src/endpoints/get_completed_quests.rs @@ -82,7 +82,7 @@ pub async fn handler( Ok(mut cursor) => { let mut quests: Vec = Vec::new(); while let Some(result) = cursor.try_next().await.unwrap() { - quests.push(result.get("quest_id").unwrap().as_i32().unwrap() as u32); + quests.push(result.get("quest_id").unwrap().as_i64().unwrap() as u32); } (StatusCode::OK, Json(quests)).into_response() } diff --git a/src/endpoints/quests/discord_fw_callback.rs b/src/endpoints/quests/discord_fw_callback.rs index 3341d092..15e1294e 100644 --- a/src/endpoints/quests/discord_fw_callback.rs +++ b/src/endpoints/quests/discord_fw_callback.rs @@ -36,7 +36,7 @@ pub async fn handler( ) -> impl IntoResponse { // the state is in format => "address+quest_id+task_id" let state_split = query.state.split('+').collect::>(); - let quest_id = state_split[1].parse::().unwrap(); + let quest_id = state_split[1].parse::().unwrap(); let task_id = state_split[2].parse::().unwrap(); let addr = FieldElement::from_dec_str(state_split[0]).unwrap(); diff --git a/src/models.rs b/src/models.rs index 86062d76..1ea901a6 100644 --- a/src/models.rs +++ b/src/models.rs @@ -109,7 +109,7 @@ pub struct CompletedTaskDocument { #[derive(Debug, Serialize, Deserialize, Default)] pub struct QuestTaskDocument { pub(crate) id: i32, - pub quest_id: u32, + pub quest_id: i64, pub name: String, pub desc: String, pub cta: String, @@ -143,7 +143,7 @@ pub_struct!(Deserialize; VerifyQuery { pub_struct!(Deserialize; VerifyNewQuery { addr: FieldElement, - quest_id: u32, + quest_id: i64, task_id: u32, }); diff --git a/src/utils.rs b/src/utils.rs index 50e7f773..aae0c87f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -784,7 +784,7 @@ pub async fn verify_task_auth( pub async fn verify_quest_auth( user: String, quest_collection: &Collection, - id: &i32, + id: &i64, ) -> bool { if user == "super_user" { return true;