Implement entry and feed pagination
This commit is contained in:
@@ -1,10 +1,27 @@
|
||||
use axum::{extract::State, Json};
|
||||
use axum::TypedHeader;
|
||||
use axum::extract::Query;
|
||||
use axum::response::IntoResponse;
|
||||
use axum::extract::State;
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::api_response::ApiResponse;
|
||||
use crate::error::Error;
|
||||
use crate::models::feed::Feed;
|
||||
use crate::headers::Accept;
|
||||
use crate::models::feed::{Feed, GetFeedsOptions};
|
||||
use crate::partials::feed_list::feed_list;
|
||||
|
||||
pub async fn get(State(pool): State<PgPool>) -> Result<Json<Vec<Feed>>, Error> {
|
||||
// TODO: pagination
|
||||
Ok(Json(Feed::get_all(&pool, Default::default()).await?))
|
||||
pub async fn get(
|
||||
Query(options): Query<GetFeedsOptions>,
|
||||
accept: Option<TypedHeader<Accept>>,
|
||||
State(pool): State<PgPool>,
|
||||
) -> Result<impl IntoResponse, impl IntoResponse> {
|
||||
let feeds = Feed::get_all(&pool, &options).await.map_err(Error::from)?;
|
||||
if let Some(TypedHeader(accept)) = accept {
|
||||
if accept == Accept::ApplicationJson {
|
||||
return Ok::<ApiResponse<Vec<Feed>>, Error>(ApiResponse::Json(feeds));
|
||||
}
|
||||
}
|
||||
Ok(ApiResponse::Html(
|
||||
feed_list(feeds, &options).into_string(),
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user