diff --git a/.woodpecker/build.yml b/.woodpecker/build.yml index 7adfe62..5779344 100644 --- a/.woodpecker/build.yml +++ b/.woodpecker/build.yml @@ -5,7 +5,7 @@ branches: pipeline: build: - image: 'rust:1.76' + image: 'rust:1.69' commands: - cargo build --verbose - cargo test --verbose diff --git a/.woodpecker/clippy.yml b/.woodpecker/clippy.yml index d34cdf6..92851e5 100644 --- a/.woodpecker/clippy.yml +++ b/.woodpecker/clippy.yml @@ -5,7 +5,7 @@ branches: pipeline: clippy: - image: 'rust:1.76' + image: 'rust:1.69' commands: - rustup component add clippy - cargo clippy -- --no-deps -Dwarnings diff --git a/.woodpecker/deploy.yml b/.woodpecker/deploy.yml index 7be1e36..1fd44e2 100644 --- a/.woodpecker/deploy.yml +++ b/.woodpecker/deploy.yml @@ -14,9 +14,9 @@ pipeline: - 'docker_username' - 'docker_password' - # deploy: - # image: 'curlimages/curl' - # secrets: - # - 'webhook' - # commands: - # - curl -XPOST --fail -s "$WEBHOOK" + deploy: + image: 'curlimages/curl' + secrets: + - 'webhook' + commands: + - curl -XPOST --fail -s "$WEBHOOK" diff --git a/.woodpecker/lint.yml b/.woodpecker/lint.yml index 89c1d62..ad2b612 100644 --- a/.woodpecker/lint.yml +++ b/.woodpecker/lint.yml @@ -5,7 +5,7 @@ branches: pipeline: lint: - image: 'rust:1.76' + image: 'rust:1.69' commands: - rustup component add rustfmt - cargo fmt -- --check diff --git a/Cargo.lock b/Cargo.lock index 31b1f33..1237a05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,11 +23,9 @@ name = "affluences-cli" version = "0.1.0" dependencies = [ "affluences-api", - "chrono", "clap", "serde_json", "tokio", - "uuid", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b41350e..518d125 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,10 +26,3 @@ diesel = { version = "2.0.4", features = ["sqlite", "returning_clauses_for_sqlit diesel_migrations = { version = "2.0.0", features = [ "sqlite" ] } # Force sqlite3 to be bundled, allowing for a fully static binary libsqlite3-sys = { version = "*", features = ["bundled"] } - -# https://stackoverflow.com/a/54842093 -[profile.release] -lto = true # Enable link-time optimization -codegen-units = 1 # Reduce number of codegen units to increase optimizations -panic = 'abort' # Abort on panic -strip = true # Strip symbols from binary* diff --git a/Dockerfile b/Dockerfile index 12e9300..b2cbacc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.76-alpine AS builder +FROM rust:1.69-alpine AS builder ARG DI_VER=1.2.5 @@ -25,9 +25,6 @@ FROM busybox:1.36.0 COPY --from=builder /build/dumb-init /build/affy/target/release/affy /bin/ -RUN mkdir /data && \ - chown -R www-data:www-data /data - WORKDIR /data ENV TZ=Europe/Brussels diff --git a/affluences-api/src/models/available.rs b/affluences-api/src/models/available.rs index ced3836..e10052c 100644 --- a/affluences-api/src/models/available.rs +++ b/affluences-api/src/models/available.rs @@ -1,19 +1,12 @@ use super::hh_mm_time_format; use chrono::{Duration, NaiveTime}; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; -#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] -#[serde(rename_all = "lowercase")] -pub enum ResourceState { - Available, - Full, -} - -#[derive(Serialize, Deserialize, Debug, Clone, Copy)] +#[derive(Deserialize, Debug, Clone, Copy)] pub struct HourBlock { #[serde(with = "hh_mm_time_format")] pub hour: NaiveTime, - pub state: ResourceState, + pub state: u32, // reservations pub granularity: u32, pub person_count: u32, @@ -21,7 +14,7 @@ pub struct HourBlock { pub places_bookable: u32, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct Resource { pub resource_id: u32, pub resource_name: String, @@ -45,7 +38,7 @@ pub struct Resource { // max_places_per_reservation pub image_url: Option, // services - pub slots_state: ResourceState, + pub slots_state: u32, pub hours: Vec, } @@ -77,18 +70,13 @@ impl Resource { pub fn condensed_available_hours(&self) -> Vec<(&HourBlock, Duration)> { self.condensed_hours() .into_iter() - .filter(|(hour, _)| hour.state == ResourceState::Available) + .filter(|(hour, _)| hour.state == 1) .collect() } /// Returns whether a slot with the given state and time bounds is present in the list of /// hours. - pub fn has_slot( - &self, - start_time: NaiveTime, - end_time: NaiveTime, - state: ResourceState, - ) -> bool { + pub fn has_slot(&self, start_time: NaiveTime, end_time: NaiveTime, state: u32) -> bool { self.condensed_hours() .into_iter() .filter(|(block, _)| block.state == state) diff --git a/affluences-cli/Cargo.toml b/affluences-cli/Cargo.toml index f9aa8b1..f46a340 100644 --- a/affluences-cli/Cargo.toml +++ b/affluences-cli/Cargo.toml @@ -10,5 +10,3 @@ affluences-api = { path = "../affluences-api" } clap = { version = "4.2.7", features = ["derive"] } serde_json = "1.0.96" tokio = { version = "1.28.1", features = ["full"] } -uuid = "*" -chrono = "*" diff --git a/affluences-cli/src/main.rs b/affluences-cli/src/main.rs index afd9b29..3b31cb5 100644 --- a/affluences-cli/src/main.rs +++ b/affluences-cli/src/main.rs @@ -1,9 +1,5 @@ use affluences_api::AffluencesClient; -use chrono::NaiveDate; use clap::{Parser, Subcommand}; -use uuid::{uuid, Uuid}; - -const STERRE_BIB_ID: Uuid = uuid!("4737e57a-ee05-4f7b-901a-7bb541eeb297"); #[derive(Parser)] #[command(author, version, about, long_about = None)] @@ -15,10 +11,7 @@ struct Cli { #[derive(Subcommand)] enum Commands { /// does testing things - SearchSite { - query: String, - }, - Available, + SearchSite { query: String }, } #[tokio::main] @@ -32,14 +25,6 @@ async fn main() { let s = serde_json::to_string_pretty(&res).unwrap(); 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 => {} } } diff --git a/build.rs b/build.rs index 3a8149e..508b53c 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,3 @@ fn main() { - println!("cargo:rerun-if-changed=migrations"); + println!("cargo:rerun-if-changed=migrations"); } diff --git a/src/commands/bib.rs b/src/commands/bib.rs index f5f68f7..32fbbe2 100644 --- a/src/commands/bib.rs +++ b/src/commands/bib.rs @@ -2,7 +2,7 @@ use crate::commands::{EmbedField, HumanNaiveDate}; use crate::db::users::User; use crate::{Context, Error}; -use affluences_api::{Reservation, Resource, ResourceState}; +use affluences_api::{Reservation, Resource}; use chrono::{NaiveDate, NaiveTime}; use uuid::{uuid, Uuid}; @@ -48,22 +48,25 @@ fn resource_to_embed_field(resource: Resource) -> EmbedField { #[poise::command(prefix_command, slash_command)] pub async fn available(ctx: Context<'_>, date: HumanNaiveDate) -> Result<(), Error> { let client = &ctx.data().client; - let date: NaiveDate = date.into(); - - let mut resources = client.available(STERRE_BIB_ID, date, 1).await?; + let mut resources = client + .available(STERRE_BIB_ID, date.clone().into(), 1) + .await?; // Cloning here isn't super efficient, but this list only consists of a handful of elements so // it's fine resources.sort_by_key(|k| k.resource_name.clone()); ctx.send(|f| { f.embed(|e| { - e.description(format!("Available booking dates for {}.", date)) - .fields( - resources - .into_iter() - .map(resource_to_embed_field) - .collect::>(), - ) + e.description(format!( + "Available booking dates for {}.", + Into::::into(date) + )) + .fields( + resources + .into_iter() + .map(resource_to_embed_field) + .collect::>(), + ) }) }) .await?; @@ -88,7 +91,6 @@ pub async fn book( let guild_id = ctx.guild_id().unwrap(); let discord_id = ctx.author().id.0 as i64; - let date: NaiveDate = date.into(); let user = { let mut conn = ctx.data().pool.get()?; @@ -105,17 +107,19 @@ pub async fn book( let user = user.unwrap(); let client = &ctx.data().client; - let resources = client.available(STERRE_BIB_ID, date, 1).await?; + let resources = client + .available(STERRE_BIB_ID, date.clone().into(), 1) + .await?; let chosen_resource = resources .iter() .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 { let reservation = Reservation { auth_type: None, email: user.email.clone(), - date, + date: date.clone().into(), start_time, end_time, note: "coworking space".to_string(), @@ -132,7 +136,7 @@ pub async fn book( ctx.send(|f| { f.embed(|e| { e.description("A new reservation has been made.") - .field("when", format!("{} {} - {}", date, start_time.format(TIME_FORMAT), end_time.format(TIME_FORMAT)), false) + .field("when", format!("{} {} - {}", Into::::into(date), start_time.format(TIME_FORMAT), end_time.format(TIME_FORMAT)), false) .field("where", &chosen_resource.resource_name, false) .footer(|ft| ft.text( format!("A confirmation mail has been sent to {}. Please check your email and confirm your reservation within two hours.", user.email)))