Skip to content

Commit

Permalink
Merge pull request #227 from starknet-id/ayush/admin-api-updates
Browse files Browse the repository at this point in the history
feat: add i64 formatting to quests
  • Loading branch information
Th0rgal authored Jun 25, 2024
2 parents a7ef538 + d603da8 commit 33151cd
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/endpoints/admin/custom/create_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,7 +41,7 @@ pub async fn handler(
let quests_collection = state.db.collection::<QuestDocument>("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());
};
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/admin/custom/update_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use jsonwebtoken::{Validation,Algorithm,decode,DecodingKey};


pub_struct!(Deserialize; CreateCustom {
id: u32,
id: i64,
name: Option<String>,
desc: Option<String>,
cta: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/admin/discord/create_discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,7 +41,7 @@ pub async fn handler(
let quests_collection = state.db.collection::<QuestDocument>("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());
};
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/admin/discord/update_discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use jsonwebtoken::{Validation,Algorithm,decode,DecodingKey};


pub_struct!(Deserialize; CreateCustom {
id: u32,
id: i64,
name: Option<String>,
desc: Option<String>,
invite_link: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/admin/domain/create_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/admin/nft_uri/create_uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,7 +35,7 @@ pub async fn handler(
let quests_collection = state.db.collection::<QuestDocument>("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());
};
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/admin/quest_boost/create_boost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub async fn handler(
let quests_collection = state.db.collection::<QuestDocument>("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());
};
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/admin/quest_boost/update_boost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/admin/quiz/create_question.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/admin/quiz/create_quiz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/admin/quiz/update_question.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/admin/twitter/create_twitter_fw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/admin/twitter/create_twitter_rw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/admin/twitter/update_twitter_fw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub_struct!(Deserialize; UpdateTwitterFw {
});

#[route(
put,
post,
"/admin/tasks/twitter_fw/update",
crate::endpoints::admin::twitter::update_twitter_fw
)]
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/admin/twitter/update_twitter_rw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<AppState>>,
headers: HeaderMap,
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/get_completed_quests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub async fn handler(
Ok(mut cursor) => {
let mut quests: Vec<u32> = 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()
}
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/quests/discord_fw_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<&str>>();
let quest_id = state_split[1].parse::<u32>().unwrap();
let quest_id = state_split[1].parse::<i64>().unwrap();
let task_id = state_split[2].parse::<u32>().unwrap();
let addr = FieldElement::from_dec_str(state_split[0]).unwrap();

Expand Down
4 changes: 2 additions & 2 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -143,7 +143,7 @@ pub_struct!(Deserialize; VerifyQuery {

pub_struct!(Deserialize; VerifyNewQuery {
addr: FieldElement,
quest_id: u32,
quest_id: i64,
task_id: u32,
});

Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ pub async fn verify_task_auth(
pub async fn verify_quest_auth(
user: String,
quest_collection: &Collection<QuestDocument>,
id: &i32,
id: &i64,
) -> bool {
if user == "super_user" {
return true;
Expand Down

0 comments on commit 33151cd

Please sign in to comment.