summaryrefslogblamecommitdiff
path: root/dichroism/src/handlers.rs
blob: 1e0ae2866dabacebd64f0bcecb2c93aba5c0be55 (plain) (tree)




























                                                                                             
use crate::image_api;
use actix_web::{get, post, HttpResponse, Responder};

#[get("/")]
async fn hello() -> impl Responder {
    HttpResponse::Ok().body("Hey, this is an API!")
}

#[post("/images")]
async fn create_image(req_body: String) -> impl Responder {
    let data = match image_api::extract_data(&req_body) {
        Err(e) => return HttpResponse::BadRequest().body(format!("fail: {}", e.to_string())),
        Ok(d) => d,
    };

    if let Err(e) = image_api::generate_images(data) {
        return HttpResponse::BadRequest().body(format!(
            "Unable to extract image from data URI: {}",
            e.to_string()
        ));
    }

    HttpResponse::Ok().body("Image created.")
}

#[get("/products")]
async fn get_products(_req_body: String) -> impl Responder {
    HttpResponse::Ok().body("got products!")
}