Compare commits

..

5 commits

Author SHA1 Message Date
Felipe Contreras
02ef910880 Bump version 2022-10-25 00:39:44 -03:00
Felipe Contreras
08364a1b5a Update Rust version and use alpine for the image. 2022-10-22 16:24:05 -03:00
Felipe Contreras
91aff930d2 Fix cinema icon. 2022-08-08 17:43:08 -04:00
Felipe Contreras
5d8b40a4c2 Prettify title 2022-08-07 00:17:19 -04:00
Felipe Contreras
2f238e8d1c Use double precision for coordinates 2022-08-06 22:21:45 -04:00
8 changed files with 67 additions and 65 deletions

View file

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

View file

@ -1,8 +1,10 @@
##### Builder ####
FROM rust:1.62-slim-bullseye as builder
FROM rust:1.64-alpine as builder
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/*
RUN apk add --no-cache sqlite npm musl-dev
# Install Typescript
RUN npm install -g typescript
WORKDIR /usr/src
@ -18,9 +20,6 @@ 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/
@ -45,12 +44,15 @@ RUN npm install
# Transpile
RUN tsc
# Delete the first line of jvascript ts-client
RUN sed -i '1d' build/client.js
################
##### Runtime
FROM debian:bullseye-slim AS runtime
FROM alpine:3.16 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 --from=builder /usr/src/huellas/target/release/huellas /usr/local/bin
# Copy Rocket.toml
@ -60,8 +62,6 @@ 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,
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name VARCHAR NOT NULL,
address VARCHAR NOT NULL,
open_hours VARCHAR NOT NULL,
icon VARCHAR NOT NULL,
description VARCHAR NOT NULL,
longitude REAL NOT NULL,
latitude REAL NOT NULL,
longitude DOUBLE NOT NULL,
latitude DOUBLE NOT NULL,
active BOOLEAN NOT NULL DEFAULT TRUE
);

View file

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

View file

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

View file

@ -16,7 +16,9 @@ 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, longitude, latitude FROM places WHERE active = TRUE")
"SELECT id, name, address, open_hours, icon, description," +
r#"longitude as "longitude: f64", latitude as "latitude: f64" FROM places WHERE active = TRUE"#
)
.fetch(&mut *db)
.map_ok(|p| Place {
id: Some(p.id),
@ -26,7 +28,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,7 +32,6 @@
margin: 0;
}
</style>
</head>
<body>
<div id="map"></div>

View file

@ -81,6 +81,7 @@ 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' }));