Skip to content

Commit

Permalink
started on food tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
sverrejb committed Feb 8, 2024
1 parent 1c812bd commit 873ceac
Show file tree
Hide file tree
Showing 8 changed files with 1,113 additions and 79 deletions.
1,026 changes: 947 additions & 79 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rust-embed = "6.8.1"
log = "0.4.20"
env_logger = "0.10.1"
tokio = { version = "1.35.1", features = ["rt-multi-thread"] }
tide = "0.16.0"

[build-dependencies]
slint-build = "1.3.2"
File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions src/food/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<title>Tracking Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}

.container {
max-width: 400px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

h1 {
text-align: center;
color: #333;
}

form {
margin-top: 20px;
}

label {
display: block;
margin-bottom: 10px;
color: #555;
}

input[type="text"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}

input[type="submit"] {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}

input[type="submit"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<h1>Tantalizing Thursday treat tracker</h1>
<form action="/id" method="post">
<label for="tracking-url">Tracking URL:</label>
<input type="text" id="tracking-url" name="tracking-url" required>
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>
20 changes: 20 additions & 0 deletions src/food/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::{error, io::Cursor, thread};

use tide::Request;
use tokio::runtime::Runtime;

pub fn setup() {
thread::spawn(move || Runtime::new().unwrap().block_on(food_endpoint_server()));
}

async fn food_endpoint_server() -> tide::Result<()> {
let mut app = tide::new();
app.at("/id").post(get_tracking_ID);
app.at("/").serve_file("src/food/index.html")?;
app.listen("127.0.0.1:1337").await?;
Ok(())
}

async fn get_tracking_ID(mut req: Request<()>) -> tide::Result {
Ok(format!("Food!").into())
}
76 changes: 76 additions & 0 deletions src/food/wolt_models.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use serde_derive::Deserialize;
use serde_derive::Serialize;

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Root {
pub status: String,
#[serde(rename = "preorder_status")]
pub preorder_status: String,
#[serde(rename = "from_location")]
pub from_location: FromLocation,
#[serde(rename = "to_location")]
pub to_location: ToLocation,
pub couriers: Vec<Courier>,
#[serde(rename = "pre_estimate")]
pub pre_estimate: String,
#[serde(rename = "delivery_eta")]
pub delivery_eta: String,
#[serde(rename = "pickup_eta")]
pub pickup_eta: String,
#[serde(rename = "requested_dropoff_time")]
pub requested_dropoff_time: String,
#[serde(rename = "refresh_in_seconds")]
pub refresh_in_seconds: i64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FromLocation {
pub coordinates: Coordinates,
pub name: Name,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Coordinates {
pub lat: f64,
pub lon: f64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Name {
pub en: String,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ToLocation {
pub coordinates: Coordinates2,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Coordinates2 {
pub lat: f64,
pub lon: f64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Courier {
pub id: String,
pub coordinates: Coordinates3,
#[serde(rename = "vehicle_type")]
pub vehicle_type: String,
#[serde(rename = "is_delivering")]
pub is_delivering: bool,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Coordinates3 {
pub lat: f64,
pub lon: f64,
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rust_embed::RustEmbed;
use slint::{PlatformError, Timer, TimerMode};
use ui::*;

mod food;
mod weather;
mod xkcd;

Expand All @@ -26,6 +27,7 @@ fn main() -> Result<(), PlatformError> {

weather::setup(&main_window);
xkcd::setup(&main_window);
food::setup();

let clock_timer = Timer::default();
let clock_handle = main_window.as_weak();
Expand Down

0 comments on commit 873ceac

Please sign in to comment.