2025-06-13 17:47:00 -04:00
|
|
|
use crate::{get_user_from_token, routes::pages::PaginatedQuery, State};
|
|
|
|
use axum::{
|
|
|
|
extract::{Path, Query},
|
|
|
|
response::IntoResponse,
|
|
|
|
Extension, Json,
|
|
|
|
};
|
2025-04-12 22:25:54 -04:00
|
|
|
use axum_extra::extract::CookieJar;
|
2025-06-13 17:47:00 -04:00
|
|
|
use tetratto_core::model::{oauth, ApiReturn, Error};
|
2025-04-12 22:25:54 -04:00
|
|
|
|
|
|
|
pub async fn delete_request(
|
|
|
|
jar: CookieJar,
|
|
|
|
Extension(data): Extension<State>,
|
|
|
|
Path((id, linked_asset)): Path<(usize, usize)>,
|
|
|
|
) -> impl IntoResponse {
|
|
|
|
let data = &(data.read().await).0;
|
2025-06-13 17:47:00 -04:00
|
|
|
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserManageRequests) {
|
2025-04-12 22:25:54 -04:00
|
|
|
Some(ua) => ua,
|
|
|
|
None => return Json(Error::NotAllowed.into()),
|
|
|
|
};
|
|
|
|
|
2025-04-14 17:21:52 -04:00
|
|
|
match data.delete_request(id, linked_asset, &user, false).await {
|
2025-04-12 22:25:54 -04:00
|
|
|
Ok(_) => Json(ApiReturn {
|
|
|
|
ok: true,
|
|
|
|
message: "Request deleted".to_string(),
|
|
|
|
payload: (),
|
|
|
|
}),
|
|
|
|
Err(e) => Json(e.into()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn delete_all_request(
|
|
|
|
jar: CookieJar,
|
|
|
|
Extension(data): Extension<State>,
|
|
|
|
) -> impl IntoResponse {
|
|
|
|
let data = &(data.read().await).0;
|
2025-06-13 17:47:00 -04:00
|
|
|
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserManageRequests) {
|
2025-04-12 22:25:54 -04:00
|
|
|
Some(ua) => ua,
|
|
|
|
None => return Json(Error::NotAllowed.into()),
|
|
|
|
};
|
|
|
|
|
|
|
|
match data.delete_all_requests(&user).await {
|
|
|
|
Ok(_) => Json(ApiReturn {
|
|
|
|
ok: true,
|
|
|
|
message: "Requests cleared".to_string(),
|
|
|
|
payload: (),
|
|
|
|
}),
|
|
|
|
Err(e) => Json(e.into()),
|
|
|
|
}
|
|
|
|
}
|
2025-06-13 17:47:00 -04:00
|
|
|
|
|
|
|
pub async fn get_list_request(
|
|
|
|
jar: CookieJar,
|
|
|
|
Extension(data): Extension<State>,
|
|
|
|
Query(props): Query<PaginatedQuery>,
|
|
|
|
) -> impl IntoResponse {
|
|
|
|
let data = &(data.read().await).0;
|
|
|
|
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserReadRequests) {
|
|
|
|
Some(ua) => ua,
|
|
|
|
None => return Json(Error::NotAllowed.into()),
|
|
|
|
};
|
|
|
|
|
|
|
|
match data
|
|
|
|
.get_requests_by_owner_paginated(user.id, 12, props.page)
|
|
|
|
.await
|
|
|
|
{
|
|
|
|
Ok(l) => Json(ApiReturn {
|
|
|
|
ok: true,
|
|
|
|
message: "Success".to_string(),
|
|
|
|
payload: Some(l),
|
|
|
|
}),
|
|
|
|
Err(e) => Json(e.into()),
|
|
|
|
}
|
|
|
|
}
|