index : license-api-rs.git

ascending towards madness

author holly sparkles <sparkles@holly.sh> 2023-10-02 18:07:37.0 +00:00:00
committer holly sparkles <sparkles@holly.sh> 2023-10-02 21:03:29.0 +00:00:00
commit
f0a8ba65b3a1e6cfb88ff0468d3dae62900b6670 [patch]
tree
cf9c89b70c749cba2a49f00adac899cb725c9d94
parent
8f2e2264df72bad622a7fba7eeca4d031abb5e00
download
f0a8ba65b3a1e6cfb88ff0468d3dae62900b6670.tar.gz

feat: add retrieving of license lists



Diff

 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<Response> {
async fn get_license_list(req: tide::Request<()>) -> tide::Result<Response> {
    log::info!("{:?}", req);

    let licenses: String = DATABASE
        .licenses
        .iter()
        .map(|license| license.id.clone())
        .collect::<Vec<String>>()
        .chunks(5)
        .map(|chunk| chunk.join(", "))
        .collect::<Vec<String>>()
        .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<Response> {
    log::info!("{:?}", req);

    const PADDING: usize = 20;

    let licenses: String = DATABASE
        .licenses
        .iter()
        .map(|license| {
            format!(
                "{:padding$}{}",
                license.id,
                license.description,
                padding = PADDING
            )
        })
        .collect::<Vec<String>>()
        .join("\n");

    Ok(build_response(
        StatusCode::Ok,
        format!("{}", "License list with full names goes here").to_string(),
        format!("{}", licenses).to_string(),
    ))
}