Interface - Implémentation d'une première ébauche technique #40

Merged
florian_briand merged 7 commits from feat/8_implement_main_ui into main 2024-08-06 21:12:31 +02:00
4 changed files with 35 additions and 20 deletions
Showing only changes of commit e057889403 - Show all commits

View File

@ -2,26 +2,27 @@ mod templates;
use std::path::Path;
use askama::Template;
use askama_axum::IntoResponse;
use templates::{hello::HelloResponse, index::GetIndexResponse};
use axum::http::{StatusCode, Uri};
use tower_http::services::ServeDir;
async fn root() -> impl IntoResponse {
return GetIndexResponse {}.into_response();
async fn fallback(uri: Uri) -> (StatusCode, String) {
(StatusCode::NOT_FOUND, format!("No route for {uri}"))
}
async fn hello() -> impl IntoResponse {
return HelloResponse {
name: "Theo".to_string(),
}
.into_response();
#[derive(Template)]
#[template(path = "index.html")]
pub struct GetIndexResponse;
async fn root() -> impl IntoResponse {
GetIndexResponse {}.into_response()
}
pub fn get_router(assets_path: &Path) -> axum::Router {
let router = axum::Router::new()
axum::Router::new()
.nest_service("/assets", ServeDir::new(assets_path))
.route("/", axum::routing::get(root))
.route("/hello", axum::routing::get(hello));
router
.merge(templates::get_routes())
.fallback(fallback)
}

View File

@ -1,7 +1,20 @@
use askama::Template;
use askama_axum::IntoResponse;
use axum::{routing, Router};
#[derive(Template)]
#[template(path = "hello.html")]
pub struct HelloResponse {
struct HelloResponse {
pub name: String,
}
async fn hello() -> impl IntoResponse {
HelloResponse {
name: "Theo".to_string(),
}.into_response()
}
pub fn get_routes() -> Router {
Router::new()
.route("/", routing::get(hello))
}

View File

@ -1,5 +0,0 @@
use askama::Template;
#[derive(Template)]
#[template(path = "index.html")]
pub struct GetIndexResponse;

View File

@ -1,2 +1,8 @@
pub mod hello;
pub mod index;
use axum::Router;
mod hello;
pub fn get_routes() -> Router {
Router::new()
.nest("/hello", hello::get_routes())
}