Merge branch 'main' into wip/images
This commit is contained in:
commit
149b81973d
54 changed files with 1201 additions and 1691 deletions
|
@ -1,8 +1,8 @@
|
|||
use actix_web::{Error, HttpRequest, HttpResponse, get, web};
|
||||
use log::error;
|
||||
use actix_web::{HttpRequest, HttpResponse, get, web};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{api::v1::auth::check_access_token, structs::User, utils::get_auth_header, Data};
|
||||
use crate::{error::Error, api::v1::auth::check_access_token, structs::User, utils::get_auth_header, Data};
|
||||
|
||||
|
||||
#[get("/{uuid}")]
|
||||
pub async fn res(
|
||||
|
@ -14,42 +14,23 @@ pub async fn res(
|
|||
|
||||
let uuid = path.into_inner().0;
|
||||
|
||||
let auth_header = get_auth_header(headers);
|
||||
let auth_header = get_auth_header(headers)?;
|
||||
|
||||
if let Err(error) = auth_header {
|
||||
return Ok(error);
|
||||
}
|
||||
let mut conn = data.pool.get().await?;
|
||||
|
||||
let authorized = check_access_token(auth_header.unwrap(), &data.pool).await;
|
||||
check_access_token(auth_header, &mut conn).await?;
|
||||
|
||||
if let Err(error) = authorized {
|
||||
return Ok(error);
|
||||
}
|
||||
|
||||
let cache_result = data.get_cache_key(uuid.to_string()).await;
|
||||
|
||||
if let Ok(cache_hit) = cache_result {
|
||||
if let Ok(cache_hit) = data.get_cache_key(uuid.to_string()).await {
|
||||
return Ok(HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(cache_hit));
|
||||
}
|
||||
|
||||
let user_result = User::fetch_one(&data.pool, uuid).await;
|
||||
let user = User::fetch_one(&mut conn, uuid).await?;
|
||||
|
||||
if let Err(error) = user_result {
|
||||
return Ok(error);
|
||||
}
|
||||
|
||||
let user = user_result.unwrap();
|
||||
|
||||
let cache_result = data
|
||||
data
|
||||
.set_cache_key(uuid.to_string(), user.clone(), 1800)
|
||||
.await;
|
||||
|
||||
if let Err(error) = cache_result {
|
||||
error!("{}", error);
|
||||
return Ok(HttpResponse::InternalServerError().finish());
|
||||
}
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(user))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue