Skip to content

Commit

Permalink
refator(api): [#208] remove ActixWeb implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Jun 20, 2023
1 parent 0f2ed68 commit 44c799e
Show file tree
Hide file tree
Showing 34 changed files with 15 additions and 2,544 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"
2 changes: 0 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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 tracker_data_importer_handle: tokio::task::JoinHandle<()>,
}
Expand Down Expand Up @@ -171,7 +170,6 @@ pub async fn run(configuration: Configuration, api_implementation: &Implementati

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,
tracker_data_importer_handle: tracker_statistics_importer_handle,
}
Expand Down
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;
}
1 change: 0 additions & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ async fn main() -> Result<(), std::io::Error> {
let app = app::run(configuration, &api_implementation).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"),
}
}
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
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 44c799e

Please sign in to comment.