Skip to content

Commit

Permalink
Merge torrust#209: Remove ActixWeb implementation
Browse files Browse the repository at this point in the history
717cdaa refactor(api): [torrust#208] use API impementation enum for API versioning (Jose Celano)
44c799e refator(api): [torrust#208] remove ActixWeb implementation (Jose Celano)

Pull request description:

  Remove ActixWeb implementation.

Top commit has no ACKs.

Tree-SHA512: 62e9724aabaf06c7ef1d2be3f8fe9e8a45ffe667ea96aa52018829231fc5ae80c7957e946040db43eccefeb544b685466e86c665d33ade50bef50727440ad116
  • Loading branch information
josecelano committed Jun 20, 2023
2 parents 0f2ed68 + 717cdaa commit dffec12
Show file tree
Hide file tree
Showing 66 changed files with 1,394 additions and 3,939 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ jobs:
run: cargo llvm-cov nextest
- name: E2E Tests
run: ./docker/bin/run-e2e-tests.sh
env:
TORRUST_IDX_BACK_E2E_EXCLUDE_ACTIX_WEB_IMPL: "true"
12 changes: 5 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ use crate::services::user::{self, DbBannedUserList, DbUserProfileRepository, DbU
use crate::services::{proxy, settings, torrent};
use crate::tracker::statistics_importer::StatisticsImporter;
use crate::web::api::v1::auth::Authentication;
use crate::web::api::{start, Implementation};
use crate::web::api::{start, Version};
use crate::{mailer, tracker};

pub struct Running {
pub api_socket_addr: SocketAddr,
pub actix_web_api_server: Option<JoinHandle<std::result::Result<(), std::io::Error>>>,
pub axum_api_server: Option<JoinHandle<std::result::Result<(), std::io::Error>>>,
pub api_server: Option<JoinHandle<std::result::Result<(), std::io::Error>>>,
pub tracker_data_importer_handle: tokio::task::JoinHandle<()>,
}

#[allow(clippy::too_many_lines)]
pub async fn run(configuration: Configuration, api_implementation: &Implementation) -> Running {
pub async fn run(configuration: Configuration, api_version: &Version) -> Running {
let log_level = configuration.settings.read().await.log_level.clone();

logging::setup(&log_level);
Expand Down Expand Up @@ -167,12 +166,11 @@ pub async fn run(configuration: Configuration, api_implementation: &Implementati

// Start API server

let running_api = start(app_data, &net_ip, net_port, api_implementation).await;
let running_api = start(app_data, &net_ip, net_port, api_version).await;

Running {
api_socket_addr: running_api.socket_addr,
actix_web_api_server: running_api.actix_web_api_server,
axum_api_server: running_api.axum_api_server,
api_server: running_api.api_server,
tracker_data_importer_handle: tracker_statistics_importer_handle,
}
}
2 changes: 1 addition & 1 deletion src/bin/import_tracker_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! You can execute it with: `cargo run --bin import_tracker_statistics`
use torrust_index_backend::console::commands::import_tracker_statistics::run_importer;

#[actix_web::main]
#[tokio::main]
async fn main() {
run_importer().await;
}
11 changes: 5 additions & 6 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use torrust_index_backend::app;
use torrust_index_backend::bootstrap::config::init_configuration;
use torrust_index_backend::web::api::Implementation;
use torrust_index_backend::web::api::Version;

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let configuration = init_configuration().await;

let api_implementation = Implementation::Axum;
let api_version = Version::V1;

let app = app::run(configuration, &api_implementation).await;
let app = app::run(configuration, &api_version).await;

match api_implementation {
Implementation::ActixWeb => app.actix_web_api_server.unwrap().await.expect("the API server was dropped"),
Implementation::Axum => app.axum_api_server.unwrap().await.expect("the Axum API server was dropped"),
match api_version {
Version::V1 => app.api_server.unwrap().await.expect("the API server was dropped"),
}
}
2 changes: 1 addition & 1 deletion src/bin/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use torrust_index_backend::upgrades::from_v1_0_0_to_v2_0_0::upgrader::run;

#[actix_web::main]
#[tokio::main]
async fn main() {
run().await;
}
2 changes: 0 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ use crate::web::api::v1::auth::Authentication;
use crate::{mailer, tracker};
pub type Username = String;

pub type WebAppData = actix_web::web::Data<Arc<AppData>>;

pub struct AppData {
pub cfg: Arc<Configuration>,
pub database: Arc<Box<dyn Database>>,
Expand Down
26 changes: 1 addition & 25 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::borrow::Cow;
use std::error;

use actix_web::http::{header, StatusCode};
use actix_web::{HttpResponse, HttpResponseBuilder, ResponseError};
use derive_more::{Display, Error};
use serde::{Deserialize, Serialize};
use hyper::StatusCode;

use crate::databases::database;

Expand Down Expand Up @@ -139,28 +137,6 @@ pub enum ServiceError {
DatabaseError,
}

// Begin ActixWeb error handling
// todo: remove after migration to Axum

#[derive(Serialize, Deserialize)]
pub struct ErrorToResponse {
pub error: String,
}

impl ResponseError for ServiceError {
fn status_code(&self) -> StatusCode {
http_status_code_for_service_error(self)
}

fn error_response(&self) -> HttpResponse {
HttpResponseBuilder::new(self.status_code())
.append_header((header::CONTENT_TYPE, "application/json; charset=UTF-8"))
.body(serde_json::to_string(&ErrorToResponse { error: self.to_string() }).unwrap())
}
}

// End ActixWeb error handling

impl From<sqlx::Error> for ServiceError {
fn from(e: sqlx::Error) -> Self {
eprintln!("{e:?}");
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! This is the backend API for [Torrust Tracker Index](https://github.com/torrust/torrust-index).
//!
//! It is written in Rust and uses the [actix-web](https://actix.rs/) framework. It is designed to be
//! It is written in Rust and uses the [Axum](https://github.com/tokio-rs/axum) framework. It is designed to be
//! used with by the [Torrust Tracker Index Frontend](https://github.com/torrust/torrust-index-frontend).
//!
//! If you are looking for information on how to use the API, please see the
Expand Down Expand Up @@ -266,7 +266,6 @@ pub mod databases;
pub mod errors;
pub mod mailer;
pub mod models;
pub mod routes;
pub mod services;
pub mod tracker;
pub mod ui;
Expand Down
4 changes: 2 additions & 2 deletions src/mailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
use crate::config::Configuration;
use crate::errors::ServiceError;
use crate::utils::clock;
use crate::web::api::API_VERSION;
use crate::web::api::v1::routes::API_VERSION_URL_PREFIX;

pub struct Service {
cfg: Arc<Configuration>,
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Service {
base_url = cfg_base_url;
}

format!("{base_url}/{API_VERSION}/user/email/verify/{token}")
format!("{base_url}/{API_VERSION_URL_PREFIX}/user/email/verify/{token}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/models/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct Metadata {
}

impl Metadata {
/// Returns the verify of this [`Create`].
/// Returns the verify of this [`Metadata`].
///
/// # Errors
///
Expand Down
38 changes: 0 additions & 38 deletions src/routes/about.rs

This file was deleted.

71 changes: 0 additions & 71 deletions src/routes/category.rs

This file was deleted.

21 changes: 0 additions & 21 deletions src/routes/mod.rs

This file was deleted.

60 changes: 0 additions & 60 deletions src/routes/proxy.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/routes/root.rs

This file was deleted.

Loading

0 comments on commit dffec12

Please sign in to comment.