Compare commits
10 Commits
bib-bookin
...
dev
Author | SHA1 | Date |
---|---|---|
Jef Roosens | 81f052ecbc | |
Jef Roosens | 80f2bb8f0e | |
Jef Roosens | 7fd6d55e71 | |
Jef Roosens | 83e9d3e8cf | |
Jef Roosens | 7467b1f588 | |
Jef Roosens | c33cec3af5 | |
Jef Roosens | fa24625a1f | |
Jef Roosens | c8ef995bc0 | |
Jef Roosens | 1eef50c999 | |
Jef Roosens | 4380074a75 |
|
@ -5,7 +5,7 @@ branches:
|
||||||
|
|
||||||
pipeline:
|
pipeline:
|
||||||
build:
|
build:
|
||||||
image: 'rust:1.69'
|
image: 'rust:1.76'
|
||||||
commands:
|
commands:
|
||||||
- cargo build --verbose
|
- cargo build --verbose
|
||||||
- cargo test --verbose
|
- cargo test --verbose
|
||||||
|
|
|
@ -5,7 +5,7 @@ branches:
|
||||||
|
|
||||||
pipeline:
|
pipeline:
|
||||||
clippy:
|
clippy:
|
||||||
image: 'rust:1.69'
|
image: 'rust:1.76'
|
||||||
commands:
|
commands:
|
||||||
- rustup component add clippy
|
- rustup component add clippy
|
||||||
- cargo clippy -- --no-deps -Dwarnings
|
- cargo clippy -- --no-deps -Dwarnings
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -5,7 +5,7 @@ branches:
|
||||||
|
|
||||||
pipeline:
|
pipeline:
|
||||||
lint:
|
lint:
|
||||||
image: 'rust:1.69'
|
image: 'rust:1.76'
|
||||||
commands:
|
commands:
|
||||||
- rustup component add rustfmt
|
- rustup component add rustfmt
|
||||||
- cargo fmt -- --check
|
- cargo fmt -- --check
|
||||||
|
|
|
@ -23,9 +23,11 @@ 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]]
|
||||||
|
|
|
@ -26,3 +26,10 @@ diesel = { version = "2.0.4", features = ["sqlite", "returning_clauses_for_sqlit
|
||||||
diesel_migrations = { version = "2.0.0", features = [ "sqlite" ] }
|
diesel_migrations = { version = "2.0.0", features = [ "sqlite" ] }
|
||||||
# Force sqlite3 to be bundled, allowing for a fully static binary
|
# Force sqlite3 to be bundled, allowing for a fully static binary
|
||||||
libsqlite3-sys = { version = "*", features = ["bundled"] }
|
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*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM rust:1.69-alpine AS builder
|
FROM rust:1.76-alpine AS builder
|
||||||
|
|
||||||
ARG DI_VER=1.2.5
|
ARG DI_VER=1.2.5
|
||||||
|
|
||||||
|
@ -25,6 +25,9 @@ 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
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
use super::hh_mm_time_format;
|
use super::hh_mm_time_format;
|
||||||
use chrono::{Duration, NaiveTime};
|
use chrono::{Duration, NaiveTime};
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone, Copy)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
|
||||||
|
#[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: u32,
|
pub state: ResourceState,
|
||||||
// reservations
|
// reservations
|
||||||
pub granularity: u32,
|
pub granularity: u32,
|
||||||
pub person_count: u32,
|
pub person_count: u32,
|
||||||
|
@ -14,7 +21,7 @@ pub struct HourBlock {
|
||||||
pub places_bookable: u32,
|
pub places_bookable: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Resource {
|
pub struct Resource {
|
||||||
pub resource_id: u32,
|
pub resource_id: u32,
|
||||||
pub resource_name: String,
|
pub resource_name: String,
|
||||||
|
@ -38,7 +45,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: u32,
|
pub slots_state: ResourceState,
|
||||||
pub hours: Vec<HourBlock>,
|
pub hours: Vec<HourBlock>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,13 +77,18 @@ 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 == 1)
|
.filter(|(hour, _)| hour.state == ResourceState::Available)
|
||||||
.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(&self, start_time: NaiveTime, end_time: NaiveTime, state: u32) -> bool {
|
pub fn has_slot(
|
||||||
|
&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)
|
||||||
|
|
|
@ -10,3 +10,5 @@ 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 = "*"
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
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)]
|
||||||
|
@ -11,7 +15,10 @@ struct Cli {
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
/// does testing things
|
/// does testing things
|
||||||
SearchSite { query: String },
|
SearchSite {
|
||||||
|
query: String,
|
||||||
|
},
|
||||||
|
Available,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -25,6 +32,14 @@ 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 => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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};
|
use affluences_api::{Reservation, Resource, ResourceState};
|
||||||
use chrono::{NaiveDate, NaiveTime};
|
use chrono::{NaiveDate, NaiveTime};
|
||||||
use uuid::{uuid, Uuid};
|
use uuid::{uuid, Uuid};
|
||||||
|
|
||||||
|
@ -48,19 +48,16 @@ fn resource_to_embed_field(resource: Resource) -> EmbedField {
|
||||||
#[poise::command(prefix_command, slash_command)]
|
#[poise::command(prefix_command, slash_command)]
|
||||||
pub async fn available(ctx: Context<'_>, date: HumanNaiveDate) -> Result<(), Error> {
|
pub async fn available(ctx: Context<'_>, date: HumanNaiveDate) -> Result<(), Error> {
|
||||||
let client = &ctx.data().client;
|
let client = &ctx.data().client;
|
||||||
let mut resources = client
|
let date: NaiveDate = date.into();
|
||||||
.available(STERRE_BIB_ID, date.clone().into(), 1)
|
|
||||||
.await?;
|
let mut resources = client.available(STERRE_BIB_ID, date, 1).await?;
|
||||||
// Cloning here isn't super efficient, but this list only consists of a handful of elements so
|
// Cloning here isn't super efficient, but this list only consists of a handful of elements so
|
||||||
// it's fine
|
// it's fine
|
||||||
resources.sort_by_key(|k| k.resource_name.clone());
|
resources.sort_by_key(|k| k.resource_name.clone());
|
||||||
|
|
||||||
ctx.send(|f| {
|
ctx.send(|f| {
|
||||||
f.embed(|e| {
|
f.embed(|e| {
|
||||||
e.description(format!(
|
e.description(format!("Available booking dates for {}.", date))
|
||||||
"Available booking dates for {}.",
|
|
||||||
Into::<NaiveDate>::into(date)
|
|
||||||
))
|
|
||||||
.fields(
|
.fields(
|
||||||
resources
|
resources
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -91,6 +88,7 @@ pub async fn book(
|
||||||
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
let discord_id = ctx.author().id.0 as i64;
|
let discord_id = ctx.author().id.0 as i64;
|
||||||
|
let date: NaiveDate = date.into();
|
||||||
|
|
||||||
let user = {
|
let user = {
|
||||||
let mut conn = ctx.data().pool.get()?;
|
let mut conn = ctx.data().pool.get()?;
|
||||||
|
@ -107,19 +105,17 @@ pub async fn book(
|
||||||
let user = user.unwrap();
|
let user = user.unwrap();
|
||||||
|
|
||||||
let client = &ctx.data().client;
|
let client = &ctx.data().client;
|
||||||
let resources = client
|
let resources = client.available(STERRE_BIB_ID, date, 1).await?;
|
||||||
.available(STERRE_BIB_ID, date.clone().into(), 1)
|
|
||||||
.await?;
|
|
||||||
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, 1));
|
.find(|r| r.has_slot(start_time, end_time, ResourceState::Available));
|
||||||
|
|
||||||
if let Some(chosen_resource) = chosen_resource {
|
if let Some(chosen_resource) = chosen_resource {
|
||||||
let reservation = Reservation {
|
let reservation = Reservation {
|
||||||
auth_type: None,
|
auth_type: None,
|
||||||
email: user.email.clone(),
|
email: user.email.clone(),
|
||||||
date: date.clone().into(),
|
date,
|
||||||
start_time,
|
start_time,
|
||||||
end_time,
|
end_time,
|
||||||
note: "coworking space".to_string(),
|
note: "coworking space".to_string(),
|
||||||
|
@ -136,7 +132,7 @@ pub async fn book(
|
||||||
ctx.send(|f| {
|
ctx.send(|f| {
|
||||||
f.embed(|e| {
|
f.embed(|e| {
|
||||||
e.description("A new reservation has been made.")
|
e.description("A new reservation has been made.")
|
||||||
.field("when", format!("{} {} - {}", Into::<NaiveDate>::into(date), start_time.format(TIME_FORMAT), end_time.format(TIME_FORMAT)), false)
|
.field("when", format!("{} {} - {}", date, start_time.format(TIME_FORMAT), end_time.format(TIME_FORMAT)), false)
|
||||||
.field("where", &chosen_resource.resource_name, false)
|
.field("where", &chosen_resource.resource_name, false)
|
||||||
.footer(|ft| ft.text(
|
.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)))
|
format!("A confirmation mail has been sent to {}. Please check your email and confirm your reservation within two hours.", user.email)))
|
||||||
|
|
Loading…
Reference in New Issue