2023-05-26 15:55:19 +00:00
|
|
|
//! # API controller
|
|
|
|
|
|
|
|
use actix_web::body::BoxBody;
|
|
|
|
use actix_web::HttpResponse;
|
|
|
|
use std::fmt::{Debug, Display, Formatter};
|
2023-08-17 15:37:44 +00:00
|
|
|
use zip::result::ZipError;
|
2023-05-26 15:55:19 +00:00
|
|
|
|
|
|
|
pub mod auth_controller;
|
2023-08-07 14:50:22 +00:00
|
|
|
pub mod couples_controller;
|
2023-08-17 15:37:44 +00:00
|
|
|
pub mod data_controller;
|
2023-06-16 15:51:51 +00:00
|
|
|
pub mod families_controller;
|
2023-08-04 17:03:46 +00:00
|
|
|
pub mod members_controller;
|
2023-08-07 12:53:44 +00:00
|
|
|
pub mod photos_controller;
|
2023-06-01 15:01:57 +00:00
|
|
|
pub mod server_controller;
|
2023-06-16 15:51:51 +00:00
|
|
|
pub mod users_controller;
|
2023-05-26 15:55:19 +00:00
|
|
|
|
|
|
|
/// Custom error to ease controller writing
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct HttpErr {
|
|
|
|
err: anyhow::Error,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for HttpErr {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
std::fmt::Display::fmt(&self.err, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl actix_web::error::ResponseError for HttpErr {
|
|
|
|
fn error_response(&self) -> HttpResponse<BoxBody> {
|
|
|
|
log::error!("Error while processing request! {}", self);
|
|
|
|
HttpResponse::InternalServerError().body("Failed to execute request!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<anyhow::Error> for HttpErr {
|
|
|
|
fn from(err: anyhow::Error) -> HttpErr {
|
|
|
|
HttpErr { err }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-17 15:37:44 +00:00
|
|
|
impl From<ZipError> for HttpErr {
|
|
|
|
fn from(value: ZipError) -> Self {
|
|
|
|
HttpErr { err: value.into() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<serde_json::Error> for HttpErr {
|
|
|
|
fn from(value: serde_json::Error) -> Self {
|
|
|
|
HttpErr { err: value.into() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::io::Error> for HttpErr {
|
|
|
|
fn from(value: std::io::Error) -> Self {
|
|
|
|
HttpErr { err: value.into() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-18 11:41:20 +00:00
|
|
|
impl From<std::num::ParseIntError> for HttpErr {
|
|
|
|
fn from(value: std::num::ParseIntError) -> Self {
|
|
|
|
HttpErr { err: value.into() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-26 15:55:19 +00:00
|
|
|
pub type HttpResult = Result<HttpResponse, HttpErr>;
|