Compare commits

..

5 Commits

Author SHA1 Message Date
Jef Roosens 81f052ecbc
chore: bump rust version to 1.76
ci/woodpecker/push/build Pipeline was successful Details
ci/woodpecker/push/clippy Pipeline failed Details
ci/woodpecker/push/lint Pipeline was successful Details
ci/woodpecker/push/deploy Pipeline was successful Details
2024-02-15 14:07:06 +01:00
Jef Roosens 80f2bb8f0e
Merge branch 'dev' of git.rustybever.be:fossil/affluence into dev
ci/woodpecker/push/clippy Pipeline is pending Details
ci/woodpecker/push/lint Pipeline is pending Details
ci/woodpecker/push/build Pipeline failed Details
2024-02-15 14:02:55 +01:00
Jef Roosens 7fd6d55e71
fix: update serialization for new state string type 2024-02-15 14:00:09 +01:00
Jef Roosens fa24625a1f
chore: conform linting
ci/woodpecker/push/deploy unknown status Details
ci/woodpecker/push/lint Pipeline was successful Details
ci/woodpecker/push/clippy Pipeline was successful Details
ci/woodpecker/push/build Pipeline was successful Details
2023-05-20 21:17:01 +02:00
Jef Roosens c8ef995bc0
feat: smaller binaries
ci/woodpecker/push/deploy unknown status Details
ci/woodpecker/push/lint Pipeline failed Details
ci/woodpecker/push/clippy Pipeline failed Details
ci/woodpecker/push/build Pipeline failed Details
2023-05-20 21:13:59 +02:00
10 changed files with 51 additions and 20 deletions

View File

@ -5,7 +5,7 @@ branches:
pipeline:
build:
image: 'rust:1.69'
image: 'rust:1.76'
commands:
- cargo build --verbose
- cargo test --verbose

View File

@ -5,7 +5,7 @@ branches:
pipeline:
clippy:
image: 'rust:1.69'
image: 'rust:1.76'
commands:
- rustup component add clippy
- cargo clippy -- --no-deps -Dwarnings

View File

@ -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"

View File

@ -5,7 +5,7 @@ branches:
pipeline:
lint:
image: 'rust:1.69'
image: 'rust:1.76'
commands:
- rustup component add rustfmt
- cargo fmt -- --check

2
Cargo.lock generated
View File

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

View File

@ -1,4 +1,4 @@
FROM rust:1.69-alpine AS builder
FROM rust:1.76-alpine AS builder
ARG DI_VER=1.2.5

View File

@ -1,12 +1,19 @@
use super::hh_mm_time_format;
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 {
#[serde(with = "hh_mm_time_format")]
pub hour: NaiveTime,
pub state: u32,
pub state: ResourceState,
// reservations
pub granularity: u32,
pub person_count: u32,
@ -14,7 +21,7 @@ pub struct HourBlock {
pub places_bookable: u32,
}
#[derive(Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug)]
pub struct Resource {
pub resource_id: u32,
pub resource_name: String,
@ -38,7 +45,7 @@ pub struct Resource {
// max_places_per_reservation
pub image_url: Option<String>,
// services
pub slots_state: u32,
pub slots_state: ResourceState,
pub hours: Vec<HourBlock>,
}
@ -70,13 +77,18 @@ impl Resource {
pub fn condensed_available_hours(&self) -> Vec<(&HourBlock, Duration)> {
self.condensed_hours()
.into_iter()
.filter(|(hour, _)| hour.state == 1)
.filter(|(hour, _)| hour.state == ResourceState::Available)
.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: u32) -> bool {
pub fn has_slot(
&self,
start_time: NaiveTime,
end_time: NaiveTime,
state: ResourceState,
) -> bool {
self.condensed_hours()
.into_iter()
.filter(|(block, _)| block.state == state)

View File

@ -10,3 +10,5 @@ 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 = "*"

View File

@ -1,5 +1,9 @@
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)]
@ -11,7 +15,10 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
/// does testing things
SearchSite { query: String },
SearchSite {
query: String,
},
Available,
}
#[tokio::main]
@ -25,6 +32,14 @@ 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 => {}
}
}

View File

@ -2,7 +2,7 @@ use crate::commands::{EmbedField, HumanNaiveDate};
use crate::db::users::User;
use crate::{Context, Error};
use affluences_api::{Reservation, Resource};
use affluences_api::{Reservation, Resource, ResourceState};
use chrono::{NaiveDate, NaiveTime};
use uuid::{uuid, Uuid};
@ -109,7 +109,7 @@ pub async fn book(
let chosen_resource = resources
.iter()
.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 {
let reservation = Reservation {