X-Git-Url: http://git.euphorik.ch/?p=recipes.git;a=blobdiff_plain;f=backend%2Fsrc%2Fmain.rs;h=037650771f26c9fe8e2d0c2db0fbc7273a5961e8;hp=4c0d6984969e313a9fadca55313bc4ff261172c3;hb=e2e54b8f43015738af860b005825dc809f5275ab;hpb=3ebbe8172b0430bae5c554925a4582c9fec545f3 diff --git a/backend/src/main.rs b/backend/src/main.rs index 4c0d698..0376507 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -2,7 +2,7 @@ use std::io::prelude::*; use std::{fs::File, env::args}; use actix_files as fs; -use actix_web::{get, web, Responder, middleware, App, HttpServer, HttpResponse, web::Query}; +use actix_web::{get, web, Responder, middleware, App, HttpServer, HttpResponse, HttpRequest, web::Query}; use askama::Template; use listenfd::ListenFd; @@ -15,9 +15,16 @@ mod consts; mod db; #[derive(Template)] -#[template(path = "main.html")] -struct MainTemplate<'a> { - test: &'a str, +#[template(path = "home.html")] +struct HomeTemplate { + recipes: Vec +} + +#[derive(Template)] +#[template(path = "view_recipe.html")] +struct ViewRecipeTemplate { + recipes: Vec, + current_recipe: db::Recipe } #[derive(Deserialize)] @@ -25,12 +32,15 @@ pub struct Request { m: Option } -fn main_page(query: Query) -> HttpResponse { - - let main_template = MainTemplate { test: &"*** test ***" }; +#[get("/")] +async fn home_page(req: HttpRequest) -> impl Responder { + HomeTemplate { recipes: vec![ db::Recipe { title: String::from("Saumon en croûte feuilletée"), id: 1 }, db::Recipe { title: String::from("Croissant au jambon"), id: 2 } ] } +} - let s = main_template.render().unwrap(); - HttpResponse::Ok().content_type("text/html").body(s) +#[get("/recipe/view/{id}")] +async fn view_page(req: HttpRequest, path: web::Path<(i32,)>) -> impl Responder { + panic!("ERROR"); + ViewRecipeTemplate { recipes: vec![ db::Recipe { title: String::from("Saumon en croûte feuilletée"), id: 1 }, db::Recipe { title: String::from("Croissant au jambon"), id: 2 } ], current_recipe: db::Recipe { title: String::from("Saumon en croûte feuilletée"), id: 1 } } } #[derive(Debug, Deserialize)] @@ -70,7 +80,8 @@ async fn main() -> std::io::Result<()> { || { App::new() .wrap(middleware::Compress::default()) - .service(web::resource("/").to(main_page)) + .service(home_page) + .service(view_page) .service(fs::Files::new("/static", "static").show_files_listing()) } ); @@ -98,7 +109,6 @@ fn process_args() -> bool { return true } else if args.iter().any(|arg| arg == "--test") { let db_connection = db::Connection::new(); - db_connection.create_or_update(); return true }