Formatting

This commit is contained in:
Aleksei Voronov 2023-09-27 12:45:08 +02:00
parent 96480b6fb9
commit db8a85624f
3 changed files with 16 additions and 13 deletions

View File

@ -1,6 +1,6 @@
mod endpoints;
mod errors;
mod server;
mod state;
mod errors;
pub use server::FeedServer;

View File

@ -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<FeedServerState>,
@ -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<Utc>, cid: &str) -> String {
fn parse_cursor(cursor: &str) -> anyhow::Result<(DateTime<Utc>, &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}"));

View File

@ -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()
}
}