mcaptcah uses const routes

This commit is contained in:
realaravinth
2021-05-02 16:35:15 +05:30
parent 76ae2b03e9
commit 5361e9b43a
9 changed files with 141 additions and 46 deletions

View File

@@ -16,12 +16,11 @@
*/
use actix_identity::Identity;
use actix_web::{post, web, HttpResponse, Responder};
use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};
use crate::api::v1::mcaptcha::mcaptcha::MCaptchaDetails;
use crate::errors::*;
use crate::CheckLogin;
use crate::Data;
pub mod routes {
@@ -45,8 +44,8 @@ pub struct UpdateDuration {
pub duration: i32,
}
#[post("/api/v1/mcaptcha/domain/token/duration/update", wrap = "CheckLogin")]
pub async fn update_duration(
//#[post("/api/v1/mcaptcha/domain/token/duration/update", wrap = "CheckLogin")]
async fn update_duration(
payload: web::Json<UpdateDuration>,
data: web::Data<Data>,
id: Identity,
@@ -83,8 +82,8 @@ pub struct GetDuration {
pub token: String,
}
#[post("/api/v1/mcaptcha/domain/token/duration/get", wrap = "CheckLogin")]
pub async fn get_duration(
//#[post("/api/v1/mcaptcha/domain/token/duration/get", wrap = "CheckLogin")]
async fn get_duration(
payload: web::Json<MCaptchaDetails>,
data: web::Data<Data>,
id: Identity,
@@ -103,6 +102,24 @@ pub async fn get_duration(
Ok(HttpResponse::Ok().json(duration))
}
pub fn services(cfg: &mut web::ServiceConfig) {
use crate::define_resource;
use crate::V1_API_ROUTES;
define_resource!(
cfg,
V1_API_ROUTES.duration.get,
Methods::ProtectPost,
get_duration
);
define_resource!(
cfg,
V1_API_ROUTES.duration.update,
Methods::ProtectPost,
update_duration
);
}
#[cfg(test)]
mod tests {
use actix_web::http::{header, StatusCode};