summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author53hornet <atc@53hor.net>2022-01-01 12:27:41 -0500
committer53hornet <atc@53hor.net>2022-01-01 12:27:41 -0500
commitd7472320a00fa0bfd6b9be904e0730461f093f61 (patch)
treeeadbbfd9a3b82eaafff30d0114fa7c0c7ca66e7d /src
parent5d2c25bf3b196321ded7b7c7ac9ab9a2021fe9c3 (diff)
downloadtwinh-d7472320a00fa0bfd6b9be904e0730461f093f61.tar.xz
twinh-d7472320a00fa0bfd6b9be904e0730461f093f61.zip
chore: pre-ripping-apartHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/models/mod.rs20
-rw-r--r--src/repo/mod.rs25
-rw-r--r--src/routes/mod.rs9
-rw-r--r--src/templates/base.hbs10
-rw-r--r--src/templates/favicon.svg5
-rw-r--r--src/templates/index.hbs5
-rw-r--r--src/templates/mod.rs2
7 files changed, 61 insertions, 15 deletions
diff --git a/src/models/mod.rs b/src/models/mod.rs
index a252f51..ddef71f 100644
--- a/src/models/mod.rs
+++ b/src/models/mod.rs
@@ -1,4 +1,21 @@
-use serde::{Deserialize, Serialize};
+use crate::error::TwinHError;
+use bincode::deserialize;
+use serde::{de::DeserializeOwned, Deserialize, Serialize};
+use sled::IVec;
+
+pub struct Entity<M: DeserializeOwned + Serialize> {
+ pub umrn: u64,
+ pub model: M,
+}
+
+impl<M: DeserializeOwned + Serialize> Entity<M> {
+ pub fn new(t: (IVec, IVec)) -> Result<Self, TwinHError> {
+ let (umrn, model) = t;
+ let umrn = deserialize(&umrn)?;
+ let model = deserialize(&model)?;
+ Ok(Entity { umrn, model })
+ }
+}
#[derive(Serialize, Deserialize)]
pub struct Part {
@@ -12,7 +29,6 @@ pub struct Part {
#[derive(Serialize, Deserialize)]
pub struct Car {
- pub key: u64,
pub doors: u8,
//pub engine: Engine,
pub make: String,
diff --git a/src/repo/mod.rs b/src/repo/mod.rs
index 80b2814..4c55696 100644
--- a/src/repo/mod.rs
+++ b/src/repo/mod.rs
@@ -35,12 +35,20 @@ pub fn create_new_db() -> Result<(), TwinHError> {
pub fn get_all_cars() -> Result<Vec<Car>, TwinHError> {
let cars = REPO_INSTANCE
.open_tree(CARS_TREE)?
- .into_iter()
- .values()
- .collect::<Result<Vec<_>, _>>()?
.iter()
- .map(|c| deserialize::<Car>(&c))
+ .collect::<Result<Vec<_>, _>>()?
+ .into_iter()
+ .map(|e| crate::models::Entity::new(e))
+ .map(|e| e.map(|e| e.model))
.collect::<Result<Vec<_>, _>>()?;
+ // let cars = REPO_INSTANCE
+ // .open_tree(CARS_TREE)?
+ // .into_iter()
+ // .values()
+ // .collect::<Result<Vec<_>, _>>()?
+ // .iter()
+ // .map(|c| deserialize::<Car>(&c))
+ // .collect::<Result<Vec<_>, _>>()?;
Ok(cars)
}
@@ -51,7 +59,7 @@ pub fn insert_part(part: Part) -> Result<u64, TwinHError> {
#[cfg(test)]
mod tests {
use super::*;
- use crate::models::{Car, Part};
+ use crate::models::{Car, Entity, Part};
use bincode::serialize;
use std::error::Error;
@@ -63,7 +71,6 @@ mod tests {
.open()?;
let car = Car {
- key: 1,
make: "Hudson".into(),
model: "Hornet".into(),
trim: "Sedan".into(),
@@ -71,8 +78,10 @@ mod tests {
year: 1953,
};
+ let entity = Entity(1, &car);
+
let tree = db.open_tree(CARS_TREE)?;
- let key = car.key.to_be_bytes();
+ let key = entity.0.to_be_bytes();
let val = serialize(&car)?;
tree.insert(key, val)?;
@@ -80,7 +89,7 @@ mod tests {
key: 2,
number: "ABC123".into(),
name: "Rear Wheel Bearing".into(),
- fits_cars: vec![car.key],
+ fits_cars: vec![entity.0],
categories: Vec::new(),
sources: Vec::new(),
};
diff --git a/src/routes/mod.rs b/src/routes/mod.rs
index be07aa0..1948657 100644
--- a/src/routes/mod.rs
+++ b/src/routes/mod.rs
@@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
pub async fn router(req: Request<Body>) -> Result<Response<Body>, TwinHError> {
match (req.method(), req.uri().path()) {
+ (&Method::GET, "/favicon.ico") | (&Method::GET, "/favicon.svg") => favicon(),
(&Method::GET, "/") => index(req).await,
(&Method::GET, "/cars") => cars(req).await,
(&Method::GET, "/login") => login().await,
@@ -128,6 +129,14 @@ async fn cars(req: Request<Body>) -> Result<Response<Body>, TwinHError> {
todo!()
}
+fn favicon() -> Result<Response<Body>, TwinHError> {
+ let resp = Response::builder()
+ .header(hyper::header::CONTENT_TYPE, "image/svg+xml")
+ .body(templates::FAVICON.into())
+ .unwrap();
+ Ok(resp)
+}
+
async fn index(req: Request<Body>) -> Result<Response<Body>, TwinHError> {
let query = req.uri().query().unwrap_or_default();
let filter = serde_urlencoded::de::from_str::<PartsQuery>(query).unwrap();
diff --git a/src/templates/base.hbs b/src/templates/base.hbs
index 410a5b2..34f435b 100644
--- a/src/templates/base.hbs
+++ b/src/templates/base.hbs
@@ -42,10 +42,12 @@
flex-direction: column;
background-color: var(--balboa);
padding: 0.5em;
+ color: white;
}
aside button {
font-size: 1em;
+ padding: 0.5em 0.5em;
display: block;
background: none;
border: 0 none;
@@ -61,11 +63,11 @@
padding: 0.5em;
}
- #hidden:target aside {
+ #hidemenu:target aside {
display: none;
}
- #hidden:target a.openMenu {
+ #hidemenu:target a.openMenu {
display: block;
}
@@ -73,7 +75,7 @@
display: none;
}
- #hidden:target a.closeMenu {
+ #hidemenu:target a.closeMenu {
display: none;
}
@@ -148,7 +150,7 @@
</style>
</head>
-<body id="hidden">
+<body id="hidemenu">
<nav>
<a href="/">Index</a>
<a href="#">Parts</a>
diff --git a/src/templates/favicon.svg b/src/templates/favicon.svg
new file mode 100644
index 0000000..4ad400c
--- /dev/null
+++ b/src/templates/favicon.svg
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24">
+ <path fill="#195970" d="M17.5 14.33C18.29 14.33 19.13 14.41 20 14.57V16.07C19.38 15.91 18.54 15.83 17.5 15.83C15.6 15.83 14.11 16.16 13 16.82V15.13C14.17 14.6 15.67 14.33 17.5 14.33M13 12.46C14.29 11.93 15.79 11.67 17.5 11.67C18.29 11.67 19.13 11.74 20 11.9V13.4C19.38 13.24 18.54 13.16 17.5 13.16C15.6 13.16 14.11 13.5 13 14.15M17.5 10.5C15.6 10.5 14.11 10.82 13 11.5V9.84C14.23 9.28 15.73 9 17.5 9C18.29 9 19.13 9.08 20 9.23V10.78C19.26 10.59 18.41 10.5 17.5 10.5M21 18.5V7C19.96 6.67 18.79 6.5 17.5 6.5C15.45 6.5 13.62 7 12 8V19.5C13.62 18.5 15.45 18 17.5 18C18.69 18 19.86 18.16 21 18.5M17.5 4.5C19.85 4.5 21.69 5 23 6V20.56C23 20.68 22.95 20.8 22.84 20.91C22.73 21 22.61 21.08 22.5 21.08C22.39 21.08 22.31 21.06 22.25 21.03C20.97 20.34 19.38 20 17.5 20C15.45 20 13.62 20.5 12 21.5C10.66 20.5 8.83 20 6.5 20C4.84 20 3.25 20.36 1.75 21.07C1.72 21.08 1.68 21.08 1.63 21.1C1.59 21.11 1.55 21.12 1.5 21.12C1.39 21.12 1.27 21.08 1.16 21C1.05 20.89 1 20.78 1 20.65V6C2.34 5 4.18 4.5 6.5 4.5C8.83 4.5 10.66 5 12 6C13.34 5 15.17 4.5 17.5 4.5Z" />
+</svg>
diff --git a/src/templates/index.hbs b/src/templates/index.hbs
index d9b3728..4c07db4 100644
--- a/src/templates/index.hbs
+++ b/src/templates/index.hbs
@@ -1,12 +1,13 @@
{{#> base}}
{{#*inline "main"}}
<aside>
- <a class="closeMenu" href="#hidden">
+ <a class="closeMenu" href="#hidemenu">
<svg style="width: 24px; height: 24px" viewBox="0 0 24 24">
<path fill="#ffffff"
d="M21,15.61L19.59,17L14.58,12L19.59,7L21,8.39L17.44,12L21,15.61M3,6H16V8H3V6M3,13V11H13V13H3M3,18V16H16V18H3Z" />
</svg>
</a>
+
{{#each makes}}
<form action="/">
{{#if (eq this ../selected_make)}}
@@ -43,6 +44,8 @@
</svg>
</a>
+ <h2>Catalog</h2>
+
<section>
<form>
{{#if selected_make}}
diff --git a/src/templates/mod.rs b/src/templates/mod.rs
index 8b8f156..99e3bf3 100644
--- a/src/templates/mod.rs
+++ b/src/templates/mod.rs
@@ -15,3 +15,5 @@ lazy_static! {
handlebars
};
}
+
+pub static FAVICON: &str = include_str!("favicon.svg");