added duration field to add_level

This commit is contained in:
realaravinth
2021-05-04 10:49:44 +05:30
parent e9c84b4ed4
commit e83a362e75
3 changed files with 13 additions and 5 deletions

View File

@@ -53,6 +53,7 @@ pub mod routes {
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct AddLevels { pub struct AddLevels {
pub levels: Vec<Level>, pub levels: Vec<Level>,
pub duration: u32,
} }
pub fn services(cfg: &mut web::ServiceConfig) { pub fn services(cfg: &mut web::ServiceConfig) {
@@ -103,7 +104,7 @@ async fn add_levels(
defense.build()?; defense.build()?;
let mcaptcha_config = add_mcaptcha_util(&data, &id).await?; let mcaptcha_config = add_mcaptcha_util(payload.duration, &data, &id).await?;
for level in payload.levels.iter() { for level in payload.levels.iter() {
let difficulty_factor = level.difficulty_factor as i32; let difficulty_factor = level.difficulty_factor as i32;

View File

@@ -88,7 +88,11 @@ pub struct MCaptchaDetails {
} }
// this should be called from within add levels // this should be called from within add levels
pub async fn add_mcaptcha_util(data: &Data, id: &Identity) -> ServiceResult<MCaptchaDetails> { pub async fn add_mcaptcha_util(
duration: u32,
data: &Data,
id: &Identity,
) -> ServiceResult<MCaptchaDetails> {
let username = id.identity().unwrap(); let username = id.identity().unwrap();
let mut key; let mut key;
@@ -99,10 +103,11 @@ pub async fn add_mcaptcha_util(data: &Data, id: &Identity) -> ServiceResult<MCap
let res = sqlx::query!( let res = sqlx::query!(
"INSERT INTO mcaptcha_config "INSERT INTO mcaptcha_config
(key, user_id) (key, user_id, duration)
VALUES ($1, (SELECT ID FROM mcaptcha_users WHERE name = $2))", VALUES ($1, (SELECT ID FROM mcaptcha_users WHERE name = $2), $3)",
&key, &key,
&username, &username,
duration as i32
) )
.execute(&data.db) .execute(&data.db)
.await; .await;
@@ -130,7 +135,8 @@ pub async fn add_mcaptcha_util(data: &Data, id: &Identity) -> ServiceResult<MCap
// this should be called from within add levels // this should be called from within add levels
async fn add_mcaptcha(data: web::Data<Data>, id: Identity) -> ServiceResult<impl Responder> { async fn add_mcaptcha(data: web::Data<Data>, id: Identity) -> ServiceResult<impl Responder> {
let resp = add_mcaptcha_util(&data, &id).await?; let duration = 30;
let resp = add_mcaptcha_util(duration, &data, &id).await?;
Ok(HttpResponse::Ok().json(resp)) Ok(HttpResponse::Ok().json(resp))
} }

View File

@@ -188,6 +188,7 @@ pub async fn add_levels_util(
let add_level = AddLevels { let add_level = AddLevels {
levels: levels.clone(), levels: levels.clone(),
duration: 30,
}; };
// 1. add level // 1. add level