Add color to accommodations
This commit is contained in:
24
geneit_backend/Cargo.lock
generated
24
geneit_backend/Cargo.lock
generated
@ -1415,6 +1415,7 @@ dependencies = [
|
||||
"httpdate",
|
||||
"ical",
|
||||
"image",
|
||||
"lazy-regex",
|
||||
"lazy_static",
|
||||
"lettre",
|
||||
"light-openid",
|
||||
@ -1952,6 +1953,29 @@ version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388"
|
||||
|
||||
[[package]]
|
||||
name = "lazy-regex"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d12be4595afdf58bd19e4a9f4e24187da2a66700786ff660a418e9059937a4c"
|
||||
dependencies = [
|
||||
"lazy-regex-proc_macros",
|
||||
"once_cell",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy-regex-proc_macros"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44bcd58e6c97a7fcbaffcdc95728b393b8d98933bfadad49ed4097845b57ef0b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"syn 2.0.63",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
|
@ -10,6 +10,7 @@ log = "0.4.21"
|
||||
env_logger = "0.11.3"
|
||||
clap = { version = "4.5.4", features = ["derive", "env"] }
|
||||
lazy_static = "1.4.0"
|
||||
lazy-regex = "3.1.0"
|
||||
anyhow = "1.0.83"
|
||||
actix-web = "4.5.1"
|
||||
actix-cors = "0.7.0"
|
||||
|
@ -15,6 +15,7 @@ CREATE TABLE IF NOT EXISTS accommodations_list
|
||||
name VARCHAR(50) NOT NULL,
|
||||
need_validation BOOLEAN NOT NULL DEFAULT true,
|
||||
description text NULL,
|
||||
color VARCHAR(6) NULL,
|
||||
open_to_reservations BOOLEAN NOT NULL DEFAULT false
|
||||
);
|
||||
|
||||
|
@ -8,10 +8,12 @@ use actix_web::{web, HttpResponse};
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
enum AccommodationListControllerErr {
|
||||
#[error("Malformed name!")]
|
||||
MalformedName,
|
||||
#[error("Malformed description!")]
|
||||
MalformedDescription,
|
||||
#[error("Invalid name length!")]
|
||||
InvalidNameLength,
|
||||
#[error("Invalid description length!")]
|
||||
InvalidDescriptionLength,
|
||||
#[error("Malformed color!")]
|
||||
MalformedColor,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Clone)]
|
||||
@ -19,6 +21,7 @@ pub struct AccommodationRequest {
|
||||
pub name: String,
|
||||
pub need_validation: bool,
|
||||
pub description: Option<String>,
|
||||
pub color: Option<String>,
|
||||
pub open_to_reservations: bool,
|
||||
}
|
||||
|
||||
@ -27,17 +30,24 @@ impl AccommodationRequest {
|
||||
let c = StaticConstraints::default();
|
||||
|
||||
if !c.accommodation_name_len.validate(&self.name) {
|
||||
return Err(AccommodationListControllerErr::MalformedName.into());
|
||||
return Err(AccommodationListControllerErr::InvalidNameLength.into());
|
||||
}
|
||||
accommodation.name = self.name;
|
||||
|
||||
if let Some(d) = &self.description {
|
||||
if !c.accommodation_description_len.validate(d) {
|
||||
return Err(AccommodationListControllerErr::MalformedDescription.into());
|
||||
return Err(AccommodationListControllerErr::InvalidDescriptionLength.into());
|
||||
}
|
||||
}
|
||||
accommodation.description.clone_from(&self.description);
|
||||
|
||||
if let Some(c) = &self.color {
|
||||
if !lazy_regex::regex!("[a-fA-F0-9]{6}").is_match(c) {
|
||||
return Err(AccommodationListControllerErr::MalformedColor.into());
|
||||
}
|
||||
}
|
||||
accommodation.color.clone_from(&self.color);
|
||||
|
||||
accommodation.need_validation = self.need_validation;
|
||||
accommodation.open_to_reservations = self.open_to_reservations;
|
||||
Ok(())
|
||||
|
@ -459,6 +459,7 @@ pub struct Accommodation {
|
||||
pub name: String,
|
||||
pub need_validation: bool,
|
||||
pub description: Option<String>,
|
||||
pub color: Option<String>,
|
||||
pub open_to_reservations: bool,
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,8 @@ diesel::table! {
|
||||
name -> Varchar,
|
||||
need_validation -> Bool,
|
||||
description -> Nullable<Text>,
|
||||
#[max_length = 6]
|
||||
color -> Nullable<Varchar>,
|
||||
open_to_reservations -> Bool,
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ pub async fn update(accommodation: &mut Accommodation) -> anyhow::Result<()> {
|
||||
accommodations_list::dsl::name.eq(accommodation.name.to_string()),
|
||||
accommodations_list::dsl::need_validation.eq(accommodation.need_validation),
|
||||
accommodations_list::dsl::description.eq(accommodation.description.clone()),
|
||||
accommodations_list::dsl::color.eq(accommodation.color.clone()),
|
||||
accommodations_list::dsl::open_to_reservations.eq(accommodation.open_to_reservations),
|
||||
))
|
||||
.execute(conn)
|
||||
|
Reference in New Issue
Block a user