From f0a8ba65b3a1e6cfb88ff0468d3dae62900b6670 Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Mon, 2 Oct 2023 20:07:37 +0200 Subject: [PATCH] feat: add retrieving of license lists --- src/main.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 02f9eae..9e4c52c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,18 +104,44 @@ async fn get_welcome_message(req: tide::Request<()>) -> tide::Result { async fn get_license_list(req: tide::Request<()>) -> tide::Result { log::info!("{:?}", req); + let licenses: String = DATABASE + .licenses + .iter() + .map(|license| license.id.clone()) + .collect::>() + .chunks(5) + .map(|chunk| chunk.join(", ")) + .collect::>() + .join("\n"); + Ok(build_response( StatusCode::Ok, - format!("{}", "License list goes here").to_string(), + format!("{}", licenses).to_string(), )) } async fn get_detailed_license_list(req: tide::Request<()>) -> tide::Result { log::info!("{:?}", req); + const PADDING: usize = 20; + + let licenses: String = DATABASE + .licenses + .iter() + .map(|license| { + format!( + "{:padding$}{}", + license.id, + license.description, + padding = PADDING + ) + }) + .collect::>() + .join("\n"); + Ok(build_response( StatusCode::Ok, - format!("{}", "License list with full names goes here").to_string(), + format!("{}", licenses).to_string(), )) } -- libgit2 1.7.2