From 1b98cbac1a761c37ea223a783d754f430777191c Mon Sep 17 00:00:00 2001 From: Milim Date: Sat, 7 Dec 2024 09:16:01 +0100 Subject: [PATCH] add basic book/chapter --- src/books/mod.rs | 15 +++++++++++++++ src/main.rs | 2 ++ 2 files changed, 17 insertions(+) create mode 100644 src/books/mod.rs diff --git a/src/books/mod.rs b/src/books/mod.rs new file mode 100644 index 0000000..c333300 --- /dev/null +++ b/src/books/mod.rs @@ -0,0 +1,15 @@ +use actix_web::{get, web, Scope}; + +pub fn book_scope() -> Scope { + web::scope("/b").service(book_view).service(chapter_view) +} + +#[get("/{book}")] +async fn book_view(book: web::Path) -> String { + format!("This is the info for {book}") +} + +#[get("/{book}/{chapter})")] +async fn chapter_view(path: web::Path<(String, String)>) -> String { + format!("This is {} of {}", path.0, path.1) +} diff --git a/src/main.rs b/src/main.rs index e95217b..41b0bce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use actix_web::{get, App, HttpServer}; use log::info; +mod books; mod config; mod db; @@ -16,6 +17,7 @@ async fn main() -> Result<(), std::io::Error> { App::new() .app_data(config) .app_data(db.clone()) + .service(books::book_scope()) .service(hello) }) .bind((config.binding_ip, config.port))?