Skip to content

Commit

Permalink
Merge pull request #279 from GiganticMinecraft/feat/answerTitle
Browse files Browse the repository at this point in the history
フォームに来た回答に対してタイトルを自動設定する機能を追加
  • Loading branch information
Mitama authored Sep 15, 2023
2 parents 36c4f87 + efb1d0b commit 6b40bc0
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 20 deletions.
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

0 comments on commit 6b40bc0

Please sign in to comment.