From 8b5bb367e2bd03a64c233e1eb128c2d0980f5b01 Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Tue, 5 May 2020 14:09:14 -0400 Subject: updated debug script, moved backlog to Deck --- BACKLOG.md | 30 ------------------------------ dichroism/Cargo.lock | 3 +++ dichroism/Cargo.toml | 3 +++ dichroism/debug.sh | 2 ++ dichroism/run-dev.sh | 2 -- dichroism/src/main.rs | 41 +++++++++++++++++++++++++++++++++++++++-- 6 files changed, 47 insertions(+), 34 deletions(-) delete mode 100644 BACKLOG.md create mode 100755 dichroism/debug.sh delete mode 100755 dichroism/run-dev.sh diff --git a/BACKLOG.md b/BACKLOG.md deleted file mode 100644 index e21f8f3..0000000 --- a/BACKLOG.md +++ /dev/null @@ -1,30 +0,0 @@ -# Sprint 1 - -# General Backlog - -## Issues - -- only import the sass modules we actually need in App.vue - -## Stories - -- navigate between store, admin, and about -- see a list of products -- get detailed information on a single product -- add various products to a cart -- see items and prices of things in their cart -- see their cart total -- search for (filter out) products by name -- sort products by price -- sort products by type/category -- check out their cart after shopping -- select their method of payment -- select their method of pickup/shipping -- see inventory change after they checkout - -## Tasks - -- create a db - - create schema - - seed db with initial data - diff --git a/dichroism/Cargo.lock b/dichroism/Cargo.lock index 4afab50..e571dcb 100644 --- a/dichroism/Cargo.lock +++ b/dichroism/Cargo.lock @@ -459,7 +459,10 @@ version = "0.1.0" dependencies = [ "actix-rt", "actix-web", + "futures", "listenfd", + "serde", + "serde_json", ] [[package]] diff --git a/dichroism/Cargo.toml b/dichroism/Cargo.toml index d53f861..8706e33 100644 --- a/dichroism/Cargo.toml +++ b/dichroism/Cargo.toml @@ -10,4 +10,7 @@ edition = "2018" actix-web = "2.0" actix-rt = "1.0" listenfd = "0.3" +serde = "1.0.106" +futures = "0.3.4" +serde_json = "1.0.52" diff --git a/dichroism/debug.sh b/dichroism/debug.sh new file mode 100755 index 0000000..c5d1213 --- /dev/null +++ b/dichroism/debug.sh @@ -0,0 +1,2 @@ +#!/bin/sh +systemfd --no-pid -s http::8000 -- cargo watch -x run diff --git a/dichroism/run-dev.sh b/dichroism/run-dev.sh deleted file mode 100755 index c5d1213..0000000 --- a/dichroism/run-dev.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -systemfd --no-pid -s http::8000 -- cargo watch -x run diff --git a/dichroism/src/main.rs b/dichroism/src/main.rs index e4bb217..858a21c 100644 --- a/dichroism/src/main.rs +++ b/dichroism/src/main.rs @@ -1,12 +1,48 @@ -use actix_web::{web, App, HttpRequest, HttpServer, Responder}; +use actix_web::{web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder}; +use futures::future::{ready, Ready}; use listenfd::ListenFd; +use serde::Serialize; + +#[derive(Serialize)] +struct Product { + id: u32, + name: String, + quantity: i32, + cents: u32, + img_path: String, + description: String, +} + +impl Responder for Product { + type Error = Error; + type Future = Ready>; + + fn respond_to(self, _req: &HttpRequest) -> Self::Future { + let body = serde_json::to_string(&self).unwrap(); + + ready(Ok(HttpResponse::Ok() + .content_type("application/json") + .body(body))) + } +} + +async fn products() -> impl Responder { + Product { + id: 1, + name: "Beach Box".to_string(), + quantity: 3, + cents: 1100, + img_path: "/beach_box.jpg".to_string(), + description: "It's a beach in a box".to_string(), + } +} async fn greet(req: HttpRequest) -> impl Responder { let name = req.match_info().get("name").unwrap_or("World"); format!("Hello {}!", &name) } -async fn index(_: HttpRequest) -> impl Responder { +async fn index() -> impl Responder { "Hello, this is an API. If you're looking for the web app, try port 443.".to_string() } @@ -17,6 +53,7 @@ async fn main() -> std::io::Result<()> { App::new() .route("/", web::get().to(index)) .route("/{name}", web::get().to(greet)) + .route("/products", web::get().to(products)) }); server = if let Some(l) = listenfd.take_tcp_listener(0).unwrap() { -- cgit v1.2.3