Moderation + Mod Editing (#101)

* Moderation + Mod Editing WIP

* Run prepare, fix perms

* Make it compile

* Finish moderation and edit routes

* More fixes

* Use better queries

* Final Fixes
This commit is contained in:
Geometrically
2020-11-15 19:58:11 -07:00
committed by GitHub
parent da911bfeb8
commit 0500994def
14 changed files with 1830 additions and 332 deletions

View File

@@ -3,6 +3,7 @@ use actix_web::web;
mod auth;
mod index;
mod mod_creation;
mod moderation;
mod mods;
mod not_found;
mod tags;
@@ -16,6 +17,7 @@ pub use tags::config as tags_config;
pub use self::index::index_get;
pub use self::not_found::not_found;
use crate::file_hosting::FileHostingError;
pub fn mods_config(cfg: &mut web::ServiceConfig) {
cfg.service(mods::mod_search);
@@ -26,6 +28,7 @@ pub fn mods_config(cfg: &mut web::ServiceConfig) {
web::scope("mod")
.service(mods::mod_get)
.service(mods::mod_delete)
.service(mods::mod_edit)
.service(web::scope("{mod_id}").service(versions::version_list)),
);
}
@@ -37,7 +40,13 @@ pub fn versions_config(cfg: &mut web::ServiceConfig) {
web::scope("version")
.service(versions::version_get)
.service(versions::version_delete)
.service(version_creation::upload_file_to_version),
.service(version_creation::upload_file_to_version)
.service(versions::version_edit),
);
cfg.service(
web::scope("version_file")
.service(versions::delete_file)
.service(versions::get_version_from_hash),
);
}
@@ -67,6 +76,8 @@ pub fn teams_config(cfg: &mut web::ServiceConfig) {
#[derive(thiserror::Error, Debug)]
pub enum ApiError {
#[error("Error while uploading file")]
FileHostingError(#[from] FileHostingError),
#[error("Internal server error")]
DatabaseError(#[from] crate::database::models::DatabaseError),
#[error("Deserialization error: {0}")]
@@ -89,6 +100,7 @@ impl actix_web::ResponseError for ApiError {
ApiError::CustomAuthenticationError(..) => actix_web::http::StatusCode::UNAUTHORIZED,
ApiError::JsonError(..) => actix_web::http::StatusCode::BAD_REQUEST,
ApiError::SearchError(..) => actix_web::http::StatusCode::INTERNAL_SERVER_ERROR,
ApiError::FileHostingError(..) => actix_web::http::StatusCode::INTERNAL_SERVER_ERROR,
ApiError::InvalidInputError(..) => actix_web::http::StatusCode::BAD_REQUEST,
}
}
@@ -102,6 +114,7 @@ impl actix_web::ResponseError for ApiError {
ApiError::CustomAuthenticationError(..) => "unauthorized",
ApiError::JsonError(..) => "json_error",
ApiError::SearchError(..) => "search_error",
ApiError::FileHostingError(..) => "file_hosting_error",
ApiError::InvalidInputError(..) => "invalid_input",
},
description: &self.to_string(),