Simplify things quite a bit

This commit is contained in:
David Pedersen
2022-02-13 21:10:56 +01:00
parent 4f087190a5
commit 9f5dbfd83a
7 changed files with 298 additions and 78 deletions
+13 -3
View File
@@ -7,15 +7,17 @@
// Just using this file for manual testing. Will be cleaned up before an eventual merge
use axum::{response::IntoResponse, Router};
use axum_extra::routing::{typed_path, RouterExt};
use axum_extra::routing::RouterExt;
use axum_macros::TypedPath;
use serde::Deserialize;
#[tokio::main]
async fn main() {
let app = Router::new()
.with(typed_path::get(users_index).post(users_create))
.with(typed_path::get(users_show));
.typed_get(users_index)
.typed_post(users_create)
.typed_get(users_show)
.typed_get(users_edit);
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
@@ -33,6 +35,10 @@ struct UsersMember {
id: u32,
}
#[derive(Deserialize, TypedPath)]
#[typed_path("/users/:id/edit")]
struct UsersEdit(u32);
async fn users_index(_: UsersCollection) -> impl IntoResponse {
"users#index"
}
@@ -44,3 +50,7 @@ async fn users_create(_: UsersCollection, _payload: String) -> impl IntoResponse
async fn users_show(UsersMember { id }: UsersMember) -> impl IntoResponse {
format!("users#show: {}", id)
}
async fn users_edit(UsersEdit(id): UsersEdit) -> impl IntoResponse {
format!("users#edit: {}", id)
}