tuitbot_server/routes/content/
list.rs1use std::sync::Arc;
4
5use axum::extract::{Query, State};
6use axum::Json;
7use serde::Deserialize;
8use serde_json::{json, Value};
9use tuitbot_core::storage::threads;
10
11use crate::account::AccountContext;
12use crate::error::ApiError;
13use crate::state::AppState;
14
15#[derive(Deserialize)]
17pub struct TweetsQuery {
18 #[serde(default = "default_tweet_limit")]
20 pub limit: u32,
21}
22
23fn default_tweet_limit() -> u32 {
24 50
25}
26
27#[derive(Deserialize)]
29pub struct ThreadsQuery {
30 #[serde(default = "default_thread_limit")]
32 pub limit: u32,
33}
34
35fn default_thread_limit() -> u32 {
36 20
37}
38
39pub async fn list_tweets(
41 State(state): State<Arc<AppState>>,
42 ctx: AccountContext,
43 Query(params): Query<TweetsQuery>,
44) -> Result<Json<Value>, ApiError> {
45 let tweets =
46 threads::get_recent_original_tweets_for(&state.db, &ctx.account_id, params.limit).await?;
47 Ok(Json(json!(tweets)))
48}
49
50pub async fn list_threads(
52 State(state): State<Arc<AppState>>,
53 ctx: AccountContext,
54 Query(params): Query<ThreadsQuery>,
55) -> Result<Json<Value>, ApiError> {
56 let threads = threads::get_recent_threads_for(&state.db, &ctx.account_id, params.limit).await?;
57 Ok(Json(json!(threads)))
58}