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

フォームに来た回答に対してタイトルを自動設定する機能を追加 #279

Merged
merged 7 commits into from
Sep 15, 2023
29 changes: 21 additions & 8 deletions server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ uuid = "1.4.1"
deriving_via = "1.5.0"
reqwest = { version = "0.11.20", default-features = false, features = ["rustls"] }
num-traits = "0.2.16"
regex = "1.9.5"
21 changes: 21 additions & 0 deletions server/domain/src/form/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub struct FormUpdateTargets {
pub response_period: Option<ResponsePeriod>,
#[serde(default)]
pub webhook: Option<WebhookUrl>,
#[serde(default)]
pub default_answer_title: Option<DefaultAnswerTitle>,
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -134,6 +136,8 @@ pub struct FormSettings {
pub response_period: ResponsePeriod,
#[serde(default)]
pub webhook_url: WebhookUrl,
#[serde(default)]
pub default_answer_title: DefaultAnswerTitle,
}

#[cfg_attr(test, derive(Arbitrary))]
Expand Down Expand Up @@ -163,10 +167,27 @@ impl ResponsePeriod {
}
}

#[cfg_attr(test, derive(Arbitrary))]
#[derive(DerivingVia, Default, Debug, PartialEq)]
#[deriving(From, Into, Serialize(via: Option::<String>), Deserialize(via: Option::<String>))]
pub struct DefaultAnswerTitle {
pub default_answer_title: Option<String>,
}

impl DefaultAnswerTitle {
pub fn unwrap_or_default(&self) -> String {
self.default_answer_title
.to_owned()
.unwrap_or("未設定".to_string())
}
}

#[derive(Serialize, Deserialize, Debug)]
pub struct PostedAnswers {
pub uuid: Uuid, //todo: あとでUser型に直す
pub timestamp: DateTime<Utc>,
pub form_id: FormId,
pub title: DefaultAnswerTitle,
pub answers: Vec<Answer>,
}

Expand Down
1 change: 1 addition & 0 deletions server/infra/entities/src/answers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Model {
pub id: i32,
#[sea_orm(column_type = "Binary(BlobSize::Blob(Some(16)))")]
pub user: Vec<u8>,
pub title: String,
pub time_stamp: DateTimeUtc,
}

Expand Down
32 changes: 32 additions & 0 deletions server/infra/entities/src/default_answer_title.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1

use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "default_answer_title")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub form_id: i32,
pub title: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::form_meta_data::Entity",
from = "Column::FormId",
to = "super::form_meta_data::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
FormMetaData,
}

impl Related<super::form_meta_data::Entity> for Entity {
fn to() -> RelationDef {
Relation::FormMetaData.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
32 changes: 32 additions & 0 deletions server/infra/entities/src/default_answer_titles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1

use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "default_answer_titles")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub form_id: i32,
pub title: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::form_meta_data::Entity",
from = "Column::FormId",
to = "super::form_meta_data::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
FormMetaData,
}

impl Related<super::form_meta_data::Entity> for Entity {
fn to() -> RelationDef {
Relation::FormMetaData.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
8 changes: 8 additions & 0 deletions server/infra/entities/src/form_meta_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub struct Model {

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::default_answer_titles::Entity")]
DefaultAnswerTitles,
#[sea_orm(has_many = "super::form_questions::Entity")]
FormQuestions,
#[sea_orm(has_many = "super::form_webhooks::Entity")]
Expand All @@ -23,6 +25,12 @@ pub enum Relation {
ResponsePeriod,
}

impl Related<super::default_answer_titles::Entity> for Entity {
fn to() -> RelationDef {
Relation::DefaultAnswerTitles.def()
}
}

impl Related<super::form_questions::Entity> for Entity {
fn to() -> RelationDef {
Relation::FormQuestions.def()
Expand Down
1 change: 1 addition & 0 deletions server/infra/entities/src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pub mod prelude;

pub mod answers;
pub mod default_answer_titles;
pub mod form_choices;
pub mod form_meta_data;
pub mod form_questions;
Expand Down
8 changes: 4 additions & 4 deletions server/infra/entities/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1

pub use super::{
answers::Entity as Answers, form_choices::Entity as FormChoices,
form_meta_data::Entity as FormMetaData, form_questions::Entity as FormQuestions,
form_webhooks::Entity as FormWebhooks, real_answers::Entity as RealAnswers,
response_period::Entity as ResponsePeriod,
answers::Entity as Answers, default_answer_titles::Entity as DefaultAnswerTitles,
form_choices::Entity as FormChoices, form_meta_data::Entity as FormMetaData,
form_questions::Entity as FormQuestions, form_webhooks::Entity as FormWebhooks,
real_answers::Entity as RealAnswers, response_period::Entity as ResponsePeriod,
};
1 change: 1 addition & 0 deletions server/infra/resource/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ sea-orm = { workspace = true }
serde = { workspace = true }
tracing = { workspace = true }
num-traits = { workspace = true }
regex = { workspace = true }
Loading