Formatting
This commit is contained in:
parent
96480b6fb9
commit
db8a85624f
|
@ -1,6 +1,6 @@
|
||||||
mod endpoints;
|
mod endpoints;
|
||||||
|
mod errors;
|
||||||
mod server;
|
mod server;
|
||||||
mod state;
|
mod state;
|
||||||
mod errors;
|
|
||||||
|
|
||||||
pub use server::FeedServer;
|
pub use server::FeedServer;
|
||||||
|
|
|
@ -7,8 +7,8 @@ use axum::extract::{Query, State};
|
||||||
use axum::Json;
|
use axum::Json;
|
||||||
use chrono::{DateTime, TimeZone, Utc};
|
use chrono::{DateTime, TimeZone, Utc};
|
||||||
|
|
||||||
use crate::processes::feed_server::state::FeedServerState;
|
|
||||||
use crate::processes::feed_server::errors::AppError;
|
use crate::processes::feed_server::errors::AppError;
|
||||||
|
use crate::processes::feed_server::state::FeedServerState;
|
||||||
|
|
||||||
pub async fn get_feed_skeleton(
|
pub async fn get_feed_skeleton(
|
||||||
State(state): State<FeedServerState>,
|
State(state): State<FeedServerState>,
|
||||||
|
@ -20,11 +20,7 @@ pub async fn get_feed_skeleton(
|
||||||
.ok_or_else(|| AppError::FeedNotFound(query.feed.clone()))?;
|
.ok_or_else(|| AppError::FeedNotFound(query.feed.clone()))?;
|
||||||
|
|
||||||
let limit = query.limit.unwrap_or(20);
|
let limit = query.limit.unwrap_or(20);
|
||||||
let earlier_than = query
|
let earlier_than = query.cursor.as_deref().map(parse_cursor).transpose()?;
|
||||||
.cursor
|
|
||||||
.as_deref()
|
|
||||||
.map(parse_cursor)
|
|
||||||
.transpose()?;
|
|
||||||
|
|
||||||
let posts = algo
|
let posts = algo
|
||||||
.fetch_posts(&state.database, limit, earlier_than)
|
.fetch_posts(&state.database, limit, earlier_than)
|
||||||
|
@ -50,8 +46,12 @@ fn make_cursor(date: &DateTime<Utc>, cid: &str) -> String {
|
||||||
fn parse_cursor(cursor: &str) -> anyhow::Result<(DateTime<Utc>, &str)> {
|
fn parse_cursor(cursor: &str) -> anyhow::Result<(DateTime<Utc>, &str)> {
|
||||||
let mut parts = cursor.split("::");
|
let mut parts = cursor.split("::");
|
||||||
|
|
||||||
let indexed_at = parts.next().ok_or_else(|| anyhow!("Malformed cursor: {cursor}"))?;
|
let indexed_at = parts
|
||||||
let cid = parts.next().ok_or_else(|| anyhow!("Malformed cursor: {cursor}"))?;
|
.next()
|
||||||
|
.ok_or_else(|| anyhow!("Malformed cursor: {cursor}"))?;
|
||||||
|
let cid = parts
|
||||||
|
.next()
|
||||||
|
.ok_or_else(|| anyhow!("Malformed cursor: {cursor}"))?;
|
||||||
|
|
||||||
if parts.next().is_some() {
|
if parts.next().is_some() {
|
||||||
return Err(anyhow!("Malformed cursor: {cursor}"));
|
return Err(anyhow!("Malformed cursor: {cursor}"));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use axum::response::{Response, IntoResponse};
|
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
|
use axum::response::{IntoResponse, Response};
|
||||||
|
|
||||||
pub enum AppError {
|
pub enum AppError {
|
||||||
FeedNotFound(String),
|
FeedNotFound(String),
|
||||||
|
@ -9,12 +9,15 @@ pub enum AppError {
|
||||||
impl IntoResponse for AppError {
|
impl IntoResponse for AppError {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
match self {
|
match self {
|
||||||
Self::FeedNotFound(name) => (StatusCode::NOT_FOUND, format!("Feed not found: {}", name)),
|
Self::FeedNotFound(name) => {
|
||||||
|
(StatusCode::NOT_FOUND, format!("Feed not found: {}", name))
|
||||||
|
}
|
||||||
Self::Other(e) => (
|
Self::Other(e) => (
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
format!("Something went wrong: {}", e),
|
format!("Something went wrong: {}", e),
|
||||||
)
|
),
|
||||||
}.into_response()
|
}
|
||||||
|
.into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue