add basic book/chapter
This commit is contained in:
parent
f5e7e0a36e
commit
1b98cbac1a
2 changed files with 17 additions and 0 deletions
15
src/books/mod.rs
Normal file
15
src/books/mod.rs
Normal file
|
@ -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>) -> 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)
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
use actix_web::{get, App, HttpServer};
|
use actix_web::{get, App, HttpServer};
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
|
mod books;
|
||||||
mod config;
|
mod config;
|
||||||
mod db;
|
mod db;
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ async fn main() -> Result<(), std::io::Error> {
|
||||||
App::new()
|
App::new()
|
||||||
.app_data(config)
|
.app_data(config)
|
||||||
.app_data(db.clone())
|
.app_data(db.clone())
|
||||||
|
.service(books::book_scope())
|
||||||
.service(hello)
|
.service(hello)
|
||||||
})
|
})
|
||||||
.bind((config.binding_ip, config.port))?
|
.bind((config.binding_ip, config.port))?
|
||||||
|
|
Loading…
Add table
Reference in a new issue