log params, better create form display, refactor
This commit is contained in:
parent
a07c61fdbf
commit
b039753181
2 changed files with 17 additions and 4 deletions
|
@ -72,6 +72,17 @@ pub async fn style() -> impl IntoResponse {
|
|||
color: wheat;
|
||||
}
|
||||
|
||||
label {
|
||||
display: inline-block;
|
||||
width: 8rem;
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 100%;
|
||||
height: 5rem;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue