2024-09-24 20:26:15 -04:00
|
|
|
use crate::{datasources::comments::CommentsDatasource, AppState};
|
|
|
|
use axum::{
|
|
|
|
extract::{Form, State},
|
|
|
|
routing::{get, post},
|
|
|
|
Json,
|
|
|
|
};
|
|
|
|
use serde::Deserialize;
|
|
|
|
use sqlx::PgPool;
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
pub struct CommentInput {
|
|
|
|
name: String,
|
|
|
|
body: String,
|
|
|
|
post_id: i32,
|
|
|
|
}
|
|
|
|
|
2024-09-22 22:38:35 -04:00
|
|
|
pub struct CommentsRoute;
|
2024-09-24 20:26:15 -04:00
|
|
|
impl CommentsRoute {
|
|
|
|
pub fn routes(app_state: &AppState) -> axum::Router {
|
|
|
|
// add more comment routes here!
|
|
|
|
axum::Router::new()
|
2024-09-25 18:29:12 -04:00
|
|
|
// .route("/post/:id", get(CommentsRoute::get_post_comments))
|
|
|
|
// .route("/add", post(CommentsRoute::insert_comment))
|
|
|
|
.with_state(app_state.db.clone())
|
2024-09-24 20:26:15 -04:00
|
|
|
}
|
|
|
|
|
2024-09-25 18:29:12 -04:00
|
|
|
// async fn get_post_comments(State(pool): State<PgPool>) -> Json<()> {
|
|
|
|
// let results = CommentsDatasource::get_posts_comments(pool).await;
|
|
|
|
// Json {}
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// async fn insert_comment(
|
|
|
|
// State(pool): State<PgPool>,
|
|
|
|
// Form(comment_input): Form<CommentInput>,
|
|
|
|
// ) -> bool {
|
|
|
|
// let results = CommentsDatasource::insert_comment(pool, comment_input).await;
|
|
|
|
// true
|
|
|
|
// }
|
2024-09-24 20:26:15 -04:00
|
|
|
}
|