diff --git a/src/processes/feed_server.rs b/src/processes/feed_server.rs index e55d94c..1ef0604 100644 --- a/src/processes/feed_server.rs +++ b/src/processes/feed_server.rs @@ -1,6 +1,6 @@ mod endpoints; +mod errors; mod server; mod state; -mod errors; pub use server::FeedServer; diff --git a/src/processes/feed_server/endpoints/get_feed_skeleton.rs b/src/processes/feed_server/endpoints/get_feed_skeleton.rs index 833916a..2649a66 100644 --- a/src/processes/feed_server/endpoints/get_feed_skeleton.rs +++ b/src/processes/feed_server/endpoints/get_feed_skeleton.rs @@ -7,8 +7,8 @@ use axum::extract::{Query, State}; use axum::Json; use chrono::{DateTime, TimeZone, Utc}; -use crate::processes::feed_server::state::FeedServerState; use crate::processes::feed_server::errors::AppError; +use crate::processes::feed_server::state::FeedServerState; pub async fn get_feed_skeleton( State(state): State, @@ -20,11 +20,7 @@ pub async fn get_feed_skeleton( .ok_or_else(|| AppError::FeedNotFound(query.feed.clone()))?; let limit = query.limit.unwrap_or(20); - let earlier_than = query - .cursor - .as_deref() - .map(parse_cursor) - .transpose()?; + let earlier_than = query.cursor.as_deref().map(parse_cursor).transpose()?; let posts = algo .fetch_posts(&state.database, limit, earlier_than) @@ -50,8 +46,12 @@ fn make_cursor(date: &DateTime, cid: &str) -> String { fn parse_cursor(cursor: &str) -> anyhow::Result<(DateTime, &str)> { let mut parts = cursor.split("::"); - let indexed_at = parts.next().ok_or_else(|| anyhow!("Malformed cursor: {cursor}"))?; - let cid = parts.next().ok_or_else(|| anyhow!("Malformed cursor: {cursor}"))?; + let indexed_at = parts + .next() + .ok_or_else(|| anyhow!("Malformed cursor: {cursor}"))?; + let cid = parts + .next() + .ok_or_else(|| anyhow!("Malformed cursor: {cursor}"))?; if parts.next().is_some() { return Err(anyhow!("Malformed cursor: {cursor}")); diff --git a/src/processes/feed_server/errors.rs b/src/processes/feed_server/errors.rs index db6992c..4231f8a 100644 --- a/src/processes/feed_server/errors.rs +++ b/src/processes/feed_server/errors.rs @@ -1,5 +1,5 @@ -use axum::response::{Response, IntoResponse}; use axum::http::StatusCode; +use axum::response::{IntoResponse, Response}; pub enum AppError { FeedNotFound(String), @@ -9,12 +9,15 @@ pub enum AppError { impl IntoResponse for AppError { fn into_response(self) -> Response { 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) => ( StatusCode::INTERNAL_SERVER_ERROR, format!("Something went wrong: {}", e), - ) - }.into_response() + ), + } + .into_response() } }