Skip to content

Commit

Permalink
refactor: [#157] extract service: about
Browse files Browse the repository at this point in the history
Decoupling services from actix-web framework.
  • Loading branch information
josecelano committed May 17, 2023
1 parent 6dd1455 commit baa4c7e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 48 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod errors;
pub mod mailer;
pub mod models;
pub mod routes;
pub mod services;
pub mod tracker;
pub mod upgrades;
pub mod utils;
Expand Down
51 changes: 3 additions & 48 deletions src/routes/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use actix_web::{web, HttpResponse, Responder};

use crate::errors::ServiceResult;
use crate::routes::API_VERSION;
use crate::services::about::{index_page, license_page};

pub fn init(cfg: &mut web::ServiceConfig) {
cfg.service(
Expand All @@ -12,24 +13,6 @@ pub fn init(cfg: &mut web::ServiceConfig) {
);
}

const ABOUT: &str = r#"
<html>
<head>
<title>About</title>
</head>
<body style="margin-left: auto;margin-right: auto;max-width: 30em;">
<h1>Torrust Index Backend</h1>
<h2>About</h2>
<p>Hi! This is a running <a href="https://github.com/torrust/torrust-index-backend">torrust-index-backend</a>.</p>
</body>
<footer style="padding: 1.25em 0;border-top: dotted 1px;">
<a href="/about/license">license</a>
</footer>
</html>
"#;

/// Get About Section HTML
///
/// # Errors
Expand All @@ -39,37 +22,9 @@ const ABOUT: &str = r#"
pub async fn get() -> ServiceResult<impl Responder> {
Ok(HttpResponse::build(StatusCode::OK)
.content_type("text/html; charset=utf-8")
.body(ABOUT))
.body(index_page()))
}

const LICENSE: &str = r#"
<html>
<head>
<title>Licensing</title>
</head>
<body style="margin-left: auto;margin-right: auto;max-width: 30em;">
<h1>Torrust Index Backend</h1>
<h2>Licensing</h2>
<h3>Multiple Licenses</h3>
<p>This repository has multiple licenses depending on the content type, the date of contributions or stemming from external component licenses that were not developed by any of Torrust team members or Torrust repository contributors.</p>
<p>The two main applicable license to most of its content are:</p>
<p>- For Code -- <a href="https://github.com/torrust/torrust-index-backend/blob/main/licensing/agpl-3.0.md">agpl-3.0</a></p>
<p>- For Media (Images, etc.) -- <a href="https://github.com/torrust/torrust-index-backend/blob/main/licensing/cc-by-sa.md">cc-by-sa</a></p>
<p>If you want to read more about all the licenses and how they apply please refer to the <a href="https://github.com/torrust/torrust-index-backend/blob/develop/licensing/contributor_agreement_v01.md">contributor agreement</a>.</p>
</body>
<footer style="padding: 1.25em 0;border-top: dotted 1px;">
<a href="/about">about</a>
</footer>
</html>
"#;

/// Get the License in HTML
///
/// # Errors
Expand All @@ -79,5 +34,5 @@ const LICENSE: &str = r#"
pub async fn license() -> ServiceResult<impl Responder> {
Ok(HttpResponse::build(StatusCode::OK)
.content_type("text/html; charset=utf-8")
.body(LICENSE))
.body(license_page()))
}
59 changes: 59 additions & 0 deletions src/services/about.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//! Templates for "about" static pages.
use crate::routes::API_VERSION;

#[must_use]
pub fn index_page() -> String {
format!(
r#"
<html>
<head>
<title>About</title>
</head>
<body style="margin-left: auto;margin-right: auto;max-width: 30em;">
<h1>Torrust Index Backend</h1>
<h2>About</h2>
<p>Hi! This is a running <a href="https://github.com/torrust/torrust-index-backend">torrust-index-backend</a>.</p>
</body>
<footer style="padding: 1.25em 0;border-top: dotted 1px;">
<a href="/{API_VERSION}/about/license">license</a>
</footer>
</html>
"#
)
}

#[must_use]
pub fn license_page() -> String {
format!(
r#"
<html>
<head>
<title>Licensing</title>
</head>
<body style="margin-left: auto;margin-right: auto;max-width: 30em;">
<h1>Torrust Index Backend</h1>
<h2>Licensing</h2>
<h3>Multiple Licenses</h3>
<p>This repository has multiple licenses depending on the content type, the date of contributions or stemming from external component licenses that were not developed by any of Torrust team members or Torrust repository contributors.</p>
<p>The two main applicable license to most of its content are:</p>
<p>- For Code -- <a href="https://github.com/torrust/torrust-index-backend/blob/main/licensing/agpl-3.0.md">agpl-3.0</a></p>
<p>- For Media (Images, etc.) -- <a href="https://github.com/torrust/torrust-index-backend/blob/main/licensing/cc-by-sa.md">cc-by-sa</a></p>
<p>If you want to read more about all the licenses and how they apply please refer to the <a href="https://github.com/torrust/torrust-index-backend/blob/develop/licensing/contributor_agreement_v01.md">contributor agreement</a>.</p>
</body>
<footer style="padding: 1.25em 0;border-top: dotted 1px;">
<a href="/{API_VERSION}/about">about</a>
</footer>
</html>
"#
)
}
1 change: 1 addition & 0 deletions src/services/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod about;

0 comments on commit baa4c7e

Please sign in to comment.