feat: implement thought thread retrieval with replies and visibility filtering
This commit is contained in:
@@ -11,7 +11,10 @@ use app::{
|
||||
persistence::thought::{create_thought, delete_thought, get_thought},
|
||||
state::AppState,
|
||||
};
|
||||
use models::{params::thought::CreateThoughtParams, schemas::thought::ThoughtSchema};
|
||||
use models::{
|
||||
params::thought::CreateThoughtParams,
|
||||
schemas::thought::{ThoughtSchema, ThoughtThreadSchema},
|
||||
};
|
||||
use sea_orm::prelude::Uuid;
|
||||
|
||||
use crate::{
|
||||
@@ -118,8 +121,33 @@ async fn thoughts_delete(
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/{id}/thread",
|
||||
params(
|
||||
("id" = Uuid, Path, description = "Thought ID")
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Thought thread found", body = ThoughtThreadSchema),
|
||||
(status = 404, description = "Not Found", body = ApiErrorResponse)
|
||||
)
|
||||
)]
|
||||
async fn get_thought_thread(
|
||||
State(state): State<AppState>,
|
||||
Path(id): Path<Uuid>,
|
||||
viewer: OptionalAuthUser,
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
let viewer_id = viewer.0.map(|u| u.id);
|
||||
let thread = app::persistence::thought::get_thought_with_replies(&state.conn, id, viewer_id)
|
||||
.await?
|
||||
.ok_or(UserError::NotFound)?;
|
||||
|
||||
Ok(Json(thread))
|
||||
}
|
||||
|
||||
pub fn create_thought_router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/", post(thoughts_post))
|
||||
.route("/{id}/thread", get(get_thought_thread))
|
||||
.route("/{id}", get(get_thought_by_id).delete(thoughts_delete))
|
||||
}
|
||||
|
Reference in New Issue
Block a user