Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

フォームの公開設定を追加 #328

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions server/domain/src/form/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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<String> for Visibility {
type Error = errors::domain::DomainError;

fn try_from(value: String) -> Result<Self, Self::Error> {
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::<String>), Deserialize(via: Option::<String>))]
Expand Down
3 changes: 2 additions & 1 deletion server/infra/resource/src/database/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl FormDatabase for ConnectionPool {
async fn get(&self, form_id: FormId) -> Result<FormDto, InfraError> {
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
Expand Down Expand Up @@ -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")?,
})
}

Expand Down
3 changes: 3 additions & 0 deletions server/infra/resource/src/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct FormDto {
pub response_period: Option<(DateTime<Utc>, DateTime<Utc>)>,
pub webhook_url: Option<String>,
pub default_answer_title: Option<String>,
pub visibility: String,
}

impl TryFrom<FormDto> for domain::form::models::Form {
Expand All @@ -60,6 +61,7 @@ impl TryFrom<FormDto> for domain::form::models::Form {
response_period,
webhook_url,
default_answer_title,
visibility,
}: FormDto,
) -> Result<Self, Self::Error> {
Ok(domain::form::models::Form::builder()
Expand All @@ -77,6 +79,7 @@ impl TryFrom<FormDto> 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())
}
Expand Down
1 change: 1 addition & 0 deletions server/migration/src/m20220101_000001_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down