Implement all API according to swagger spec #27
|
@ -1 +1,19 @@
|
|||
use warp::{reply::{WithStatus, Json, json}, http::StatusCode};
|
||||
|
||||
use crate::web::state::SharedState;
|
||||
|
||||
use super::types::{ErrorMessage, Error};
|
||||
|
||||
fn check_api_enabled(state: &SharedState) -> Result<(), WithStatus<Json>> {
|
||||
if ! state.config.api.enabled {
|
||||
return Err(
|
||||
warp::reply::with_status(
|
||||
json(&ErrorMessage::new(Error::APIDisabled)),
|
||||
StatusCode::SERVICE_UNAVAILABLE
|
||||
)
|
||||
)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub mod get_all;
|
|
@ -1,19 +1,12 @@
|
|||
use warp::{reply::{Reply, json}, reject::Rejection, Filter, http::StatusCode};
|
||||
use warp::{reply::{Reply, json}, reject::Rejection, Filter};
|
||||
|
||||
use crate::web::{state::SharedState, rejection::HttpReject};
|
||||
|
||||
use super::super::types::{ErrorMessage, Error};
|
||||
use super::check_api_enabled;
|
||||
|
||||
pub async fn get_all(state: SharedState) -> Result<Box<dyn Reply>, Rejection> {
|
||||
if ! state.config.api.enabled {
|
||||
return Ok(
|
||||
Box::new(
|
||||
warp::reply::with_status(
|
||||
json(&ErrorMessage::new(Error::APIDisabled)),
|
||||
StatusCode::SERVICE_UNAVAILABLE
|
||||
)
|
||||
)
|
||||
)
|
||||
if let Err(res) = check_api_enabled(&state) {
|
||||
return Ok(Box::new(res));
|
||||
}
|
||||
|
||||
Ok(
|
||||
|
|
Loading…
Reference in New Issue