Implement all API according to swagger spec #27

Merged
blek merged 16 commits from delete-upload-api-methods into 0.2-dev 2023-12-14 11:56:46 +01:00
3 changed files with 16 additions and 3 deletions
Showing only changes of commit 1aa8a77b78 - Show all commits

View File

@ -16,4 +16,11 @@ fn check_api_enabled(state: &SharedState) -> Result<(), WithStatus<Json>> {
Ok(())
}
fn function_disabled_err() -> WithStatus<Json> {
warp::reply::with_status(
json(&ErrorMessage::new(Error::APIFunctionDisabled)),
StatusCode::SERVICE_UNAVAILABLE
)
}
pub mod get_all;

View File

@ -2,11 +2,15 @@ use warp::{reply::{Reply, json}, reject::Rejection, Filter};
use crate::web::{state::SharedState, rejection::HttpReject};
use super::check_api_enabled;
use super::{check_api_enabled, function_disabled_err};
pub async fn get_all(state: SharedState) -> Result<Box<dyn Reply>, Rejection> {
if let Err(res) = check_api_enabled(&state) {
return Ok(Box::new(res));
return Ok(Box::new(res))
}
if ! state.config.api.get_all {
return Ok(Box::new(function_disabled_err()))
}
Ok(

View File

@ -3,6 +3,7 @@ use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Error {
APIDisabled,
APIFunctionDisabled
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -15,7 +16,8 @@ impl ErrorMessage {
pub fn new(error: Error) -> ErrorMessage {
ErrorMessage {
details: match error {
Error::APIDisabled => Some("API is disabled by the administrator. Please contact them for further details".into())
Error::APIDisabled => Some("API is disabled by the administrator. Please contact them for further details".into()),
Error::APIFunctionDisabled => Some("This API function is disabled by the administrator. Please contact them for further details.".into())
},
error,
}