summaryrefslogtreecommitdiff
path: root/dichroism/src/handlers.rs
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2020-10-03 22:39:05 -0400
committerAdam T. Carpenter <atc@53hor.net>2020-10-03 22:39:05 -0400
commitf8bf353073220ce329d8eb347e3574d5793b6d26 (patch)
treee82af1a3d953c2e332a0b15e7e3b7adb059ff061 /dichroism/src/handlers.rs
parent8da473460c3f82737ff34d02006ceac4c289243c (diff)
downloadtheglassyladies-f8bf353073220ce329d8eb347e3574d5793b6d26.tar.xz
theglassyladies-f8bf353073220ce329d8eb347e3574d5793b6d26.zip
moved handlers into separate module, started config
Diffstat (limited to 'dichroism/src/handlers.rs')
-rw-r--r--dichroism/src/handlers.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/dichroism/src/handlers.rs b/dichroism/src/handlers.rs
new file mode 100644
index 0000000..1e0ae28
--- /dev/null
+++ b/dichroism/src/handlers.rs
@@ -0,0 +1,29 @@
+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!")
+}