This commit is contained in:
Aadi Desai 2023-12-21 15:07:53 +00:00
parent 6b5c90729d
commit 7c3030c8ca
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
2 changed files with 35 additions and 0 deletions

33
src/cal/day05.rs Normal file
View file

@ -0,0 +1,33 @@
use axum::{
extract::Query,
response::{IntoResponse, Response},
routing::post,
Json, Router,
};
pub(crate) fn router() -> Router {
Router::new().route("/5", post(five))
}
#[derive(serde::Deserialize)]
struct Pagination {
offset: Option<usize>,
limit: Option<usize>,
split: Option<usize>,
}
async fn five(Query(pagination): Query<Pagination>, Json(names): Json<Vec<String>>) -> Response {
let offset = pagination.offset.unwrap_or(0);
let limit = pagination.limit.unwrap_or(names.len());
let names = names
.into_iter()
.skip(offset)
.take(limit)
.collect::<Vec<_>>();
if let Some(split) = pagination.split {
let names = names.chunks(split).map(|a| a.to_vec()).collect::<Vec<_>>();
Json(names).into_response()
} else {
Json(names).into_response()
}
}

View file

@ -1,6 +1,7 @@
mod day00; mod day00;
mod day01; mod day01;
mod day04; mod day04;
mod day05;
mod day06; mod day06;
mod day07; mod day07;
mod day08; mod day08;
@ -18,6 +19,7 @@ pub(crate) fn router(pool: sqlx::PgPool) -> axum::Router {
.nest("/", day00::router()) .nest("/", day00::router())
.nest("/", day01::router()) .nest("/", day01::router())
.nest("/", day04::router()) .nest("/", day04::router())
.nest("/", day05::router())
.nest("/", day06::router()) .nest("/", day06::router())
.nest("/", day07::router()) .nest("/", day07::router())
.nest("/", day08::router()) .nest("/", day08::router())