Mercurial > lbo > hg > geohub
changeset 5:b879b0124a07
Improve API more
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Tue, 01 Dec 2020 20:05:32 +0100 |
parents | 5a0ac0fe8fb6 |
children | 6b97ebb6ee9c |
files | src/main.rs |
diffstat | 1 files changed, 7 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main.rs Tue Dec 01 20:03:31 2020 +0100 +++ b/src/main.rs Tue Dec 01 20:05:32 2020 +0100 @@ -35,21 +35,24 @@ } /// lat, long are floats -/// time is like 2020-11-30T20:12:36.444Z (ISO 8601) +/// time is like 2020-11-30T20:12:36.444Z (ISO 8601). By default, server time is set. #[rocket::get("/geo/<name>/log?<lat>&<longitude>&<time>&<s>&<ele>")] fn hello( db: DBConn, name: String, lat: f64, longitude: f64, - time: String, - s: f64, + time: Option<String>, + s: Option<f64>, ele: Option<f64>, ) -> rocket::http::Status { if name.chars().any(|c| !c.is_alphanumeric()) { return rocket::http::Status::NotAcceptable; } - let ts = flexible_timestamp_parse(time); + let mut ts = chrono::Utc::now(); + if let Some(time) = time { + ts = flexible_timestamp_parse(time).unwrap_or(ts); + } db.0.execute( "INSERT INTO geohub.geodata (id, lat, long, spd, t, ele) VALUES ($1, $2, $3, $4, $5, $6)", &[&name, &lat, &longitude, &s, &ts, &ele],