mirror of
https://github.com/supleed2/cch23-8bit.git
synced 2024-12-22 22:15:49 +00:00
Day 5
This commit is contained in:
parent
6b5c90729d
commit
7c3030c8ca
33
src/cal/day05.rs
Normal file
33
src/cal/day05.rs
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
|
@ -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())
|
||||||
|
|
Loading…
Reference in a new issue