2020-08-12 14:54:03 -05:00
|
|
|
use actix_web::web;
|
|
|
|
|
|
2020-09-26 22:49:16 -07:00
|
|
|
mod auth;
|
2020-05-14 22:53:22 -07:00
|
|
|
mod index;
|
2020-07-16 10:16:35 -07:00
|
|
|
mod mod_creation;
|
2020-06-30 19:23:52 +02:00
|
|
|
mod mods;
|
|
|
|
|
mod not_found;
|
2020-08-12 14:54:03 -05:00
|
|
|
mod tags;
|
2020-09-28 22:30:13 -07:00
|
|
|
mod users;
|
2020-08-12 11:05:49 -07:00
|
|
|
mod version_creation;
|
2020-08-12 14:54:03 -05:00
|
|
|
mod versions;
|
|
|
|
|
|
2020-09-26 22:49:16 -07:00
|
|
|
pub use auth::config as auth_config;
|
2020-09-28 21:05:42 -07:00
|
|
|
pub use tags::config as tags_config;
|
2020-05-14 22:53:22 -07:00
|
|
|
|
2020-05-27 20:51:28 +02:00
|
|
|
pub use self::index::index_get;
|
2020-06-30 19:23:52 +02:00
|
|
|
pub use self::not_found::not_found;
|
2020-08-12 14:54:03 -05:00
|
|
|
|
|
|
|
|
pub fn mods_config(cfg: &mut web::ServiceConfig) {
|
|
|
|
|
cfg.service(mods::mod_search);
|
|
|
|
|
cfg.service(mod_creation::mod_create);
|
|
|
|
|
|
|
|
|
|
cfg.service(
|
|
|
|
|
web::scope("mod")
|
|
|
|
|
.service(mods::mod_get)
|
|
|
|
|
.service(mods::mod_delete)
|
|
|
|
|
.service(web::scope("{mod_id}").configure(versions_config)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn versions_config(cfg: &mut web::ServiceConfig) {
|
|
|
|
|
cfg.service(versions::version_list)
|
|
|
|
|
.service(version_creation::version_create)
|
|
|
|
|
.service(
|
|
|
|
|
web::scope("version")
|
|
|
|
|
.service(versions::version_get)
|
|
|
|
|
.service(versions::version_delete)
|
2020-10-01 00:07:52 -05:00
|
|
|
.service(version_creation::upload_file_to_version),
|
2020-08-12 14:54:03 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 22:30:13 -07:00
|
|
|
pub fn users_config(cfg: &mut web::ServiceConfig) {
|
|
|
|
|
cfg.service(users::user_auth_get);
|
|
|
|
|
|
|
|
|
|
cfg.service(
|
|
|
|
|
web::scope("user")
|
|
|
|
|
.service(users::user_get)
|
|
|
|
|
.service(users::user_delete),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-12 14:54:03 -05:00
|
|
|
#[derive(thiserror::Error, Debug)]
|
|
|
|
|
pub enum ApiError {
|
|
|
|
|
#[error("Internal server error")]
|
|
|
|
|
DatabaseError(#[from] crate::database::models::DatabaseError),
|
2020-09-28 21:05:42 -07:00
|
|
|
#[error("Authentication Error")]
|
|
|
|
|
AuthenticationError,
|
2020-08-12 14:54:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl actix_web::ResponseError for ApiError {
|
|
|
|
|
fn status_code(&self) -> actix_web::http::StatusCode {
|
|
|
|
|
match self {
|
|
|
|
|
ApiError::DatabaseError(..) => actix_web::http::StatusCode::INTERNAL_SERVER_ERROR,
|
2020-09-28 21:05:42 -07:00
|
|
|
ApiError::AuthenticationError => actix_web::http::StatusCode::UNAUTHORIZED,
|
2020-08-12 14:54:03 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn error_response(&self) -> actix_web::web::HttpResponse {
|
|
|
|
|
actix_web::web::HttpResponse::build(self.status_code()).json(
|
|
|
|
|
crate::models::error::ApiError {
|
|
|
|
|
error: match self {
|
|
|
|
|
ApiError::DatabaseError(..) => "database_error",
|
2020-09-28 21:05:42 -07:00
|
|
|
ApiError::AuthenticationError => "unauthorized",
|
2020-08-12 14:54:03 -05:00
|
|
|
},
|
|
|
|
|
description: &self.to_string(),
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|