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,25 +1,34 @@
use actix_web::{get, post, web, Error, HttpRequest, HttpResponse};
use serde::Deserialize;
use crate::{api::v1::auth::check_access_token, structs::{Channel, Member}, utils::get_auth_header, Data};
use crate::{
Data,
api::v1::auth::check_access_token,
structs::{Channel, Member},
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;
#[derive(Deserialize)]
struct ChannelInfo {
name: String,
description: Option<String>
description: Option<String>,
}
#[get("{uuid}/channels")]
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;
@ -27,7 +36,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();
@ -41,18 +50,22 @@ pub async fn get(req: HttpRequest, path: web::Path<(Uuid,)>, data: web::Data<Dat
let cache_result = data.get_cache_key(format!("{}_channels", 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 channels_result = Channel::fetch_all(&data.pool, guild_uuid).await;
if let Err(error) = channels_result {
return Ok(error)
return Ok(error);
}
let channels = channels_result.unwrap();
let cache_result = data.set_cache_key(format!("{}_channels", guild_uuid), channels.clone(), 1800).await;
let cache_result = data
.set_cache_key(format!("{}_channels", guild_uuid), channels.clone(), 1800)
.await;
if let Err(error) = cache_result {
error!("{}", error);
@ -63,13 +76,18 @@ pub async fn get(req: HttpRequest, path: web::Path<(Uuid,)>, data: web::Data<Dat
}
#[post("{uuid}/channels")]
pub async fn create(req: HttpRequest, channel_info: web::Json<ChannelInfo>, path: web::Path<(Uuid,)>, data: web::Data<Data>) -> Result<HttpResponse, Error> {
pub async fn create(
req: HttpRequest,
channel_info: web::Json<ChannelInfo>,
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;
@ -77,7 +95,7 @@ pub async fn create(req: HttpRequest, channel_info: web::Json<ChannelInfo>, path
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();
@ -90,7 +108,13 @@ pub async fn create(req: HttpRequest, channel_info: web::Json<ChannelInfo>, path
// FIXME: Logic to check permissions, should probably be done in utils.rs
let channel = Channel::new(data.clone(), guild_uuid, channel_info.name.clone(), channel_info.description.clone()).await;
let channel = Channel::new(
data.clone(),
guild_uuid,
channel_info.name.clone(),
channel_info.description.clone(),
)
.await;
if let Err(error) = channel {
return Ok(error);