Skip to content

Commit

Permalink
Merge pull request #307 from sohosai/develop
Browse files Browse the repository at this point in the history
deploy 20240517
  • Loading branch information
arata-nvm authored May 16, 2024
2 parents cf84820 + 6a156b2 commit a479096
Show file tree
Hide file tree
Showing 25 changed files with 520 additions and 398 deletions.
546 changes: 274 additions & 272 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions crates/sos24-domain/src/entity/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct Form {
}

impl Form {
#[allow(clippy::too_many_arguments)]
pub fn create(
title: FormTitle,
description: FormDescription,
Expand Down Expand Up @@ -255,6 +256,14 @@ impl Form {
pub fn is_started(&self, now: &chrono::DateTime<chrono::Utc>) -> bool {
&self.starts_at.clone().value() <= now
}

pub fn is_ended(&self, now: &chrono::DateTime<chrono::Utc>) -> bool {
&self.ends_at.clone().value() <= now
}

pub fn can_be_updated(&self, actor: &Actor, now: &chrono::DateTime<chrono::Utc>) -> bool {
!self.is_ended(now) || actor.has_permission(Permissions::UPDATE_FORM_ANSWER_ANYTIME)
}
}

impl_value_object!(FormId(uuid::Uuid));
Expand Down Expand Up @@ -591,8 +600,8 @@ mod tests {
let form = Form::create(
fixture::form::title1(),
fixture::form::description1(),
fixture::form::starts_at1(),
fixture::form::ends_at1(),
fixture::form::starts_at1_opened(),
fixture::form::ends_at1_opened(),
fixture::form::categories1(),
fixture::form::attributes1(),
fixture::form::items1(),
Expand All @@ -606,8 +615,8 @@ mod tests {
let form = Form::create(
fixture::form::title1(),
fixture::form::description1(),
fixture::form::ends_at1(),
fixture::form::starts_at1(),
fixture::form::ends_at1_opened(),
fixture::form::starts_at1_opened(),
fixture::form::categories1(),
fixture::form::attributes1(),
fixture::form::items1(),
Expand Down
1 change: 1 addition & 0 deletions crates/sos24-domain/src/entity/news.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct News {
}

impl News {
#[allow(clippy::too_many_arguments)]
pub fn new(
id: NewsId,
title: NewsTitle,
Expand Down
12 changes: 7 additions & 5 deletions crates/sos24-domain/src/entity/permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ bitflags! {
const CREATE_FORM_ANSWER = 1 << 20;
const READ_FORM_ANSWER_ALL = 1 << 21;
const UPDATE_FORM_ANSWER_ALL = 1 << 22;
const UPDATE_FORM_ANSWER_ANYTIME = 1 << 23;

const CREATE_FILE_PRIVATE = 1 << 23;
const CREATE_FILE_PUBLIC = 1 << 24;
const READ_FILE_ALL = 1 << 25;
const DELETE_FILE_ALL = 1 << 26;
const CREATE_FILE_PRIVATE = 1 << 24;
const CREATE_FILE_PUBLIC = 1 << 25;
const READ_FILE_ALL = 1 << 26;
const DELETE_FILE_ALL = 1 << 27;

const CREATE_PROJECT_ANYTIME = 1 << 27;
const CREATE_PROJECT_ANYTIME = 1 << 28;
}
}

Expand All @@ -67,6 +68,7 @@ impl UserRole {
| Permissions::DELETE_INVITATION_ALL
| Permissions::CREATE_INVITATION_ANYTIME
| Permissions::UPDATE_FORM_ANSWER_ALL
| Permissions::UPDATE_FORM_ANSWER_ANYTIME
| Permissions::CREATE_FILE_PUBLIC
| Permissions::DELETE_FILE_ALL
| Permissions::CREATE_PROJECT_ANYTIME
Expand Down
1 change: 1 addition & 0 deletions crates/sos24-domain/src/entity/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct User {
}

impl User {
#[allow(clippy::too_many_arguments)]
pub fn new(
id: UserId,
name: UserName,
Expand Down
55 changes: 48 additions & 7 deletions crates/sos24-domain/src/test/fixture/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,36 @@ pub fn description1() -> FormDescription {
FormDescription::new("そぽたん申請です".to_string())
}

pub fn starts_at1() -> DateTime {
DateTime::try_from("2021-01-01T00:00:00+00:00".to_string()).unwrap()
pub fn starts_at1_opened() -> DateTime {
DateTime::new(
chrono::Utc::now()
.checked_sub_days(chrono::Days::new(1))
.unwrap(),
)
}

pub fn ends_at1_opened() -> DateTime {
DateTime::new(
chrono::Utc::now()
.checked_add_days(chrono::Days::new(1))
.unwrap(),
)
}

pub fn ends_at1() -> DateTime {
DateTime::try_from("2021-01-01T23:59:59+00:00".to_string()).unwrap()
pub fn starts_at1_closed() -> DateTime {
DateTime::new(
chrono::Utc::now()
.checked_sub_days(chrono::Days::new(2))
.unwrap(),
)
}

pub fn ends_at1_closed() -> DateTime {
DateTime::new(
chrono::Utc::now()
.checked_sub_days(chrono::Days::new(1))
.unwrap(),
)
}

pub fn categories1() -> ProjectCategories {
Expand Down Expand Up @@ -83,13 +107,30 @@ pub fn attachments1() -> Vec<FileId> {
vec![]
}

pub fn form1() -> Form {
pub fn form1_opened() -> Form {
Form::new(
id1(),
title1(),
description1(),
starts_at1_opened(),
ends_at1_opened(),
categories1(),
attributes1(),
is_notified1(),
items1(),
attachments1(),
datetime::now(),
datetime::now(),
)
}

pub fn form1_closed() -> Form {
Form::new(
id1(),
title1(),
description1(),
starts_at1(),
ends_at1(),
starts_at1_closed(),
ends_at1_closed(),
categories1(),
attributes1(),
is_notified1(),
Expand Down
12 changes: 6 additions & 6 deletions crates/sos24-infrastructure/src/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ pub struct SendGridEmailSender {
}

trait EmailToSendGridEmail {
fn into_email<'a>(&'a self) -> Email;
fn to_email(&self) -> Email;
}

impl EmailToSendGridEmail for email::Email {
fn into_email<'a>(&'a self) -> Email {
fn to_email(&self) -> Email {
Email::new(&self.address).set_name(&self.name)
}
}

impl EmailToSendGridEmail for String {
fn into_email<'a>(&'a self) -> Email {
fn to_email(&self) -> Email {
Email::new(self)
}
}
Expand All @@ -42,7 +42,7 @@ impl EmailSender for SendGridEmailSender {
return Ok(());
}

let mut message = Message::new(command.from.into_email())
let mut message = Message::new(command.from.to_email())
.set_subject(&command.subject)
.add_content(
Content::new()
Expand All @@ -51,7 +51,7 @@ impl EmailSender for SendGridEmailSender {
)
.add_category("sos");
if let Some(ref reply_to) = command.reply_to {
message = message.set_reply_to(reply_to.into_email());
message = message.set_reply_to(reply_to.to_email());
}

// 宛先数が1000件より多い場合は分割して送信する必要がある
Expand All @@ -61,7 +61,7 @@ impl EmailSender for SendGridEmailSender {
}

for address in &command.to {
message = message.add_personalization(Personalization::new(address.into_email()));
message = message.add_personalization(Personalization::new(address.to_email()));
}

self.sender.send(&message).await?;
Expand Down
5 changes: 5 additions & 0 deletions crates/sos24-presentation/src/error/convert_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ impl From<FormAnswerUseCaseError> for AppError {
"form-answer/export-failed".to_string(),
message,
),
FormAnswerUseCaseError::FormClosed => AppError::new(
StatusCode::BAD_REQUEST,
"form-answer/form-closed".to_string(),
message,
),
FormAnswerUseCaseError::FormIdError(e) => e.into(),
FormAnswerUseCaseError::ProjectIdError(e) => e.into(),
FormAnswerUseCaseError::FormUseCaseError(e) => e.into(),
Expand Down
5 changes: 4 additions & 1 deletion crates/sos24-presentation/src/model/form_answer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ pub struct FormAnswerSummary {
form_id: String,
form_title: String,
#[schema(format = "date-time")]
created_at: String,
#[schema(format = "date-time")]
updated_at: String,
}

Expand All @@ -127,7 +129,8 @@ impl From<FormAnswerDto> for FormAnswerSummary {
project_title: form_answer_dto.project_title,
form_id: form_answer_dto.form_id,
form_title: form_answer_dto.form_title,
updated_at: form_answer_dto.updated_at.to_rfc3339(),
created_at: form_answer_dto.created_at.to_rfc3339(),
updated_at: form_answer_dto.created_at.to_rfc3339(),
}
}
}
Expand Down
35 changes: 18 additions & 17 deletions crates/sos24-presentation/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,59 @@ use sos24_use_case::{
};

#[cfg(not(test))]
mod module {
mod modules {
pub type Repositories = sos24_infrastructure::DefaultRepositories;
pub type Adapters = sos24_infrastructure::DefaultAdapters;
}

#[cfg(test)]
mod module {
#[allow(clippy::items_after_test_module)]
mod modules {
pub type Repositories = sos24_domain::test::repository::MockRepositories;
pub type Adapters = sos24_use_case::shared::adapter::MockAdapters;
}

pub struct Modules {
config: Config,
form_use_case: FormUseCase<module::Repositories, module::Adapters>,
form_answer_use_case: FormAnswerUseCase<module::Repositories>,
invitation_use_case: InvitationUseCase<module::Repositories>,
news_use_case: NewsUseCase<module::Repositories, module::Adapters>,
file_use_case: FileUseCase<module::Repositories>,
project_use_case: ProjectUseCase<module::Repositories, module::Adapters>,
user_use_case: UserUseCase<module::Repositories>,
form_use_case: FormUseCase<modules::Repositories, modules::Adapters>,
form_answer_use_case: FormAnswerUseCase<modules::Repositories>,
invitation_use_case: InvitationUseCase<modules::Repositories>,
news_use_case: NewsUseCase<modules::Repositories, modules::Adapters>,
file_use_case: FileUseCase<modules::Repositories>,
project_use_case: ProjectUseCase<modules::Repositories, modules::Adapters>,
user_use_case: UserUseCase<modules::Repositories>,
}

impl Modules {
pub fn config(&self) -> &Config {
&self.config
}

pub fn form_use_case(&self) -> &FormUseCase<module::Repositories, module::Adapters> {
pub fn form_use_case(&self) -> &FormUseCase<modules::Repositories, modules::Adapters> {
&self.form_use_case
}

pub fn form_answer_use_case(&self) -> &FormAnswerUseCase<module::Repositories> {
pub fn form_answer_use_case(&self) -> &FormAnswerUseCase<modules::Repositories> {
&self.form_answer_use_case
}

pub fn invitation_use_case(&self) -> &InvitationUseCase<module::Repositories> {
pub fn invitation_use_case(&self) -> &InvitationUseCase<modules::Repositories> {
&self.invitation_use_case
}

pub fn news_use_case(&self) -> &NewsUseCase<module::Repositories, module::Adapters> {
pub fn news_use_case(&self) -> &NewsUseCase<modules::Repositories, modules::Adapters> {
&self.news_use_case
}

pub fn file_use_case(&self) -> &FileUseCase<module::Repositories> {
pub fn file_use_case(&self) -> &FileUseCase<modules::Repositories> {
&self.file_use_case
}

pub fn project_use_case(&self) -> &ProjectUseCase<module::Repositories, module::Adapters> {
pub fn project_use_case(&self) -> &ProjectUseCase<modules::Repositories, modules::Adapters> {
&self.project_use_case
}

pub fn user_use_case(&self) -> &UserUseCase<module::Repositories> {
pub fn user_use_case(&self) -> &UserUseCase<modules::Repositories> {
&self.user_use_case
}
}
Expand Down Expand Up @@ -93,7 +94,7 @@ pub async fn new(config: Config) -> anyhow::Result<Modules> {
object_storage,
));

let send_grid = SendGrid::new(&env::send_grid_api_key());
let send_grid = SendGrid::new(env::send_grid_api_key());
let adapters = Arc::new(sos24_infrastructure::DefaultAdapters::new(
send_grid,
env::slack_webhook_url(),
Expand Down
6 changes: 3 additions & 3 deletions crates/sos24-presentation/src/route/form_answer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use percent_encoding::NON_ALPHANUMERIC;
use sos24_use_case::form_answer::interactor::create::CreateFormAnswerCommand;

use crate::context::Context;
use crate::csv::{serialize_to_csv, CsvSerializationError};
use crate::csv::serialize_to_csv;
use crate::model::form_answer::{
CreatedFormAnswer, ExportFormAnswerQuery, FormAnswerSummary, UpdateFormAnswer,
};
Expand Down Expand Up @@ -154,7 +154,7 @@ pub async fn handle_export(
AppError::from(err)
})?;

let data = (|| -> Result<String, CsvSerializationError> {
let data = {
let mut csv_data = vec![];

let form_item_names_len = form_answer_list.form_item_names.len();
Expand Down Expand Up @@ -184,7 +184,7 @@ pub async fn handle_export(
}

serialize_to_csv(csv_data)
})()
}
.map_err(|err| {
tracing::error!("Failed to serialize to csv: {err:?}");
AppError::from(err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::convert::identity;

use chrono_tz::Asia::Tokyo;
use sos24_domain::repository::{form::FormRepository, project::ProjectRepository, Repositories};

Expand Down Expand Up @@ -42,7 +40,7 @@ impl<R: Repositories, A: Adapters> FormUseCase<R, A> {
.map(|it| it.email().clone().value()),
]
})
.filter_map(identity)
.flatten()
.collect::<Vec<_>>();

let command = SendEmailCommand {
Expand Down
8 changes: 4 additions & 4 deletions crates/sos24-use-case/src/form/interactor/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ mod tests {
CreateFormCommand {
title: fixture::form::title1().value(),
description: fixture::form::description1().value(),
starts_at: fixture::form::starts_at1().value().to_rfc3339(),
ends_at: fixture::form::ends_at1().value().to_rfc3339(),
starts_at: fixture::form::starts_at1_opened().value().to_rfc3339(),
ends_at: fixture::form::ends_at1_opened().value().to_rfc3339(),
categories: ProjectCategoriesDto::from(fixture::form::categories1()),
attributes: ProjectAttributesDto::from(fixture::form::attributes1()),
items: vec![NewFormItemDto::new(
Expand Down Expand Up @@ -159,8 +159,8 @@ mod tests {
CreateFormCommand {
title: fixture::form::title1().value(),
description: fixture::form::description1().value(),
starts_at: fixture::form::starts_at1().value().to_rfc3339(),
ends_at: fixture::form::ends_at1().value().to_rfc3339(),
starts_at: fixture::form::starts_at1_opened().value().to_rfc3339(),
ends_at: fixture::form::ends_at1_opened().value().to_rfc3339(),
categories: ProjectCategoriesDto::from(fixture::form::categories1()),
attributes: ProjectAttributesDto::from(fixture::form::attributes1()),
items: vec![NewFormItemDto::new(
Expand Down
Loading

0 comments on commit a479096

Please sign in to comment.