From 118d6a5d0ea76f0fe893577d72128777972207ef Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Tue, 6 Feb 2024 12:46:00 +0000 Subject: [PATCH] refactor: [#453] reorganize web mod Added `server` subfolder. We will add a client folder. --- src/app.rs | 2 +- src/common.rs | 2 +- src/lib.rs | 4 ++-- src/mailer.rs | 2 +- src/services/about.rs | 2 +- src/services/user.rs | 2 +- src/web/api/mod.rs | 1 - src/web/api/{server.rs => server/mod.rs} | 8 +++++--- src/web/api/{ => server}/v1/auth.rs | 2 +- .../v1/contexts/about/handlers.rs | 2 +- .../api/{ => server}/v1/contexts/about/mod.rs | 0 .../{ => server}/v1/contexts/about/routes.rs | 6 +++--- .../v1/contexts/category/forms.rs | 0 .../v1/contexts/category/handlers.rs | 8 ++++---- .../{ => server}/v1/contexts/category/mod.rs | 0 .../v1/contexts/category/responses.rs | 4 ++-- .../v1/contexts/category/routes.rs | 6 +++--- src/web/api/server/v1/contexts/mod.rs | 19 +++++++++++++++++++ .../v1/contexts/proxy/handlers.rs | 4 ++-- .../api/{ => server}/v1/contexts/proxy/mod.rs | 0 .../v1/contexts/proxy/responses.rs | 0 .../{ => server}/v1/contexts/proxy/routes.rs | 6 +++--- .../v1/contexts/settings/handlers.rs | 6 +++--- .../{ => server}/v1/contexts/settings/mod.rs | 0 .../v1/contexts/settings/routes.rs | 6 +++--- .../api/{ => server}/v1/contexts/tag/forms.rs | 2 +- .../{ => server}/v1/contexts/tag/handlers.rs | 8 ++++---- .../api/{ => server}/v1/contexts/tag/mod.rs | 0 .../{ => server}/v1/contexts/tag/responses.rs | 4 ++-- .../{ => server}/v1/contexts/tag/routes.rs | 8 ++++---- .../v1/contexts/torrent/errors.rs | 2 +- .../{ => server}/v1/contexts/torrent/forms.rs | 0 .../v1/contexts/torrent/handlers.rs | 10 +++++----- .../{ => server}/v1/contexts/torrent/mod.rs | 2 +- .../v1/contexts/torrent/responses.rs | 2 +- .../v1/contexts/torrent/routes.rs | 8 ++++---- .../{ => server}/v1/contexts/user/forms.rs | 0 .../{ => server}/v1/contexts/user/handlers.rs | 6 +++--- .../api/{ => server}/v1/contexts/user/mod.rs | 14 +++++++------- .../v1/contexts/user/responses.rs | 2 +- .../{ => server}/v1/contexts/user/routes.rs | 6 +++--- .../v1/extractors/bearer_token.rs | 2 +- src/web/api/{ => server}/v1/extractors/mod.rs | 0 src/web/api/{ => server}/v1/mod.rs | 0 src/web/api/{ => server}/v1/responses.rs | 0 src/web/api/{ => server}/v1/routes.rs | 0 src/web/api/v1/contexts/mod.rs | 19 ------------------- src/web/mod.rs | 2 +- tests/common/asserts.rs | 2 +- .../e2e/web/api/v1/contexts/torrent/steps.rs | 2 +- 50 files changed, 97 insertions(+), 96 deletions(-) rename src/web/api/{server.rs => server/mod.rs} (93%) rename src/web/api/{ => server}/v1/auth.rs (98%) rename src/web/api/{ => server}/v1/contexts/about/handlers.rs (89%) rename src/web/api/{ => server}/v1/contexts/about/mod.rs (100%) rename src/web/api/{ => server}/v1/contexts/about/routes.rs (58%) rename src/web/api/{ => server}/v1/contexts/category/forms.rs (100%) rename src/web/api/{ => server}/v1/contexts/category/handlers.rs (90%) rename src/web/api/{ => server}/v1/contexts/category/mod.rs (100%) rename src/web/api/{ => server}/v1/contexts/category/responses.rs (74%) rename src/web/api/{ => server}/v1/contexts/category/routes.rs (61%) create mode 100644 src/web/api/server/v1/contexts/mod.rs rename src/web/api/{ => server}/v1/contexts/proxy/handlers.rs (91%) rename src/web/api/{ => server}/v1/contexts/proxy/mod.rs (100%) rename src/web/api/{ => server}/v1/contexts/proxy/responses.rs (100%) rename src/web/api/{ => server}/v1/contexts/proxy/routes.rs (51%) rename src/web/api/{ => server}/v1/contexts/settings/handlers.rs (87%) rename src/web/api/{ => server}/v1/contexts/settings/mod.rs (100%) rename src/web/api/{ => server}/v1/contexts/settings/routes.rs (62%) rename src/web/api/{ => server}/v1/contexts/tag/forms.rs (76%) rename src/web/api/{ => server}/v1/contexts/tag/handlers.rs (89%) rename src/web/api/{ => server}/v1/contexts/tag/mod.rs (100%) rename src/web/api/{ => server}/v1/contexts/tag/responses.rs (74%) rename src/web/api/{ => server}/v1/contexts/tag/routes.rs (64%) rename src/web/api/{ => server}/v1/contexts/torrent/errors.rs (96%) rename src/web/api/{ => server}/v1/contexts/torrent/forms.rs (100%) rename src/web/api/{ => server}/v1/contexts/torrent/handlers.rs (97%) rename src/web/api/{ => server}/v1/contexts/torrent/mod.rs (99%) rename src/web/api/{ => server}/v1/contexts/torrent/responses.rs (96%) rename src/web/api/{ => server}/v1/contexts/torrent/routes.rs (75%) rename src/web/api/{ => server}/v1/contexts/user/forms.rs (100%) rename src/web/api/{ => server}/v1/contexts/user/handlers.rs (95%) rename src/web/api/{ => server}/v1/contexts/user/mod.rs (93%) rename src/web/api/{ => server}/v1/contexts/user/responses.rs (95%) rename src/web/api/{ => server}/v1/contexts/user/routes.rs (83%) rename src/web/api/{ => server}/v1/extractors/bearer_token.rs (93%) rename src/web/api/{ => server}/v1/extractors/mod.rs (100%) rename src/web/api/{ => server}/v1/mod.rs (100%) rename src/web/api/{ => server}/v1/responses.rs (100%) rename src/web/api/{ => server}/v1/routes.rs (100%) delete mode 100644 src/web/api/v1/contexts/mod.rs diff --git a/src/app.rs b/src/app.rs index 7fd825df..bb71d5dc 100644 --- a/src/app.rs +++ b/src/app.rs @@ -18,7 +18,7 @@ use crate::services::torrent::{ use crate::services::user::{self, DbBannedUserList, DbUserProfileRepository, DbUserRepository}; use crate::services::{proxy, settings, torrent}; use crate::tracker::statistics_importer::StatisticsImporter; -use crate::web::api::v1::auth::Authentication; +use crate::web::api::server::v1::auth::Authentication; use crate::web::api::Version; use crate::{console, mailer, tracker, web}; diff --git a/src/common.rs b/src/common.rs index bf16889a..755a775b 100644 --- a/src/common.rs +++ b/src/common.rs @@ -13,7 +13,7 @@ use crate::services::torrent::{ use crate::services::user::{self, DbBannedUserList, DbUserProfileRepository, DbUserRepository}; use crate::services::{proxy, settings, torrent}; use crate::tracker::statistics_importer::StatisticsImporter; -use crate::web::api::v1::auth::Authentication; +use crate::web::api::server::v1::auth::Authentication; use crate::{mailer, tracker}; pub type Username = String; diff --git a/src/lib.rs b/src/lib.rs index ba89003c..45e6ad24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ //! used with by the [Torrust Tracker Index Gui](https://github.com/torrust/torrust-index-gui). //! //! If you are looking for information on how to use the API, please see the -//! [API v1](crate::web::api::v1) section of the documentation. +//! [API v1](crate::web::api::server::v1) section of the documentation. //! //! # Table of contents //! @@ -37,7 +37,7 @@ //! //! From the end-user perspective the Torrust Tracker exposes three different services. //! -//! - A REST [API](crate::web::api::v1) +//! - A REST [API](crate::web::api::server::v1) //! //! From the administrator perspective, the Torrust Index exposes: //! diff --git a/src/mailer.rs b/src/mailer.rs index 0c48acd6..39c1d0d4 100644 --- a/src/mailer.rs +++ b/src/mailer.rs @@ -13,7 +13,7 @@ use tera::{try_get_value, Context, Tera}; use crate::config::Configuration; use crate::errors::ServiceError; use crate::utils::clock; -use crate::web::api::v1::routes::API_VERSION_URL_PREFIX; +use crate::web::api::server::v1::routes::API_VERSION_URL_PREFIX; lazy_static! { pub static ref TEMPLATES: Tera = { diff --git a/src/services/about.rs b/src/services/about.rs index 82175bf6..28eedc02 100644 --- a/src/services/about.rs +++ b/src/services/about.rs @@ -1,5 +1,5 @@ //! Templates for "about" static pages. -use crate::web::api::v1::routes::API_VERSION_URL_PREFIX; +use crate::web::api::server::v1::routes::API_VERSION_URL_PREFIX; #[must_use] pub fn index_page() -> String { diff --git a/src/services/user.rs b/src/services/user.rs index 358e7431..cd4e5937 100644 --- a/src/services/user.rs +++ b/src/services/user.rs @@ -14,7 +14,7 @@ use crate::mailer; use crate::mailer::VerifyClaims; use crate::models::user::{UserCompact, UserId, UserProfile}; use crate::utils::validation::validate_email_address; -use crate::web::api::v1::contexts::user::forms::RegistrationForm; +use crate::web::api::server::v1::contexts::user::forms::RegistrationForm; /// Since user email could be optional, we need a way to represent "no email" /// in the database. This function returns the string that should be used for diff --git a/src/web/api/mod.rs b/src/web/api/mod.rs index 749008f1..a9789a7f 100644 --- a/src/web/api/mod.rs +++ b/src/web/api/mod.rs @@ -4,7 +4,6 @@ //! //! Refer to the [`v1`]) module for more information. pub mod server; -pub mod v1; use std::net::SocketAddr; use std::sync::Arc; diff --git a/src/web/api/server.rs b/src/web/api/server/mod.rs similarity index 93% rename from src/web/api/server.rs rename to src/web/api/server/mod.rs index 8fa1e704..a9756c68 100644 --- a/src/web/api/server.rs +++ b/src/web/api/server/mod.rs @@ -1,3 +1,5 @@ +pub mod v1; + use std::net::SocketAddr; use std::sync::Arc; @@ -5,9 +7,9 @@ use futures::Future; use log::info; use tokio::sync::oneshot::{self, Sender}; -use super::v1::routes::router; use super::{Running, ServerStartedMessage}; use crate::common::AppData; +use v1::routes::router; /// Starts the API server. /// @@ -57,7 +59,7 @@ fn start_server( .local_addr() .expect("tcp listener to be bound to a socket address."); - info!("API server listening on http://{}", bound_addr); + info!("API server listening on http://{}", bound_addr); // # DevSkim: ignore DS137138 let app = router(app_data); @@ -70,6 +72,6 @@ fn start_server( server.with_graceful_shutdown(async move { tokio::signal::ctrl_c().await.expect("Failed to listen to shutdown signal."); - info!("Stopping API server on http://{} ...", bound_addr); + info!("Stopping API server on http://{} ...", bound_addr); // # DevSkim: ignore DS137138 }) } diff --git a/src/web/api/v1/auth.rs b/src/web/api/server/v1/auth.rs similarity index 98% rename from src/web/api/v1/auth.rs rename to src/web/api/server/v1/auth.rs index e52542cc..3e355b30 100644 --- a/src/web/api/v1/auth.rs +++ b/src/web/api/server/v1/auth.rs @@ -86,7 +86,7 @@ use crate::common::AppData; use crate::errors::ServiceError; use crate::models::user::{UserClaims, UserCompact, UserId}; use crate::services::authentication::JsonWebToken; -use crate::web::api::v1::extractors::bearer_token::BearerToken; +use crate::web::api::server::v1::extractors::bearer_token::BearerToken; pub struct Authentication { json_web_token: Arc, diff --git a/src/web/api/v1/contexts/about/handlers.rs b/src/web/api/server/v1/contexts/about/handlers.rs similarity index 89% rename from src/web/api/v1/contexts/about/handlers.rs rename to src/web/api/server/v1/contexts/about/handlers.rs index 07d5977b..76004133 100644 --- a/src/web/api/v1/contexts/about/handlers.rs +++ b/src/web/api/server/v1/contexts/about/handlers.rs @@ -1,4 +1,4 @@ -//! API handlers for the the [`about`](crate::web::api::v1::contexts::about) API +//! API handlers for the the [`about`](crate::web::api::server::v1::contexts::about) API //! context. use std::sync::Arc; diff --git a/src/web/api/v1/contexts/about/mod.rs b/src/web/api/server/v1/contexts/about/mod.rs similarity index 100% rename from src/web/api/v1/contexts/about/mod.rs rename to src/web/api/server/v1/contexts/about/mod.rs diff --git a/src/web/api/v1/contexts/about/routes.rs b/src/web/api/server/v1/contexts/about/routes.rs similarity index 58% rename from src/web/api/v1/contexts/about/routes.rs rename to src/web/api/server/v1/contexts/about/routes.rs index d3877a3b..8a9ccef7 100644 --- a/src/web/api/v1/contexts/about/routes.rs +++ b/src/web/api/server/v1/contexts/about/routes.rs @@ -1,6 +1,6 @@ -//! API routes for the [`about`](crate::web::api::v1::contexts::about) API context. +//! API routes for the [`about`](crate::web::api::server::v1::contexts::about) API context. //! -//! Refer to the [API endpoint documentation](crate::web::api::v1::contexts::about). +//! Refer to the [API endpoint documentation](crate::web::api::server::v1::contexts::about). use std::sync::Arc; use axum::routing::get; @@ -9,7 +9,7 @@ use axum::Router; use super::handlers::{about_page_handler, license_page_handler}; use crate::common::AppData; -/// Routes for the [`about`](crate::web::api::v1::contexts::about) API context. +/// Routes for the [`about`](crate::web::api::server::v1::contexts::about) API context. pub fn router(app_data: Arc) -> Router { Router::new() .route("/", get(about_page_handler).with_state(app_data.clone())) diff --git a/src/web/api/v1/contexts/category/forms.rs b/src/web/api/server/v1/contexts/category/forms.rs similarity index 100% rename from src/web/api/v1/contexts/category/forms.rs rename to src/web/api/server/v1/contexts/category/forms.rs diff --git a/src/web/api/v1/contexts/category/handlers.rs b/src/web/api/server/v1/contexts/category/handlers.rs similarity index 90% rename from src/web/api/v1/contexts/category/handlers.rs rename to src/web/api/server/v1/contexts/category/handlers.rs index da0c1209..b73b15c5 100644 --- a/src/web/api/v1/contexts/category/handlers.rs +++ b/src/web/api/server/v1/contexts/category/handlers.rs @@ -1,4 +1,4 @@ -//! API handlers for the the [`category`](crate::web::api::v1::contexts::category) API +//! API handlers for the the [`category`](crate::web::api::server::v1::contexts::category) API //! context. use std::sync::Arc; @@ -8,8 +8,8 @@ use axum::response::{IntoResponse, Json, Response}; use super::forms::{AddCategoryForm, DeleteCategoryForm}; use super::responses::{added_category, deleted_category}; use crate::common::AppData; -use crate::web::api::v1::extractors::bearer_token::Extract; -use crate::web::api::v1::responses::{self}; +use crate::web::api::server::v1::extractors::bearer_token::Extract; +use crate::web::api::server::v1::responses::{self}; /// It handles the request to get all the categories. /// @@ -18,7 +18,7 @@ use crate::web::api::v1::responses::{self}; /// - `200` response with a json containing the category list [`Vec`](crate::databases::database::Category). /// - Other error status codes if there is a database error. /// -/// Refer to the [API endpoint documentation](crate::web::api::v1::contexts::category) +/// Refer to the [API endpoint documentation](crate::web::api::server::v1::contexts::category) /// for more information about this endpoint. /// /// # Errors diff --git a/src/web/api/v1/contexts/category/mod.rs b/src/web/api/server/v1/contexts/category/mod.rs similarity index 100% rename from src/web/api/v1/contexts/category/mod.rs rename to src/web/api/server/v1/contexts/category/mod.rs diff --git a/src/web/api/v1/contexts/category/responses.rs b/src/web/api/server/v1/contexts/category/responses.rs similarity index 74% rename from src/web/api/v1/contexts/category/responses.rs rename to src/web/api/server/v1/contexts/category/responses.rs index b1e20d19..2f761d2c 100644 --- a/src/web/api/v1/contexts/category/responses.rs +++ b/src/web/api/server/v1/contexts/category/responses.rs @@ -1,8 +1,8 @@ -//! API responses for the the [`category`](crate::web::api::v1::contexts::category) API +//! API responses for the the [`category`](crate::web::api::server::v1::contexts::category) API //! context. use axum::Json; -use crate::web::api::v1::responses::OkResponseData; +use crate::web::api::server::v1::responses::OkResponseData; /// Response after successfully creating a new category. pub fn added_category(category_name: &str) -> Json> { diff --git a/src/web/api/v1/contexts/category/routes.rs b/src/web/api/server/v1/contexts/category/routes.rs similarity index 61% rename from src/web/api/v1/contexts/category/routes.rs rename to src/web/api/server/v1/contexts/category/routes.rs index 2d762c47..df8e728d 100644 --- a/src/web/api/v1/contexts/category/routes.rs +++ b/src/web/api/server/v1/contexts/category/routes.rs @@ -1,6 +1,6 @@ -//! API routes for the [`category`](crate::web::api::v1::contexts::category) API context. +//! API routes for the [`category`](crate::web::api::server::v1::contexts::category) API context. //! -//! Refer to the [API endpoint documentation](crate::web::api::v1::contexts::category). +//! Refer to the [API endpoint documentation](crate::web::api::server::v1::contexts::category). use std::sync::Arc; use axum::routing::{delete, get, post}; @@ -9,7 +9,7 @@ use axum::Router; use super::handlers::{add_handler, delete_handler, get_all_handler}; use crate::common::AppData; -/// Routes for the [`category`](crate::web::api::v1::contexts::category) API context. +/// Routes for the [`category`](crate::web::api::server::v1::contexts::category) API context. pub fn router(app_data: Arc) -> Router { Router::new() .route("/", get(get_all_handler).with_state(app_data.clone())) diff --git a/src/web/api/server/v1/contexts/mod.rs b/src/web/api/server/v1/contexts/mod.rs new file mode 100644 index 00000000..a39cbf4e --- /dev/null +++ b/src/web/api/server/v1/contexts/mod.rs @@ -0,0 +1,19 @@ +//! The API is organized in the following contexts: +//! +//! Context | Description | Version +//! ---|---|--- +//! `About` | Metadata about the API | [`v1`](crate::web::api::server::v1::contexts::about) +//! `Category` | Torrent categories | [`v1`](crate::web::api::server::v1::contexts::category) +//! `Proxy` | Image proxy cache | [`v1`](crate::web::api::server::v1::contexts::proxy) +//! `Settings` | Index settings | [`v1`](crate::web::api::server::v1::contexts::settings) +//! `Tag` | Torrent tags | [`v1`](crate::web::api::server::v1::contexts::tag) +//! `Torrent` | Indexed torrents | [`v1`](crate::web::api::server::v1::contexts::torrent) +//! `User` | Users | [`v1`](crate::web::api::server::v1::contexts::user) +//! +pub mod about; +pub mod category; +pub mod proxy; +pub mod settings; +pub mod tag; +pub mod torrent; +pub mod user; diff --git a/src/web/api/v1/contexts/proxy/handlers.rs b/src/web/api/server/v1/contexts/proxy/handlers.rs similarity index 91% rename from src/web/api/v1/contexts/proxy/handlers.rs rename to src/web/api/server/v1/contexts/proxy/handlers.rs index 1e5105ee..7c04e50f 100644 --- a/src/web/api/v1/contexts/proxy/handlers.rs +++ b/src/web/api/server/v1/contexts/proxy/handlers.rs @@ -1,4 +1,4 @@ -//! API handlers for the the [`proxy`](crate::web::api::v1::contexts::proxy) API +//! API handlers for the the [`proxy`](crate::web::api::server::v1::contexts::proxy) API //! context. use std::sync::Arc; @@ -9,7 +9,7 @@ use super::responses::png_image; use crate::cache::image::manager::Error; use crate::common::AppData; use crate::ui::proxy::map_error_to_image; -use crate::web::api::v1::extractors::bearer_token::Extract; +use crate::web::api::server::v1::extractors::bearer_token::Extract; /// Get the remote image. It uses the cached image if available. #[allow(clippy::unused_async)] diff --git a/src/web/api/v1/contexts/proxy/mod.rs b/src/web/api/server/v1/contexts/proxy/mod.rs similarity index 100% rename from src/web/api/v1/contexts/proxy/mod.rs rename to src/web/api/server/v1/contexts/proxy/mod.rs diff --git a/src/web/api/v1/contexts/proxy/responses.rs b/src/web/api/server/v1/contexts/proxy/responses.rs similarity index 100% rename from src/web/api/v1/contexts/proxy/responses.rs rename to src/web/api/server/v1/contexts/proxy/responses.rs diff --git a/src/web/api/v1/contexts/proxy/routes.rs b/src/web/api/server/v1/contexts/proxy/routes.rs similarity index 51% rename from src/web/api/v1/contexts/proxy/routes.rs rename to src/web/api/server/v1/contexts/proxy/routes.rs index e6bd7bef..b12ff0ee 100644 --- a/src/web/api/v1/contexts/proxy/routes.rs +++ b/src/web/api/server/v1/contexts/proxy/routes.rs @@ -1,6 +1,6 @@ -//! API routes for the [`proxy`](crate::web::api::v1::contexts::proxy) API context. +//! API routes for the [`proxy`](crate::web::api::server::v1::contexts::proxy) API context. //! -//! Refer to the [API endpoint documentation](crate::web::api::v1::contexts::proxy). +//! Refer to the [API endpoint documentation](crate::web::api::server::v1::contexts::proxy). use std::sync::Arc; use axum::routing::get; @@ -9,7 +9,7 @@ use axum::Router; use super::handlers::get_proxy_image_handler; use crate::common::AppData; -/// Routes for the [`about`](crate::web::api::v1::contexts::about) API context. +/// Routes for the [`about`](crate::web::api::server::v1::contexts::about) API context. pub fn router(app_data: Arc) -> Router { Router::new().route("/image/:url", get(get_proxy_image_handler).with_state(app_data)) } diff --git a/src/web/api/v1/contexts/settings/handlers.rs b/src/web/api/server/v1/contexts/settings/handlers.rs similarity index 87% rename from src/web/api/v1/contexts/settings/handlers.rs rename to src/web/api/server/v1/contexts/settings/handlers.rs index f4d94541..48c0cb91 100644 --- a/src/web/api/v1/contexts/settings/handlers.rs +++ b/src/web/api/server/v1/contexts/settings/handlers.rs @@ -1,4 +1,4 @@ -//! API handlers for the the [`category`](crate::web::api::v1::contexts::category) API +//! API handlers for the the [`category`](crate::web::api::server::v1::contexts::category) API //! context. use std::sync::Arc; @@ -6,8 +6,8 @@ use axum::extract::State; use axum::response::{IntoResponse, Json, Response}; use crate::common::AppData; -use crate::web::api::v1::extractors::bearer_token::Extract; -use crate::web::api::v1::responses; +use crate::web::api::server::v1::extractors::bearer_token::Extract; +use crate::web::api::server::v1::responses; /// Get all settings. /// diff --git a/src/web/api/v1/contexts/settings/mod.rs b/src/web/api/server/v1/contexts/settings/mod.rs similarity index 100% rename from src/web/api/v1/contexts/settings/mod.rs rename to src/web/api/server/v1/contexts/settings/mod.rs diff --git a/src/web/api/v1/contexts/settings/routes.rs b/src/web/api/server/v1/contexts/settings/routes.rs similarity index 62% rename from src/web/api/v1/contexts/settings/routes.rs rename to src/web/api/server/v1/contexts/settings/routes.rs index e0990f52..ebca3bb6 100644 --- a/src/web/api/v1/contexts/settings/routes.rs +++ b/src/web/api/server/v1/contexts/settings/routes.rs @@ -1,6 +1,6 @@ -//! API routes for the [`settings`](crate::web::api::v1::contexts::settings) API context. +//! API routes for the [`settings`](crate::web::api::server::v1::contexts::settings) API context. //! -//! Refer to the [API endpoint documentation](crate::web::api::v1::contexts::settings). +//! Refer to the [API endpoint documentation](crate::web::api::server::v1::contexts::settings). use std::sync::Arc; use axum::routing::get; @@ -9,7 +9,7 @@ use axum::Router; use super::handlers::{get_all_handler, get_public_handler, get_site_name_handler}; use crate::common::AppData; -/// Routes for the [`category`](crate::web::api::v1::contexts::category) API context. +/// Routes for the [`category`](crate::web::api::server::v1::contexts::category) API context. pub fn router(app_data: Arc) -> Router { Router::new() .route("/", get(get_all_handler).with_state(app_data.clone())) diff --git a/src/web/api/v1/contexts/tag/forms.rs b/src/web/api/server/v1/contexts/tag/forms.rs similarity index 76% rename from src/web/api/v1/contexts/tag/forms.rs rename to src/web/api/server/v1/contexts/tag/forms.rs index 12c751ad..d254b324 100644 --- a/src/web/api/v1/contexts/tag/forms.rs +++ b/src/web/api/server/v1/contexts/tag/forms.rs @@ -1,4 +1,4 @@ -//! API forms for the the [`tag`](crate::web::api::v1::contexts::tag) API +//! API forms for the the [`tag`](crate::web::api::server::v1::contexts::tag) API //! context. use serde::{Deserialize, Serialize}; diff --git a/src/web/api/v1/contexts/tag/handlers.rs b/src/web/api/server/v1/contexts/tag/handlers.rs similarity index 89% rename from src/web/api/v1/contexts/tag/handlers.rs rename to src/web/api/server/v1/contexts/tag/handlers.rs index f750c385..5ba38249 100644 --- a/src/web/api/v1/contexts/tag/handlers.rs +++ b/src/web/api/server/v1/contexts/tag/handlers.rs @@ -1,4 +1,4 @@ -//! API handlers for the [`tag`](crate::web::api::v1::contexts::tag) API +//! API handlers for the [`tag`](crate::web::api::server::v1::contexts::tag) API //! context. use std::sync::Arc; @@ -8,8 +8,8 @@ use axum::response::{IntoResponse, Json, Response}; use super::forms::{AddTagForm, DeleteTagForm}; use super::responses::{added_tag, deleted_tag}; use crate::common::AppData; -use crate::web::api::v1::extractors::bearer_token::Extract; -use crate::web::api::v1::responses::{self}; +use crate::web::api::server::v1::extractors::bearer_token::Extract; +use crate::web::api::server::v1::responses::{self}; /// It handles the request to get all the tags. /// @@ -18,7 +18,7 @@ use crate::web::api::v1::responses::{self}; /// - `200` response with a json containing the tag list [`Vec`](crate::models::torrent_tag::TorrentTag). /// - Other error status codes if there is a database error. /// -/// Refer to the [API endpoint documentation](crate::web::api::v1::contexts::tag) +/// Refer to the [API endpoint documentation](crate::web::api::server::v1::contexts::tag) /// for more information about this endpoint. /// /// # Errors diff --git a/src/web/api/v1/contexts/tag/mod.rs b/src/web/api/server/v1/contexts/tag/mod.rs similarity index 100% rename from src/web/api/v1/contexts/tag/mod.rs rename to src/web/api/server/v1/contexts/tag/mod.rs diff --git a/src/web/api/v1/contexts/tag/responses.rs b/src/web/api/server/v1/contexts/tag/responses.rs similarity index 74% rename from src/web/api/v1/contexts/tag/responses.rs rename to src/web/api/server/v1/contexts/tag/responses.rs index a1645994..ac1e2c75 100644 --- a/src/web/api/v1/contexts/tag/responses.rs +++ b/src/web/api/server/v1/contexts/tag/responses.rs @@ -1,9 +1,9 @@ -//! API responses for the [`tag`](crate::web::api::v1::contexts::tag) API +//! API responses for the [`tag`](crate::web::api::server::v1::contexts::tag) API //! context. use axum::Json; use crate::models::torrent_tag::TagId; -use crate::web::api::v1::responses::OkResponseData; +use crate::web::api::server::v1::responses::OkResponseData; /// Response after successfully creating a new tag. pub fn added_tag(tag_name: &str) -> Json> { diff --git a/src/web/api/v1/contexts/tag/routes.rs b/src/web/api/server/v1/contexts/tag/routes.rs similarity index 64% rename from src/web/api/v1/contexts/tag/routes.rs rename to src/web/api/server/v1/contexts/tag/routes.rs index 4d72970a..0ec554e4 100644 --- a/src/web/api/v1/contexts/tag/routes.rs +++ b/src/web/api/server/v1/contexts/tag/routes.rs @@ -1,6 +1,6 @@ -//! API routes for the [`tag`](crate::web::api::v1::contexts::tag) API context. +//! API routes for the [`tag`](crate::web::api::server::v1::contexts::tag) API context. //! -//! Refer to the [API endpoint documentation](crate::web::api::v1::contexts::tag). +//! Refer to the [API endpoint documentation](crate::web::api::server::v1::contexts::tag). use std::sync::Arc; use axum::routing::{delete, get, post}; @@ -11,14 +11,14 @@ use crate::common::AppData; // code-review: should we use `tags` also for single resources? -/// Routes for the [`tag`](crate::web::api::v1::contexts::tag) API context. +/// Routes for the [`tag`](crate::web::api::server::v1::contexts::tag) API context. pub fn router_for_single_resources(app_data: Arc) -> Router { Router::new() .route("/", post(add_handler).with_state(app_data.clone())) .route("/", delete(delete_handler).with_state(app_data)) } -/// Routes for the [`tag`](crate::web::api::v1::contexts::tag) API context. +/// Routes for the [`tag`](crate::web::api::server::v1::contexts::tag) API context. pub fn router_for_multiple_resources(app_data: Arc) -> Router { Router::new().route("/", get(get_all_handler).with_state(app_data)) } diff --git a/src/web/api/v1/contexts/torrent/errors.rs b/src/web/api/server/v1/contexts/torrent/errors.rs similarity index 96% rename from src/web/api/v1/contexts/torrent/errors.rs rename to src/web/api/server/v1/contexts/torrent/errors.rs index 9bf24d48..87166419 100644 --- a/src/web/api/v1/contexts/torrent/errors.rs +++ b/src/web/api/server/v1/contexts/torrent/errors.rs @@ -2,7 +2,7 @@ use axum::response::{IntoResponse, Response}; use derive_more::{Display, Error}; use hyper::StatusCode; -use crate::web::api::v1::responses::{json_error_response, ErrorResponseData}; +use crate::web::api::server::v1::responses::{json_error_response, ErrorResponseData}; #[derive(Debug, Display, PartialEq, Eq, Error)] pub enum Request { diff --git a/src/web/api/v1/contexts/torrent/forms.rs b/src/web/api/server/v1/contexts/torrent/forms.rs similarity index 100% rename from src/web/api/v1/contexts/torrent/forms.rs rename to src/web/api/server/v1/contexts/torrent/forms.rs diff --git a/src/web/api/v1/contexts/torrent/handlers.rs b/src/web/api/server/v1/contexts/torrent/handlers.rs similarity index 97% rename from src/web/api/v1/contexts/torrent/handlers.rs rename to src/web/api/server/v1/contexts/torrent/handlers.rs index bab51443..745a81df 100644 --- a/src/web/api/v1/contexts/torrent/handlers.rs +++ b/src/web/api/server/v1/contexts/torrent/handlers.rs @@ -1,4 +1,4 @@ -//! API handlers for the [`torrent`](crate::web::api::v1::contexts::torrent) API +//! API handlers for the [`torrent`](crate::web::api::server::v1::contexts::torrent) API //! context. use std::io::{Cursor, Write}; use std::str::FromStr; @@ -21,10 +21,10 @@ use crate::models::torrent_tag::TagId; use crate::services::torrent::{AddTorrentRequest, ListingRequest}; use crate::services::torrent_file::generate_random_torrent; use crate::utils::parse_torrent; -use crate::web::api::v1::auth::get_optional_logged_in_user; -use crate::web::api::v1::extractors::bearer_token::Extract; -use crate::web::api::v1::responses::OkResponseData; -use crate::web::api::v1::routes::API_VERSION_URL_PREFIX; +use crate::web::api::server::v1::auth::get_optional_logged_in_user; +use crate::web::api::server::v1::extractors::bearer_token::Extract; +use crate::web::api::server::v1::responses::OkResponseData; +use crate::web::api::server::v1::routes::API_VERSION_URL_PREFIX; /// Upload a new torrent file to the Index /// diff --git a/src/web/api/v1/contexts/torrent/mod.rs b/src/web/api/server/v1/contexts/torrent/mod.rs similarity index 99% rename from src/web/api/v1/contexts/torrent/mod.rs rename to src/web/api/server/v1/contexts/torrent/mod.rs index 6b047940..3f915f76 100644 --- a/src/web/api/v1/contexts/torrent/mod.rs +++ b/src/web/api/server/v1/contexts/torrent/mod.rs @@ -271,7 +271,7 @@ //! `tags` | `Option>` | The tag Id list | No | `[1,2,3]` //! //! -//! Refer to the [`UpdateTorrentInfoForm`](crate::web::api::v1::contexts::torrent::forms::UpdateTorrentInfoForm) +//! Refer to the [`UpdateTorrentInfoForm`](crate::web::api::server::v1::contexts::torrent::forms::UpdateTorrentInfoForm) //! struct for more information about the request attributes. //! //! **Example request** diff --git a/src/web/api/v1/contexts/torrent/responses.rs b/src/web/api/server/v1/contexts/torrent/responses.rs similarity index 96% rename from src/web/api/v1/contexts/torrent/responses.rs rename to src/web/api/server/v1/contexts/torrent/responses.rs index 9873b420..d928f675 100644 --- a/src/web/api/v1/contexts/torrent/responses.rs +++ b/src/web/api/server/v1/contexts/torrent/responses.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::models::torrent::TorrentId; use crate::services::torrent::AddTorrentResponse; -use crate::web::api::v1::responses::OkResponseData; +use crate::web::api::server::v1::responses::OkResponseData; #[allow(clippy::module_name_repetitions)] #[derive(Serialize, Deserialize, Debug)] diff --git a/src/web/api/v1/contexts/torrent/routes.rs b/src/web/api/server/v1/contexts/torrent/routes.rs similarity index 75% rename from src/web/api/v1/contexts/torrent/routes.rs rename to src/web/api/server/v1/contexts/torrent/routes.rs index 1c529599..952ff396 100644 --- a/src/web/api/v1/contexts/torrent/routes.rs +++ b/src/web/api/server/v1/contexts/torrent/routes.rs @@ -1,6 +1,6 @@ -//! API routes for the [`torrent`](crate::web::api::v1::contexts::torrent) API context. +//! API routes for the [`torrent`](crate::web::api::server::v1::contexts::torrent) API context. //! -//! Refer to the [API endpoint documentation](crate::web::api::v1::contexts::torrent). +//! Refer to the [API endpoint documentation](crate::web::api::server::v1::contexts::torrent). use std::sync::Arc; use axum::routing::{delete, get, post, put}; @@ -12,7 +12,7 @@ use super::handlers::{ }; use crate::common::AppData; -/// Routes for the [`torrent`](crate::web::api::v1::contexts::torrent) API context for single resources. +/// Routes for the [`torrent`](crate::web::api::server::v1::contexts::torrent) API context for single resources. pub fn router_for_single_resources(app_data: Arc) -> Router { let torrent_info_routes = Router::new() .route("/", get(get_torrent_info_handler).with_state(app_data.clone())) @@ -32,7 +32,7 @@ pub fn router_for_single_resources(app_data: Arc) -> Router { .nest("/:info_hash", torrent_info_routes) } -/// Routes for the [`torrent`](crate::web::api::v1::contexts::torrent) API context for multiple resources. +/// Routes for the [`torrent`](crate::web::api::server::v1::contexts::torrent) API context for multiple resources. pub fn router_for_multiple_resources(app_data: Arc) -> Router { Router::new().route("/", get(get_torrents_handler).with_state(app_data)) } diff --git a/src/web/api/v1/contexts/user/forms.rs b/src/web/api/server/v1/contexts/user/forms.rs similarity index 100% rename from src/web/api/v1/contexts/user/forms.rs rename to src/web/api/server/v1/contexts/user/forms.rs diff --git a/src/web/api/v1/contexts/user/handlers.rs b/src/web/api/server/v1/contexts/user/handlers.rs similarity index 95% rename from src/web/api/v1/contexts/user/handlers.rs rename to src/web/api/server/v1/contexts/user/handlers.rs index 170bd073..ee33d2e0 100644 --- a/src/web/api/v1/contexts/user/handlers.rs +++ b/src/web/api/server/v1/contexts/user/handlers.rs @@ -1,4 +1,4 @@ -//! API handlers for the the [`user`](crate::web::api::v1::contexts::user) API +//! API handlers for the the [`user`](crate::web::api::server::v1::contexts::user) API //! context. use std::sync::Arc; @@ -10,8 +10,8 @@ use serde::Deserialize; use super::forms::{JsonWebToken, LoginForm, RegistrationForm}; use super::responses::{self}; use crate::common::AppData; -use crate::web::api::v1::extractors::bearer_token::Extract; -use crate::web::api::v1::responses::OkResponseData; +use crate::web::api::server::v1::extractors::bearer_token::Extract; +use crate::web::api::server::v1::responses::OkResponseData; // Registration diff --git a/src/web/api/v1/contexts/user/mod.rs b/src/web/api/server/v1/contexts/user/mod.rs similarity index 93% rename from src/web/api/v1/contexts/user/mod.rs rename to src/web/api/server/v1/contexts/user/mod.rs index 4f4682e0..a13c2bb8 100644 --- a/src/web/api/v1/contexts/user/mod.rs +++ b/src/web/api/server/v1/contexts/user/mod.rs @@ -6,7 +6,7 @@ //! - User authentication //! - User ban //! -//! For more information about the API authentication, refer to the [`auth`](crate::web::api::v1::auth) +//! For more information about the API authentication, refer to the [`auth`](crate::web::api::server::v1::auth) //! module. //! //! # Endpoints @@ -50,7 +50,7 @@ //! max_password_length = 64 //! ``` //! -//! Refer to the [`RegistrationForm`](crate::web::api::v1::contexts::user::forms::RegistrationForm) +//! Refer to the [`RegistrationForm`](crate::web::api::server::v1::contexts::user::forms::RegistrationForm) //! struct for more information about the registration form. //! //! **Example request** @@ -63,7 +63,7 @@ //! http://127.0.0.1:3001/v1/user/register //! ``` //! -//! For more information about the registration process, refer to the [`auth`](crate::web::api::v1::auth) +//! For more information about the registration process, refer to the [`auth`](crate::web::api::server::v1::auth) //! module. //! //! # Email verification @@ -97,7 +97,7 @@ //! `login` | `String` | The password | Yes | `indexadmin` //! `password` | `String` | The password | Yes | `BenoitMandelbrot1924` //! -//! Refer to the [`LoginForm`](crate::web::api::v1::contexts::user::forms::LoginForm) +//! Refer to the [`LoginForm`](crate::web::api::server::v1::contexts::user::forms::LoginForm) //! struct for more information about the login form. //! //! **Example request** @@ -110,7 +110,7 @@ //! http://127.0.0.1:3001/v1/user/login //! ``` //! -//! For more information about the login process, refer to the [`auth`](crate::web::api::v1::auth) +//! For more information about the login process, refer to the [`auth`](crate::web::api::server::v1::auth) //! module. //! //! # Token verification @@ -125,7 +125,7 @@ //! ---|---|---|---|--- //! `token` | `String` | The token you want to verify | Yes | `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7InVzZXJfaWQiOjEsInVzZXJuYW1lIjoiaW5kZXhhZG1pbiIsImFkbWluaXN0cmF0b3IiOnRydWV9LCJleHAiOjE2ODYyMTU3ODh9.4k8ty27DiWwOk4WVcYEhIrAndhpXMRWnLZ3i_HlJnvI` //! -//! Refer to the [`JsonWebToken`](crate::web::api::v1::contexts::user::forms::JsonWebToken) +//! Refer to the [`JsonWebToken`](crate::web::api::server::v1::contexts::user::forms::JsonWebToken) //! struct for more information about the token. //! //! **Example request** @@ -171,7 +171,7 @@ //! ---|---|---|---|--- //! `token` | `String` | The current valid token | Yes | `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7InVzZXJfaWQiOjEsInVzZXJuYW1lIjoiaW5kZXhhZG1pbiIsImFkbWluaXN0cmF0b3IiOnRydWV9LCJleHAiOjE2ODYyMTU3ODh9.4k8ty27DiWwOk4WVcYEhIrAndhpXMRWnLZ3i_HlJnvI` //! -//! Refer to the [`JsonWebToken`](crate::web::api::v1::contexts::user::forms::JsonWebToken) +//! Refer to the [`JsonWebToken`](crate::web::api::server::v1::contexts::user::forms::JsonWebToken) //! struct for more information about the token. //! //! **Example request** diff --git a/src/web/api/v1/contexts/user/responses.rs b/src/web/api/server/v1/contexts/user/responses.rs similarity index 95% rename from src/web/api/v1/contexts/user/responses.rs rename to src/web/api/server/v1/contexts/user/responses.rs index 17a06bdf..fde7c78b 100644 --- a/src/web/api/v1/contexts/user/responses.rs +++ b/src/web/api/server/v1/contexts/user/responses.rs @@ -2,7 +2,7 @@ use axum::Json; use serde::{Deserialize, Serialize}; use crate::models::user::{UserCompact, UserId}; -use crate::web::api::v1::responses::OkResponseData; +use crate::web::api::server::v1::responses::OkResponseData; // Registration diff --git a/src/web/api/v1/contexts/user/routes.rs b/src/web/api/server/v1/contexts/user/routes.rs similarity index 83% rename from src/web/api/v1/contexts/user/routes.rs rename to src/web/api/server/v1/contexts/user/routes.rs index b2a21624..04ae9980 100644 --- a/src/web/api/v1/contexts/user/routes.rs +++ b/src/web/api/server/v1/contexts/user/routes.rs @@ -1,6 +1,6 @@ -//! API routes for the [`user`](crate::web::api::v1::contexts::user) API context. +//! API routes for the [`user`](crate::web::api::server::v1::contexts::user) API context. //! -//! Refer to the [API endpoint documentation](crate::web::api::v1::contexts::user). +//! Refer to the [API endpoint documentation](crate::web::api::server::v1::contexts::user). use std::sync::Arc; use axum::routing::{delete, get, post}; @@ -11,7 +11,7 @@ use super::handlers::{ }; use crate::common::AppData; -/// Routes for the [`user`](crate::web::api::v1::contexts::user) API context. +/// Routes for the [`user`](crate::web::api::server::v1::contexts::user) API context. pub fn router(app_data: Arc) -> Router { Router::new() // Registration diff --git a/src/web/api/v1/extractors/bearer_token.rs b/src/web/api/server/v1/extractors/bearer_token.rs similarity index 93% rename from src/web/api/v1/extractors/bearer_token.rs rename to src/web/api/server/v1/extractors/bearer_token.rs index 1c9b5be9..7a166503 100644 --- a/src/web/api/v1/extractors/bearer_token.rs +++ b/src/web/api/server/v1/extractors/bearer_token.rs @@ -4,7 +4,7 @@ use axum::http::request::Parts; use axum::response::Response; use serde::Deserialize; -use crate::web::api::v1::auth::parse_token; +use crate::web::api::server::v1::auth::parse_token; pub struct Extract(pub Option); diff --git a/src/web/api/v1/extractors/mod.rs b/src/web/api/server/v1/extractors/mod.rs similarity index 100% rename from src/web/api/v1/extractors/mod.rs rename to src/web/api/server/v1/extractors/mod.rs diff --git a/src/web/api/v1/mod.rs b/src/web/api/server/v1/mod.rs similarity index 100% rename from src/web/api/v1/mod.rs rename to src/web/api/server/v1/mod.rs diff --git a/src/web/api/v1/responses.rs b/src/web/api/server/v1/responses.rs similarity index 100% rename from src/web/api/v1/responses.rs rename to src/web/api/server/v1/responses.rs diff --git a/src/web/api/v1/routes.rs b/src/web/api/server/v1/routes.rs similarity index 100% rename from src/web/api/v1/routes.rs rename to src/web/api/server/v1/routes.rs diff --git a/src/web/api/v1/contexts/mod.rs b/src/web/api/v1/contexts/mod.rs deleted file mode 100644 index f6ef4069..00000000 --- a/src/web/api/v1/contexts/mod.rs +++ /dev/null @@ -1,19 +0,0 @@ -//! The API is organized in the following contexts: -//! -//! Context | Description | Version -//! ---|---|--- -//! `About` | Metadata about the API | [`v1`](crate::web::api::v1::contexts::about) -//! `Category` | Torrent categories | [`v1`](crate::web::api::v1::contexts::category) -//! `Proxy` | Image proxy cache | [`v1`](crate::web::api::v1::contexts::proxy) -//! `Settings` | Index settings | [`v1`](crate::web::api::v1::contexts::settings) -//! `Tag` | Torrent tags | [`v1`](crate::web::api::v1::contexts::tag) -//! `Torrent` | Indexed torrents | [`v1`](crate::web::api::v1::contexts::torrent) -//! `User` | Users | [`v1`](crate::web::api::v1::contexts::user) -//! -pub mod about; -pub mod category; -pub mod proxy; -pub mod settings; -pub mod tag; -pub mod torrent; -pub mod user; diff --git a/src/web/mod.rs b/src/web/mod.rs index 9007e88f..d51f4b78 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -2,5 +2,5 @@ //! //! Currently, the API has only one version: `v1`. //! -//! Refer to the [`v1`](crate::web::api::v1) module for more information. +//! Refer to the [`v1`](crate::web::api::server::v1) module for more information. pub mod api; diff --git a/tests/common/asserts.rs b/tests/common/asserts.rs index 50a60e26..0760d1cd 100644 --- a/tests/common/asserts.rs +++ b/tests/common/asserts.rs @@ -1,6 +1,6 @@ // Text responses -use torrust_index::web::api::v1::responses::ErrorResponseData; +use torrust_index::web::api::server::v1::responses::ErrorResponseData; use super::responses::TextResponse; diff --git a/tests/e2e/web/api/v1/contexts/torrent/steps.rs b/tests/e2e/web/api/v1/contexts/torrent/steps.rs index 56c7a648..3782f307 100644 --- a/tests/e2e/web/api/v1/contexts/torrent/steps.rs +++ b/tests/e2e/web/api/v1/contexts/torrent/steps.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use torrust_index::models::info_hash::InfoHash; -use torrust_index::web::api::v1::responses::ErrorResponseData; +use torrust_index::web::api::server::v1::responses::ErrorResponseData; use crate::common::client::Client; use crate::common::contexts::torrent::fixtures::{random_torrent, TestTorrent, TorrentIndexInfo, TorrentListedInIndex};