mirror of
https://git.alemi.dev/guestbook.rs.git
synced 2024-12-19 02:54:52 +01:00
feat: add GET with help
This commit is contained in:
parent
c11b12a03f
commit
62a7cdbbef
1 changed files with 10 additions and 4 deletions
14
src/main.rs
14
src/main.rs
|
@ -1,5 +1,5 @@
|
|||
use std::net::SocketAddr;
|
||||
use axum::{routing::{put, post}, http::StatusCode, Json, Router, Form, response::Response, extract::FromRequest};
|
||||
use axum::{routing::{get, put, post}, http::StatusCode, Json, Router, Form};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use clap::Parser;
|
||||
use teloxide::prelude::*;
|
||||
|
@ -30,8 +30,9 @@ async fn main() {
|
|||
*CHAT_ID.write().await = ChatId(args.target);
|
||||
|
||||
let app = Router::new()
|
||||
.route("/suggestion", post(suggestion_form))
|
||||
.route("/suggestion", put(suggestion_json));
|
||||
.route("/send", get(suggestion_help))
|
||||
.route("/send", post(suggestion_form))
|
||||
.route("/send", put(suggestion_json));
|
||||
|
||||
let addr : SocketAddr = args.addr.parse().expect("invalid host provided");
|
||||
|
||||
|
@ -43,6 +44,11 @@ async fn main() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
async fn suggestion_help() -> (StatusCode, Json<Suggestion>) {
|
||||
let body = "use this endpoint to send me direct messages. this is the accepted structure. on PUT send as json, on POST send as form-urlencoded".to_string();
|
||||
(StatusCode::OK, Json(Suggestion { author: None, contact: None, body }))
|
||||
}
|
||||
|
||||
async fn suggestion_json(Json(payload): Json<Suggestion>) -> (StatusCode, Json<Acknowledgement>) {
|
||||
suggestion_inner(payload).await
|
||||
}
|
||||
|
@ -69,7 +75,7 @@ async fn suggestion_inner(payload: Suggestion) -> (StatusCode, Json<Acknowledgem
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Suggestion {
|
||||
author: Option<String>,
|
||||
contact: Option<String>,
|
||||
|
|
Loading…
Reference in a new issue