log params, better create form display, refactor

This commit is contained in:
JOLIMAITRE Matthieu 2024-08-04 18:19:29 +02:00
parent a07c61fdbf
commit b039753181
2 changed files with 17 additions and 4 deletions

View file

@ -65,8 +65,10 @@ async fn main() -> Result<()> {
.route("/", get(home))
.with_state(state);
let listener = TcpListener::bind((address, port)).await.unwrap();
let listener = TcpListener::bind((address.as_str(), port)).await.unwrap();
let server = axum::serve(listener, app);
println!("Listening on http://{address}:{port}");
server.await?;
Ok(())
@ -183,11 +185,11 @@ fn validate_topic(topic: &str) -> Result<(), ValidationError> {
Ok(())
}
async fn post(State(state): State<MainState>, Form(post_content): Form<PostContent>) -> Response {
async fn post(State(state): State<MainState>, Form(post): Form<PostContent>) -> Response {
let mut store = state.store.write().unwrap();
let date = Utc::now().format("%d/%m/%Y");
if post_content.validate().is_err() {
if post.validate().is_err() {
return (StatusCode::BAD_REQUEST, "Bad input.").into_response();
}
@ -195,7 +197,7 @@ async fn post(State(state): State<MainState>, Form(post_content): Form<PostConte
topic,
content,
author,
} = post_content;
} = post;
let topic = sanithize_identifier(&topic);