style: cargo fmt

This commit is contained in:
Radical 2025-05-19 15:14:03 +02:00
parent c21762ac7e
commit 78e87b65ce
23 changed files with 555 additions and 276 deletions

View file

@ -1,16 +1,25 @@
use actix_web::{get, web, Error, HttpRequest, HttpResponse};
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, web};
use log::error;
#[get("{uuid}/roles/{role_uuid}")]
pub async fn get(req: HttpRequest, path: web::Path<(Uuid, Uuid)>, data: web::Data<Data>) -> Result<HttpResponse, Error> {
pub async fn get(
req: HttpRequest,
path: web::Path<(Uuid, 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, role_uuid) = path.into_inner();
@ -18,7 +27,7 @@ pub async fn get(req: HttpRequest, path: web::Path<(Uuid, Uuid)>, data: web::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();
@ -32,18 +41,22 @@ pub async fn get(req: HttpRequest, path: web::Path<(Uuid, Uuid)>, data: web::Dat
let cache_result = data.get_cache_key(format!("{}", role_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 role_result = Role::fetch_one(&data.pool, guild_uuid, role_uuid).await;
if let Err(error) = role_result {
return Ok(error)
return Ok(error);
}
let role = role_result.unwrap();
let cache_result = data.set_cache_key(format!("{}", role_uuid), role.clone(), 60).await;
let cache_result = data
.set_cache_key(format!("{}", role_uuid), role.clone(), 60)
.await;
if let Err(error) = cache_result {
error!("{}", error);