Compare commits

..

No commits in common. "02ef91088022cb234bb9ceee15f6f3e844be43f5" and "78185cd40d11ca82b504e316558cc523e7a8afa7" have entirely different histories.

8 changed files with 65 additions and 67 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "huellas"
version = "0.1.1"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -1,10 +1,8 @@
##### Builder ####
FROM rust:1.64-alpine as builder
FROM rust:1.62-slim-bullseye as builder
RUN apk add --no-cache sqlite npm musl-dev
# Install Typescript
RUN npm install -g typescript
RUN apt-get update && apt-get -y upgrade
RUN apt-get -y install --no-install-recommends sqlite3 libsqlite3-dev npm && rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src
@ -20,6 +18,9 @@ WORKDIR /usr/src/huellas
# This is an empty build to get the dependencies cached.
RUN cargo build --release
# Install Typescript
RUN npm install -g typescript
# Now copy in the rest of the sources
COPY src /usr/src/huellas/src/
COPY migrations /usr/src/huellas/migrations/
@ -44,15 +45,12 @@ RUN npm install
# Transpile
RUN tsc
# Delete the first line of jvascript ts-client
RUN sed -i '1d' build/client.js
################
##### Runtime
FROM alpine:3.16 AS Runtime
RUN apk add --no-cache sqlite
FROM debian:bullseye-slim AS runtime
RUN apt-get update && apt-get -y upgrade
RUN apt-get -y install --no-install-recommends sqlite3 && rm -rf /var/lib/apt/lists/*
# Copy application binary from builder image
COPY --from=builder /usr/src/huellas/target/release/huellas /usr/local/bin
# Copy Rocket.toml
@ -62,6 +60,8 @@ COPY Rocket.toml /usr/local/bin
COPY static /usr/local/bin/static/
# Copy javascript client
COPY --from=builder /usr/src/huellas/ts-client/build/client.js /usr/local/bin/static
# Delete the first line of jvascript ts-client
RUN sed -i '1d' /usr/local/bin/static/client.js
# Run the application
WORKDIR /usr/local/bin

View file

@ -1,11 +1,11 @@
CREATE TABLE places (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR NOT NULL,
address VARCHAR NOT NULL,
open_hours VARCHAR NOT NULL,
icon VARCHAR NOT NULL,
description VARCHAR NOT NULL,
longitude DOUBLE NOT NULL,
latitude DOUBLE NOT NULL,
longitude REAL NOT NULL,
latitude REAL NOT NULL,
active BOOLEAN NOT NULL DEFAULT TRUE
);

View file

@ -10,35 +10,7 @@
},
"query": "UPDATE places SET (name, address, open_hours, icon, description, longitude, latitude) = (?, ?, ?, ?, ?, ?, ?)"
},
"af66ec71413501f84c7f4cb0dd732c8ebfcd3da36a5f1177918c2277a8674c28": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 1
}
},
"query": "UPDATE places SET active = FALSE WHERE id = ?"
},
"e10f7e8f125a3f60338f6c35b195517d4304304599c75e4f26f071e2a09609dc": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Int64"
}
],
"nullable": [
false
],
"parameters": {
"Right": 7
}
},
"query": "INSERT INTO places (name, address, open_hours, icon, description, longitude, latitude)VALUES (?, ?, ?, ?, ?, ?, ?)RETURNING id"
},
"fdc2eb1d98b93f2b61c756687f1a30edf2e4a74622e23b6b72a9509a9303385d": {
"8f8e9058b89c1f10360e08f8733c75e6ea2e8c15ff2c1e8a9f4a8ecd6e778642": {
"describe": {
"columns": [
{
@ -72,12 +44,12 @@
"type_info": "Text"
},
{
"name": "longitude: f64",
"name": "longitude",
"ordinal": 6,
"type_info": "Float"
},
{
"name": "latitude: f64",
"name": "latitude",
"ordinal": 7,
"type_info": "Float"
}
@ -96,6 +68,34 @@
"Right": 0
}
},
"query": "SELECT id, name, address, open_hours, icon, description,longitude as \"longitude: f64\", latitude as \"latitude: f64\" FROM places WHERE active = TRUE"
"query": "SELECT id, name, address, open_hours, icon, description, longitude, latitude FROM places WHERE active = TRUE"
},
"af66ec71413501f84c7f4cb0dd732c8ebfcd3da36a5f1177918c2277a8674c28": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 1
}
},
"query": "UPDATE places SET active = FALSE WHERE id = ?"
},
"e10f7e8f125a3f60338f6c35b195517d4304304599c75e4f26f071e2a09609dc": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Int64"
}
],
"nullable": [
false
],
"parameters": {
"Right": 7
}
},
"query": "INSERT INTO places (name, address, open_hours, icon, description, longitude, latitude)VALUES (?, ?, ?, ?, ?, ?, ?)RETURNING id"
}
}

View file

@ -9,6 +9,6 @@ pub struct Place {
pub open_hours: String,
pub icon: String,
pub description: String,
pub longitude: f64,
pub latitude: f64,
pub longitude: f32,
pub latitude: f32,
}

View file

@ -16,9 +16,7 @@ struct Db(rocket_db_pools::sqlx::SqlitePool);
#[get("/places")]
async fn get_places(mut db: Connection<Db>) -> Result<Json<Vec<Place>>> {
let places = rocket_db_pools::sqlx::query!(
"SELECT id, name, address, open_hours, icon, description," +
r#"longitude as "longitude: f64", latitude as "latitude: f64" FROM places WHERE active = TRUE"#
)
"SELECT id, name, address, open_hours, icon, description, longitude, latitude FROM places WHERE active = TRUE")
.fetch(&mut *db)
.map_ok(|p| Place {
id: Some(p.id),
@ -28,7 +26,7 @@ async fn get_places(mut db: Connection<Db>) -> Result<Json<Vec<Place>>> {
icon: p.icon,
description: p.description,
latitude: p.latitude,
longitude: p.longitude,
longitude: p.longitude
})
.try_collect::<Vec<_>>()
.await?;

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta charset=utf-8>
<title>👣 Huellas 🐾</title>
<title>Huellas</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css"
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
@ -32,6 +32,7 @@
margin: 0;
}
</style>
</head>
<body>
<div id="map"></div>

View file

@ -81,7 +81,6 @@ async function setupMap(): Promise<void> {
const icons = new Map<string, L.Icon>();
icons.set('bar', new L.Icon({ iconUrl: 'icons/bar.svg' }));
icons.set('coffee', new L.Icon({ iconUrl: 'icons/coffee.svg' }));
icons.set('cinema', new L.Icon({ iconUrl: 'icons/film.svg' }));
icons.set('dining', new L.Icon({ iconUrl: 'icons/dining.svg' }));
icons.set('food', new L.Icon({ iconUrl: 'icons/food.svg' }));
icons.set('jazz', new L.Icon({ iconUrl: 'icons/saxophone.svg' }));