style: cargo fmt
This commit is contained in:
parent
c21762ac7e
commit
78e87b65ce
23 changed files with 555 additions and 276 deletions
|
@ -1,8 +1,13 @@
|
|||
use actix_web::{get, post, web, Error, HttpRequest, HttpResponse};
|
||||
use serde::Deserialize;
|
||||
use crate::{api::v1::auth::check_access_token, structs::{Member, Role}, utils::get_auth_header, Data};
|
||||
use crate::{
|
||||
Data,
|
||||
api::v1::auth::check_access_token,
|
||||
structs::{Member, Role},
|
||||
utils::get_auth_header,
|
||||
};
|
||||
use ::uuid::Uuid;
|
||||
use actix_web::{Error, HttpRequest, HttpResponse, get, post, web};
|
||||
use log::error;
|
||||
use serde::Deserialize;
|
||||
|
||||
pub mod uuid;
|
||||
|
||||
|
@ -12,13 +17,17 @@ struct RoleInfo {
|
|||
}
|
||||
|
||||
#[get("{uuid}/roles")]
|
||||
pub async fn get(req: HttpRequest, path: web::Path<(Uuid,)>, data: web::Data<Data>) -> Result<HttpResponse, Error> {
|
||||
pub async fn get(
|
||||
req: HttpRequest,
|
||||
path: web::Path<(Uuid,)>,
|
||||
data: web::Data<Data>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let headers = req.headers();
|
||||
|
||||
let auth_header = get_auth_header(headers);
|
||||
|
||||
if let Err(error) = auth_header {
|
||||
return Ok(error)
|
||||
return Ok(error);
|
||||
}
|
||||
|
||||
let guild_uuid = path.into_inner().0;
|
||||
|
@ -26,7 +35,7 @@ pub async fn get(req: HttpRequest, path: web::Path<(Uuid,)>, data: web::Data<Dat
|
|||
let authorized = check_access_token(auth_header.unwrap(), &data.pool).await;
|
||||
|
||||
if let Err(error) = authorized {
|
||||
return Ok(error)
|
||||
return Ok(error);
|
||||
}
|
||||
|
||||
let uuid = authorized.unwrap();
|
||||
|
@ -40,18 +49,22 @@ pub async fn get(req: HttpRequest, path: web::Path<(Uuid,)>, data: web::Data<Dat
|
|||
let cache_result = data.get_cache_key(format!("{}_roles", guild_uuid)).await;
|
||||
|
||||
if let Ok(cache_hit) = cache_result {
|
||||
return Ok(HttpResponse::Ok().content_type("application/json").body(cache_hit))
|
||||
return Ok(HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(cache_hit));
|
||||
}
|
||||
|
||||
let roles_result = Role::fetch_all(&data.pool, guild_uuid).await;
|
||||
|
||||
if let Err(error) = roles_result {
|
||||
return Ok(error)
|
||||
return Ok(error);
|
||||
}
|
||||
|
||||
let roles = roles_result.unwrap();
|
||||
|
||||
let cache_result = data.set_cache_key(format!("{}_roles", guild_uuid), roles.clone(), 1800).await;
|
||||
let cache_result = data
|
||||
.set_cache_key(format!("{}_roles", guild_uuid), roles.clone(), 1800)
|
||||
.await;
|
||||
|
||||
if let Err(error) = cache_result {
|
||||
error!("{}", error);
|
||||
|
@ -62,13 +75,18 @@ pub async fn get(req: HttpRequest, path: web::Path<(Uuid,)>, data: web::Data<Dat
|
|||
}
|
||||
|
||||
#[post("{uuid}/roles")]
|
||||
pub async fn create(req: HttpRequest, role_info: web::Json<RoleInfo>, path: web::Path<(Uuid,)>, data: web::Data<Data>) -> Result<HttpResponse, Error> {
|
||||
pub async fn create(
|
||||
req: HttpRequest,
|
||||
role_info: web::Json<RoleInfo>,
|
||||
path: web::Path<(Uuid,)>,
|
||||
data: web::Data<Data>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let headers = req.headers();
|
||||
|
||||
let auth_header = get_auth_header(headers);
|
||||
|
||||
if let Err(error) = auth_header {
|
||||
return Ok(error)
|
||||
return Ok(error);
|
||||
}
|
||||
|
||||
let guild_uuid = path.into_inner().0;
|
||||
|
@ -76,7 +94,7 @@ pub async fn create(req: HttpRequest, role_info: web::Json<RoleInfo>, path: web:
|
|||
let authorized = check_access_token(auth_header.unwrap(), &data.pool).await;
|
||||
|
||||
if let Err(error) = authorized {
|
||||
return Ok(error)
|
||||
return Ok(error);
|
||||
}
|
||||
|
||||
let uuid = authorized.unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue