Verified Commit 9b500364 authored by Ole Martin Ruud's avatar Ole Martin Ruud
Browse files

Add additional options to query

parent a99419b8
......@@ -344,6 +344,11 @@ dependencies = [
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "data-encoding"
version = "2.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "derive_builder"
version = "0.7.2"
......@@ -583,11 +588,10 @@ dependencies = [
"reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)",
"rpassword 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_qs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_yaml 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)",
"snafu 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"strum 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"strum_macros 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unhtml 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -1507,6 +1511,17 @@ dependencies = [
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_qs"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_urlencoded"
version = "0.5.5"
......@@ -1648,22 +1663,6 @@ dependencies = [
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "strum"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "strum_macros"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "0.15.44"
......@@ -2167,6 +2166,7 @@ dependencies = [
"checksum darling 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fcfbcb0c5961907597a7d1148e3af036268f2b773886b8bb3eeb1e1281d3d3d6"
"checksum darling_core 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6afc018370c3bff3eb51f89256a6bdb18b4fdcda72d577982a14954a7a0b402c"
"checksum darling_macro 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c6d8dac1c6f1d29a41c4712b4400f878cb4fcc4c7628f298dd75038e024998d1"
"checksum data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4f47ca1860a761136924ddd2422ba77b2ea54fe8cc75b9040804a0d9d32ad97"
"checksum derive_builder 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ac53fa6a3cda160df823a9346442525dcaf1e171999a1cf23e67067e4fd64d4"
"checksum derive_builder_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0288a23da9333c246bb18c143426074a6ae96747995c5819d2947b64cd942b37"
"checksum derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a141330240c921ec6d074a3e188a7c7ef95668bb95e7d44fa0e5778ec2a7afe"
......@@ -2296,6 +2296,7 @@ dependencies = [
"checksum serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "fec2851eb56d010dc9a21b89ca53ee75e6528bab60c11e89d38390904982da9f"
"checksum serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "cb4dc18c61206b08dc98216c98faa0232f4337e1e1b8574551d5bad29ea1b425"
"checksum serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704"
"checksum serde_qs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b232c387059b62b17eb0487bf23de3ddf21b648ad2206fadc6ff3af9e2f3c07"
"checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a"
"checksum serde_yaml 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)" = "38b08a9a90e5260fe01c6480ec7c811606df6d3a660415808c3c3fa8ed95b582"
"checksum servo_arc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d98238b800e0d1576d8b6e3de32827c2d74bee68bb97748dcf5071fb53965432"
......@@ -2313,8 +2314,6 @@ dependencies = [
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
"checksum structopt 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "48399718b3ad695558b979b08a9056a5272ec573cd3070f5ca34165bd4a5bf35"
"checksum structopt-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2558075232402034384db060831349fb2d1303479593177cc84c25febbebbc6d"
"checksum strum 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e5d1c33039533f051704951680f1adfd468fd37ac46816ded0d9ee068e60f05f"
"checksum strum_macros 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "47cd23f5c7dee395a00fa20135e2ec0fffcdfa151c56182966d7a3261343432e"
"checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
......
......@@ -16,10 +16,9 @@ log = "0.4.8"
reqwest = "0.9.20"
serde = { version = "1.0.99", features = ["derive"] }
serde_yaml = "0.8.9"
serde_qs = "0.5.0"
snafu = "0.5.0"
structopt = "0.3.0"
unhtml = { version = "0.7.3", features = ["derive"] }
rpassword = "4.0.1"
lazy_static = "1.4.0"
strum = "0.15.0"
strum_macros = "0.15.0"
use log::*;
use reqwest::{Client, Request, Response};
use reqwest::{
header::{HeaderValue, CONTENT_TYPE},
Client, Request, Response,
};
use snafu::{IntoError, OptionExt, ResultExt};
use std::fs::File;
use std::string::ToString;
......@@ -290,7 +293,12 @@ impl App {
let req = self
.client
.post(self.config.base_url.clone())
.form(&query)
// TODO workaround using serde_qs because serde_urlencoded does not support vectors
.body(serde_qs::to_string(&query).context(QsError { name: "query" })?)
.header(
CONTENT_TYPE,
HeaderValue::from_static("application/x-www-form-urlencoded"),
)
.build()
.context(RequestBuildError)?;
let mut res = self.request(req)?;
......
......@@ -40,6 +40,11 @@ pub enum Error {
name: String,
source: serde_yaml::Error,
},
#[snafu(display("Unable to {{de,}}serialize '{}' to query string: {}", name, source))]
QsError {
name: String,
source: serde_qs::Error,
},
#[snafu(display("Unable to authenticate to service: {}", msg))]
AuthError { msg: String },
}
......@@ -6,7 +6,6 @@ use snafu::ResultExt;
use std::error::Error;
use std::fs::File;
use structopt::StructOpt;
use strum_macros::{EnumString, IntoStaticStr};
pub mod app;
pub mod auth;
......@@ -33,10 +32,7 @@ lazy_static::lazy_static! {
pub struct Opts {
#[structopt(short, help = "FEIDE username (overrides `grupperom.yml`)")]
username: Option<String>,
#[structopt(
short,
help = "Should prompt for FEIDE password (overrides `grupperom.yml`)"
)]
#[structopt(short, help = "Prompt for FEIDE password (overrides `grupperom.yml`)")]
password: bool,
#[structopt(
short,
......@@ -69,7 +65,7 @@ pub struct Opts {
struct Timeslot {
#[structopt(short, long, help = "Day to order room (YYYY-MM-DD)", default_value = &TODAY)]
day: chrono::NaiveDate,
#[structopt(short, long, help = "Hour to order room from (HH:MM)", default_value = &NOW, parse(try_from_str = parse_hour))]
#[structopt(short = "H", long, help = "Hour to order room from (HH:MM)", default_value = &NOW, parse(try_from_str = parse_hour))]
hour: chrono::NaiveTime,
#[structopt(
short = "D",
......@@ -129,6 +125,10 @@ enum Command {
area: Option<String>,
#[structopt(short, long, help = "Building code (see options)")]
building: Option<String>,
#[structopt(short, long, help = "Room type code (see options)")]
room_type: Option<String>,
#[structopt(short, long, help = "Equipment codes (see options)")]
equipments: Vec<String>,
#[structopt(short, long, help = "Minimum size of room")]
size: Option<usize>,
},
......@@ -181,8 +181,10 @@ fn run() -> Result<()> {
match opts.command {
Options { fresh, option_type } => app.options(fresh, option_type),
Query {
building,
area,
building,
room_type,
equipments,
size,
timeslot:
Timeslot {
......@@ -203,6 +205,8 @@ fn run() -> Result<()> {
area.as_ref().map(|a| query_room_builder.area(a));
building.as_ref().map(|b| query_room_builder.building(b));
size.as_ref().map(|&s| query_room_builder.size(s));
room_type.as_ref().map(|r| query_room_builder.roomtype(r));
query_room_builder.equipments(equipments);
let query_room = query_room_builder
.build()
......
......@@ -33,13 +33,16 @@ pub struct QueryRoomForm {
#[html(selector = "[name=size]", attr = "value")]
#[builder(setter(into, strip_option), default)]
pub size: Option<usize>,
/// ID
#[html(
selector = "select[name=new_equipment]>option[selected]",
attr = "value"
)]
#[builder(setter(into, strip_option), default)]
pub new_equipment: Option<String>,
new_equipment: Option<String>,
/// ID
#[html(selector = r#"[name="equipment[]"]"#, attr = "value")]
#[builder(setter(into, name = "equipments"), default)]
pub equipment: Vec<String>,
/// none/'on'
#[html(selector = "[name=single_place]", attr = "checked")]
#[builder(setter(into, strip_option), default)]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment