diff --git a/server/domain/src/form/models.rs b/server/domain/src/form/models.rs index 93145d30..ebc7f0c4 100644 --- a/server/domain/src/form/models.rs +++ b/server/domain/src/form/models.rs @@ -146,6 +146,8 @@ pub struct FormSettings { pub webhook_url: WebhookUrl, #[serde(default)] pub default_answer_title: DefaultAnswerTitle, + #[serde(default)] + pub visibility: Visibility, } #[cfg_attr(test, derive(Arbitrary))] @@ -175,6 +177,23 @@ impl ResponsePeriod { } } +#[cfg_attr(test, derive(Arbitrary))] +#[derive(Serialize, Deserialize, Debug, EnumString, Display, Default, PartialOrd, PartialEq)] +pub enum Visibility { + #[default] + PUBLIC, + PRIVATE, +} + +impl TryFrom for Visibility { + type Error = errors::domain::DomainError; + + fn try_from(value: String) -> Result { + use std::str::FromStr; + Self::from_str(&value).map_err(Into::into) + } +} + #[cfg_attr(test, derive(Arbitrary))] #[derive(DerivingVia, Default, Debug, PartialEq)] #[deriving(From, Into, Serialize(via: Option::), Deserialize(via: Option::))] diff --git a/server/infra/resource/src/database/form.rs b/server/infra/resource/src/database/form.rs index 68fcda31..64edb5b0 100644 --- a/server/infra/resource/src/database/form.rs +++ b/server/infra/resource/src/database/form.rs @@ -81,7 +81,7 @@ impl FormDatabase for ConnectionPool { async fn get(&self, form_id: FormId) -> Result { let form_query = self .query_all_and_values( - r"SELECT form_meta_data.id AS form_id, form_meta_data.title AS form_title, description, created_at, updated_at, url, start_at, end_at, default_answer_titles.title + r"SELECT form_meta_data.id AS form_id, form_meta_data.title AS form_title, description, visibility, created_at, updated_at, url, start_at, end_at, default_answer_titles.title FROM form_meta_data LEFT JOIN form_webhooks ON form_meta_data.id = form_webhooks.form_id LEFT JOIN response_period ON form_meta_data.id = response_period.form_id @@ -152,6 +152,7 @@ impl FormDatabase for ConnectionPool { response_period: start_at.zip(end_at), webhook_url: form.try_get("", "url")?, default_answer_title: form.try_get("", "default_answer_titles.title")?, + visibility: form.try_get("", "visibility")?, }) } diff --git a/server/infra/resource/src/dto.rs b/server/infra/resource/src/dto.rs index 9eae9a9b..584667e1 100644 --- a/server/infra/resource/src/dto.rs +++ b/server/infra/resource/src/dto.rs @@ -45,6 +45,7 @@ pub struct FormDto { pub response_period: Option<(DateTime, DateTime)>, pub webhook_url: Option, pub default_answer_title: Option, + pub visibility: String, } impl TryFrom for domain::form::models::Form { @@ -60,6 +61,7 @@ impl TryFrom for domain::form::models::Form { response_period, webhook_url, default_answer_title, + visibility, }: FormDto, ) -> Result { Ok(domain::form::models::Form::builder() @@ -77,6 +79,7 @@ impl TryFrom for domain::form::models::Form { response_period: ResponsePeriod::new(response_period), webhook_url: webhook_url.into(), default_answer_title: default_answer_title.into(), + visibility: visibility.try_into()?, }) .build()) } diff --git a/server/migration/src/m20220101_000001_create_table.rs b/server/migration/src/m20220101_000001_create_table.rs index c9ed6027..73c44064 100644 --- a/server/migration/src/m20220101_000001_create_table.rs +++ b/server/migration/src/m20220101_000001_create_table.rs @@ -29,6 +29,7 @@ impl MigrationTrait for Migration { id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, title TEXT NOT NULL, description TEXT NOT NULL, + visibility ENUM('PUBLIC', 'PRIVATE'), created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_by INT NOT NULL, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,