From bd96d57a04c6b77ec9296517bb9b7a70b40883f9 Mon Sep 17 00:00:00 2001 From: rito528 <39003544+rito528@users.noreply.github.com> Date: Tue, 31 Oct 2023 22:25:57 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=95=E3=82=A9=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E3=81=AE=E5=85=AC=E9=96=8B=E8=A8=AD=E5=AE=9A=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/domain/src/form/models.rs | 19 +++++++++++++++++++ server/infra/resource/src/database/form.rs | 6 ++++-- server/infra/resource/src/dto.rs | 3 +++ .../src/m20220101_000001_create_table.rs | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/server/domain/src/form/models.rs b/server/domain/src/form/models.rs index 6484dfce..0b6ae144 100644 --- a/server/domain/src/form/models.rs +++ b/server/domain/src/form/models.rs @@ -138,6 +138,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))] @@ -167,6 +169,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 39eb522a..5162bad0 100644 --- a/server/infra/resource/src/database/form.rs +++ b/server/infra/resource/src/database/form.rs @@ -49,7 +49,7 @@ impl FormDatabase for ConnectionPool { ) -> Result, InfraError> { let forms = self .query_all( - &format!(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 + &format!(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 @@ -136,6 +136,7 @@ impl FormDatabase for ConnectionPool { response_period: start_at.zip(end_at), webhook_url: rs.try_get("", "url")?, default_answer_title: rs.try_get("", "default_answer_titles.title")?, + visibility: rs.try_get("", "visibility")?, }) }) .collect() @@ -145,7 +146,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 @@ -216,6 +217,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 99859c55..da7d80f0 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,