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] [package]
name = "huellas" name = "huellas"
version = "0.1.1" version = "0.1.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -1,10 +1,8 @@
##### Builder #### ##### 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 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/*
# Install Typescript
RUN npm install -g typescript
WORKDIR /usr/src WORKDIR /usr/src
@ -20,6 +18,9 @@ WORKDIR /usr/src/huellas
# This is an empty build to get the dependencies cached. # This is an empty build to get the dependencies cached.
RUN cargo build --release RUN cargo build --release
# Install Typescript
RUN npm install -g typescript
# Now copy in the rest of the sources # Now copy in the rest of the sources
COPY src /usr/src/huellas/src/ COPY src /usr/src/huellas/src/
COPY migrations /usr/src/huellas/migrations/ COPY migrations /usr/src/huellas/migrations/
@ -44,15 +45,12 @@ RUN npm install
# Transpile # Transpile
RUN tsc RUN tsc
# Delete the first line of jvascript ts-client
RUN sed -i '1d' build/client.js
################ ################
##### Runtime ##### Runtime
FROM alpine:3.16 AS Runtime FROM debian:bullseye-slim AS runtime
RUN apk add --no-cache sqlite
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 application binary from builder image
COPY --from=builder /usr/src/huellas/target/release/huellas /usr/local/bin COPY --from=builder /usr/src/huellas/target/release/huellas /usr/local/bin
# Copy Rocket.toml # Copy Rocket.toml
@ -62,6 +60,8 @@ COPY Rocket.toml /usr/local/bin
COPY static /usr/local/bin/static/ COPY static /usr/local/bin/static/
# Copy javascript client # Copy javascript client
COPY --from=builder /usr/src/huellas/ts-client/build/client.js /usr/local/bin/static 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 # Run the application
WORKDIR /usr/local/bin WORKDIR /usr/local/bin

View file

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

View file

@ -10,35 +10,7 @@
}, },
"query": "UPDATE places SET (name, address, open_hours, icon, description, longitude, latitude) = (?, ?, ?, ?, ?, ?, ?)" "query": "UPDATE places SET (name, address, open_hours, icon, description, longitude, latitude) = (?, ?, ?, ?, ?, ?, ?)"
}, },
"af66ec71413501f84c7f4cb0dd732c8ebfcd3da36a5f1177918c2277a8674c28": { "8f8e9058b89c1f10360e08f8733c75e6ea2e8c15ff2c1e8a9f4a8ecd6e778642": {
"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": {
"describe": { "describe": {
"columns": [ "columns": [
{ {
@ -72,12 +44,12 @@
"type_info": "Text" "type_info": "Text"
}, },
{ {
"name": "longitude: f64", "name": "longitude",
"ordinal": 6, "ordinal": 6,
"type_info": "Float" "type_info": "Float"
}, },
{ {
"name": "latitude: f64", "name": "latitude",
"ordinal": 7, "ordinal": 7,
"type_info": "Float" "type_info": "Float"
} }
@ -96,6 +68,34 @@
"Right": 0 "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 open_hours: String,
pub icon: String, pub icon: String,
pub description: String, pub description: String,
pub longitude: f64, pub longitude: f32,
pub latitude: f64, pub latitude: f32,
} }

View file

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

View file

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta charset=utf-8> <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" /> <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" <link rel="stylesheet" href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css"
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ==" integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
@ -32,6 +32,7 @@
margin: 0; margin: 0;
} }
</style> </style>
</head> </head>
<body> <body>
<div id="map"></div> <div id="map"></div>

View file

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