Compare commits

..

No commits in common. "80f2bb8f0e884eaf49696672a7487fedce442c67" and "fa24625a1f75c168bcb107ecab1fd14f27ddfcce" have entirely different histories.

7 changed files with 16 additions and 50 deletions

View File

@ -14,9 +14,9 @@ pipeline:
- 'docker_username' - 'docker_username'
- 'docker_password' - 'docker_password'
# deploy: deploy:
# image: 'curlimages/curl' image: 'curlimages/curl'
# secrets: secrets:
# - 'webhook' - 'webhook'
# commands: commands:
# - curl -XPOST --fail -s "$WEBHOOK" - curl -XPOST --fail -s "$WEBHOOK"

2
Cargo.lock generated
View File

@ -23,11 +23,9 @@ name = "affluences-cli"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"affluences-api", "affluences-api",
"chrono",
"clap", "clap",
"serde_json", "serde_json",
"tokio", "tokio",
"uuid",
] ]
[[package]] [[package]]

View File

@ -25,9 +25,6 @@ FROM busybox:1.36.0
COPY --from=builder /build/dumb-init /build/affy/target/release/affy /bin/ COPY --from=builder /build/dumb-init /build/affy/target/release/affy /bin/
RUN mkdir /data && \
chown -R www-data:www-data /data
WORKDIR /data WORKDIR /data
ENV TZ=Europe/Brussels ENV TZ=Europe/Brussels

View File

@ -1,19 +1,12 @@
use super::hh_mm_time_format; use super::hh_mm_time_format;
use chrono::{Duration, NaiveTime}; use chrono::{Duration, NaiveTime};
use serde::{Deserialize, Serialize}; use serde::Deserialize;
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] #[derive(Deserialize, Debug, Clone, Copy)]
#[serde(rename_all = "lowercase")]
pub enum ResourceState {
Available,
Full,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct HourBlock { pub struct HourBlock {
#[serde(with = "hh_mm_time_format")] #[serde(with = "hh_mm_time_format")]
pub hour: NaiveTime, pub hour: NaiveTime,
pub state: ResourceState, pub state: u32,
// reservations // reservations
pub granularity: u32, pub granularity: u32,
pub person_count: u32, pub person_count: u32,
@ -21,7 +14,7 @@ pub struct HourBlock {
pub places_bookable: u32, pub places_bookable: u32,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Deserialize, Debug)]
pub struct Resource { pub struct Resource {
pub resource_id: u32, pub resource_id: u32,
pub resource_name: String, pub resource_name: String,
@ -45,7 +38,7 @@ pub struct Resource {
// max_places_per_reservation // max_places_per_reservation
pub image_url: Option<String>, pub image_url: Option<String>,
// services // services
pub slots_state: ResourceState, pub slots_state: u32,
pub hours: Vec<HourBlock>, pub hours: Vec<HourBlock>,
} }
@ -77,18 +70,13 @@ impl Resource {
pub fn condensed_available_hours(&self) -> Vec<(&HourBlock, Duration)> { pub fn condensed_available_hours(&self) -> Vec<(&HourBlock, Duration)> {
self.condensed_hours() self.condensed_hours()
.into_iter() .into_iter()
.filter(|(hour, _)| hour.state == ResourceState::Available) .filter(|(hour, _)| hour.state == 1)
.collect() .collect()
} }
/// Returns whether a slot with the given state and time bounds is present in the list of /// Returns whether a slot with the given state and time bounds is present in the list of
/// hours. /// hours.
pub fn has_slot( pub fn has_slot(&self, start_time: NaiveTime, end_time: NaiveTime, state: u32) -> bool {
&self,
start_time: NaiveTime,
end_time: NaiveTime,
state: ResourceState,
) -> bool {
self.condensed_hours() self.condensed_hours()
.into_iter() .into_iter()
.filter(|(block, _)| block.state == state) .filter(|(block, _)| block.state == state)

View File

@ -10,5 +10,3 @@ affluences-api = { path = "../affluences-api" }
clap = { version = "4.2.7", features = ["derive"] } clap = { version = "4.2.7", features = ["derive"] }
serde_json = "1.0.96" serde_json = "1.0.96"
tokio = { version = "1.28.1", features = ["full"] } tokio = { version = "1.28.1", features = ["full"] }
uuid = "*"
chrono = "*"

View File

@ -1,9 +1,5 @@
use affluences_api::AffluencesClient; use affluences_api::AffluencesClient;
use chrono::NaiveDate;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use uuid::{uuid, Uuid};
const STERRE_BIB_ID: Uuid = uuid!("4737e57a-ee05-4f7b-901a-7bb541eeb297");
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
@ -15,10 +11,7 @@ struct Cli {
#[derive(Subcommand)] #[derive(Subcommand)]
enum Commands { enum Commands {
/// does testing things /// does testing things
SearchSite { SearchSite { query: String },
query: String,
},
Available,
} }
#[tokio::main] #[tokio::main]
@ -32,14 +25,6 @@ async fn main() {
let s = serde_json::to_string_pretty(&res).unwrap(); let s = serde_json::to_string_pretty(&res).unwrap();
println!("{}", s); println!("{}", s);
} }
Some(Commands::Available) => {
let res = client
.available(STERRE_BIB_ID, chrono::Utc::now().naive_utc().date(), 1)
.await
.unwrap();
let s = serde_json::to_string_pretty(&res).unwrap();
println!("{}", s);
}
None => {} None => {}
} }
} }

View File

@ -2,7 +2,7 @@ use crate::commands::{EmbedField, HumanNaiveDate};
use crate::db::users::User; use crate::db::users::User;
use crate::{Context, Error}; use crate::{Context, Error};
use affluences_api::{Reservation, Resource, ResourceState}; use affluences_api::{Reservation, Resource};
use chrono::{NaiveDate, NaiveTime}; use chrono::{NaiveDate, NaiveTime};
use uuid::{uuid, Uuid}; use uuid::{uuid, Uuid};
@ -109,7 +109,7 @@ pub async fn book(
let chosen_resource = resources let chosen_resource = resources
.iter() .iter()
.filter(|r| capacity.is_none() || capacity.unwrap() <= r.capacity) .filter(|r| capacity.is_none() || capacity.unwrap() <= r.capacity)
.find(|r| r.has_slot(start_time, end_time, ResourceState::Available)); .find(|r| r.has_slot(start_time, end_time, 1));
if let Some(chosen_resource) = chosen_resource { if let Some(chosen_resource) = chosen_resource {
let reservation = Reservation { let reservation = Reservation {