Skip to content

Commit

Permalink
clippyで指摘された箇所を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
momeemt committed Apr 22, 2023
1 parent 927ae36 commit 06c9779
Show file tree
Hide file tree
Showing 28 changed files with 47 additions and 57 deletions.
7 changes: 4 additions & 3 deletions sos21-api-server/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ impl App {
"never" => ProjectCreationPeriod::never(),
_ => {
let (starts_at, ends_at) = period
.split_once("-")
.split_once('-')
.context("period must be delimited with '-'")?;
let starts_at = DateTime::from_utc(Utc.timestamp_millis(starts_at.parse()?));
let ends_at = DateTime::from_utc(Utc.timestamp_millis(ends_at.parse()?));
// FIXME: 範囲外の場合にハンドリングする
let starts_at = DateTime::from_utc(Utc.timestamp_millis_opt(starts_at.parse()?).unwrap());
let ends_at = DateTime::from_utc(Utc.timestamp_millis_opt(ends_at.parse()?).unwrap());
ProjectCreationPeriod::from_datetime(starts_at, ends_at)
.context("invalid project creation period")?
}
Expand Down
3 changes: 1 addition & 2 deletions sos21-api-server/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::app::App;
use mime::Mime;
use warp::{
http::{header, method::Method},
reply::Reply,
Filter,
};

Expand Down Expand Up @@ -69,7 +68,7 @@ macro_rules! routes {
pub fn endpoints(
app: App,
key_store: KeyStore,
) -> impl Filter<Extract = impl Reply, Error = Infallible> + Clone {
) -> impl Filter<Extract = (impl warp::Reply,), Error = Infallible> + Clone {
use crate::handler;

let with_auth = authenticate(key_store, app.config().clone());
Expand Down
2 changes: 2 additions & 0 deletions sos21-api-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ struct Opt {
#[structopt(long, env = "SOS21_API_SERVER_ADMINISTRATOR_EMAIL")]
administrator_email: String,
#[structopt(long, env = "SOS21_API_SERVER_START_PROJECT_CREATION_PERIOD")]
#[allow(dead_code)]
start_project_creation_period: Option<i64>,
#[structopt(long, env = "SOS21_API_SERVER_END_PROJECT_CREATION_PERIOD")]
#[allow(dead_code)]
end_project_creation_period: Option<i64>,
#[structopt(short, long, env = "SOS21_API_SERVER_BIND")]
bind: SocketAddr,
Expand Down
2 changes: 1 addition & 1 deletion sos21-database/src/query/find_file_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ WHERE file_distributions.id = $1

let files = row
.files
.unwrap_or_else(Vec::new)
.unwrap_or_default()
.into_iter()
.map(|(project_id, sharing_id)| FileDistributionFile {
project_id,
Expand Down
6 changes: 3 additions & 3 deletions sos21-database/src/query/find_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ WHERE forms.id = $1
answer_notification_webhook: row.answer_notification_webhook,
};

let include_ids = row.include_ids.unwrap_or_else(Vec::new);
let exclude_ids = row.exclude_ids.unwrap_or_else(Vec::new);
let include_ids = row.include_ids.unwrap_or_default();
let exclude_ids = row.exclude_ids.unwrap_or_default();
let query = row
.query
.unwrap_or_else(Vec::new)
.unwrap_or_default()
.into_iter()
.map(|(category, attributes)| FormProjectQueryConjunction {
category,
Expand Down
2 changes: 1 addition & 1 deletion sos21-database/src/query/find_registration_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ WHERE registration_forms.id = $1

let query = row
.query
.unwrap_or_else(Vec::new)
.unwrap_or_default()
.into_iter()
.map(
|(category, attributes)| RegistrationFormProjectQueryConjunction {
Expand Down
2 changes: 1 addition & 1 deletion sos21-database/src/query/list_file_distributions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ GROUP BY file_distributions.id

let files = row
.files
.unwrap_or_else(Vec::new)
.unwrap_or_default()
.into_iter()
.map(|(project_id, sharing_id)| FileDistributionFile {
project_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ GROUP BY file_distributions.id

let files = row
.files
.unwrap_or_else(Vec::new)
.unwrap_or_default()
.into_iter()
.map(|(project_id, sharing_id)| FileDistributionFile {
project_id,
Expand Down
6 changes: 3 additions & 3 deletions sos21-database/src/query/list_forms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ GROUP BY forms.id
answer_notification_webhook: row.answer_notification_webhook,
};

let include_ids = row.include_ids.unwrap_or_else(Vec::new);
let exclude_ids = row.exclude_ids.unwrap_or_else(Vec::new);
let include_ids = row.include_ids.unwrap_or_default();
let exclude_ids = row.exclude_ids.unwrap_or_default();
let query = row
.query
.unwrap_or_else(Vec::new)
.unwrap_or_default()
.into_iter()
.map(|(category, attributes)| FormProjectQueryConjunction {
category,
Expand Down
6 changes: 3 additions & 3 deletions sos21-database/src/query/list_forms_by_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ GROUP BY forms.id
answer_notification_webhook:row.answer_notification_webhook
};

let include_ids = row.include_ids.unwrap_or_else(Vec::new);
let exclude_ids = row.exclude_ids.unwrap_or_else(Vec::new);
let include_ids = row.include_ids.unwrap_or_default();
let exclude_ids = row.exclude_ids.unwrap_or_default();
let query = row
.query
.unwrap_or_else(Vec::new)
.unwrap_or_default()
.into_iter()
.map(|(category, attributes)| FormProjectQueryConjunction {
category,
Expand Down
2 changes: 1 addition & 1 deletion sos21-database/src/query/list_registration_forms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ GROUP BY registration_forms.id

let query = row
.query
.unwrap_or_else(Vec::new)
.unwrap_or_default()
.into_iter()
.map(|(category, attributes)| RegistrationFormProjectQueryConjunction {
category,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ GROUP BY registration_forms.id

let query = row
.query
.unwrap_or_else(Vec::new)
.unwrap_or_default()
.into_iter()
.map(|(category, attributes)| RegistrationFormProjectQueryConjunction {
category,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ GROUP BY registration_forms.id

let query = row
.query
.unwrap_or_else(Vec::new)
.unwrap_or_default()
.into_iter()
.map(|(category, attributes)| RegistrationFormProjectQueryConjunction {
category,
Expand Down
3 changes: 2 additions & 1 deletion sos21-domain/src/model/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ impl DateTime {
}

pub fn jst(&self) -> chrono::DateTime<chrono::FixedOffset> {
let jst = chrono::FixedOffset::east(9 * 3600);
// FIXME: 範囲外の場合のハンドリングをする
let jst = chrono::FixedOffset::east_opt(9 * 3600).unwrap();
self.0.with_timezone(&jst)
}
}
2 changes: 1 addition & 1 deletion sos21-domain/src/model/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Form {
}));
}

domain_ensure!(self.is_visible_to_with_project(&user, project));
domain_ensure!(self.is_visible_to_with_project(user, project));

// TODO: Move this to FormAnswer
let created_at = DateTime::now();
Expand Down
19 changes: 8 additions & 11 deletions sos21-domain/src/model/form/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl FormItem {
}
};

Ok(self.body.check_answer(&body))
Ok(self.body.check_answer(body))
}
}

Expand Down Expand Up @@ -448,7 +448,7 @@ impl CheckFormItems {
) -> Result<(), FromItemsError> {
for conj in conditions.conjunctions() {
for condition in conj {
self.check_condition(item_id, &condition)?;
self.check_condition(item_id, condition)?;
}
}

Expand Down Expand Up @@ -505,10 +505,9 @@ impl CheckFormItems {
}
};

if item
if !item
.boxes()
.find(|checkbox| checkbox.id == checkbox_id)
.is_none()
.any(|checkbox| checkbox.id == checkbox_id)
{
return Err(FromItemsError {
kind: FromItemsErrorKind::UnknownCheckboxIdInConditions {
Expand Down Expand Up @@ -551,10 +550,9 @@ impl CheckFormItems {
}
};

if item
if !item
.buttons()
.find(|button| button.id == radio_id)
.is_none()
.any(|button| button.id == radio_id)
{
return Err(FromItemsError {
kind: FromItemsErrorKind::UnknownRadioIdInConditions {
Expand Down Expand Up @@ -597,10 +595,9 @@ impl CheckFormItems {
}
};

if item
if !item
.columns()
.find(|column| column.id == column_id)
.is_none()
.any(|column| column.id == column_id)
{
return Err(FromItemsError {
kind: FromItemsErrorKind::UnknownGridRadioColumnIdInConditions {
Expand Down
5 changes: 2 additions & 3 deletions sos21-domain/src/model/form/item/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,9 @@ impl CheckboxFormItem {
}

for check_id in answer.checked_ids() {
if self
if !self
.boxes()
.find(|checkbox| checkbox.id == check_id)
.is_none()
.any(|checkbox| checkbox.id == check_id)
{
return Err(CheckAnswerError {
kind: CheckAnswerErrorKind::UnknownCheckboxId { id: check_id },
Expand Down
5 changes: 2 additions & 3 deletions sos21-domain/src/model/form/item/grid_radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,9 @@ impl GridRadioFormItem {
}

if let Some(column_id) = row_answer.value {
if self
if !self
.columns()
.find(|column| column.id == column_id)
.is_none()
.any(|column| column.id == column_id)
{
return Err(CheckAnswerError {
kind: CheckAnswerErrorKind::UnknownGridRadioColumnId { id: column_id },
Expand Down
5 changes: 2 additions & 3 deletions sos21-domain/src/model/form/item/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,10 @@ impl RadioFormItem {
(_, Some(answer)) => answer,
};

if self
if !self
.buttons
.buttons()
.find(|button| button.id == answer)
.is_none()
.any(|button| button.id == answer)
{
return Err(CheckAnswerError {
kind: CheckAnswerErrorKind::UnknownRadioId { id: answer },
Expand Down
3 changes: 1 addition & 2 deletions sos21-domain/src/model/project_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ impl ProjectQuery {
pub fn possible_categories(&self) -> impl Iterator<Item = ProjectCategory> {
let categories: HashSet<_> = self
.conjunctions()
.map(|conj| conj.possible_categories())
.flatten()
.flat_map(|conj| conj.possible_categories())
.collect();
categories.into_iter()
}
Expand Down
2 changes: 1 addition & 1 deletion sos21-domain/src/model/registration_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl RegistrationForm {
{
domain_ensure!(user.id() == pending_project.owner_id());

if !self.query.check_pending_project(&pending_project) {
if !self.query.check_pending_project(pending_project) {
return Err(DomainError::Domain(AnswerError {
kind: AnswerErrorKind::NotTargeted,
}));
Expand Down
4 changes: 1 addition & 3 deletions sos21-domain/src/test/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,6 @@ impl RegistrationFormRepository for MockApp {
.query
.check_pending_project(&pending_project)
})
.cloned()
.count();
let len = len.try_into()?;
Ok(len)
Expand Down Expand Up @@ -927,7 +926,6 @@ impl RegistrationFormAnswerRepository for MockApp {
.respondent()
.is_pending_project(&pending_project)
})
.cloned()
.count();
let len = len.try_into()?;
Ok(len)
Expand Down Expand Up @@ -979,7 +977,7 @@ impl UserInvitationRepository for MockApp {

impl ConfigContext for MockApp {
fn administrator_email(&self) -> &UserEmailAddress {
&*test_model::ADMINISTRATOR_EMAIL
&test_model::ADMINISTRATOR_EMAIL
}

fn project_creation_period_for(&self, category: ProjectCategory) -> ProjectCreationPeriod {
Expand Down
4 changes: 1 addition & 3 deletions sos21-domain/src/test/model/form_answer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ pub fn new_form_answer_id() -> FormAnswerId {

pub fn mock_form_answer_item_text(item: &TextFormItem) -> Option<FormAnswerItemText> {
let text = if let Some(min_length) = item.min_length() {
let text = std::iter::repeat('テ')
.take(min_length as usize)
.collect::<String>();
let text = "テ".repeat(min_length as usize);
FormAnswerItemText::from_string(text).unwrap()
} else {
FormAnswerItemText::from_string("ア").unwrap()
Expand Down
2 changes: 1 addition & 1 deletion sos21-use-case/src/distribute_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ where
.await
.context("Failed to get a project")?,
InputProject::Code(project_code) => {
let code = project::ProjectCode::parse(&project_code)
let code = project::ProjectCode::parse(project_code)
.map_err(|err| UseCaseError::UseCase(Error::from_code_error(err)))?;

ctx.get_project_by_index(code.index)
Expand Down
2 changes: 1 addition & 1 deletion sos21-use-case/src/export_registration_form_answers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ where
write_field!(writer, author_id);

for item in registration_form.items.items() {
write_item_header_fields(writer, &item)?;
write_item_header_fields(writer, item)?;
}

// this terminates the record (see docs on `csv::Writer::write_record`)
Expand Down
2 changes: 1 addition & 1 deletion sos21-use-case/src/list_user_file_sharings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where
.context("Failed to list file sharings")?;

use_case_ensure!(sharings.iter().all(|(sharing, file)| sharing
.is_visible_to_with_file(login_user, &file)
.is_visible_to_with_file(login_user, file)
&& file.is_visible_to(login_user)));

let sharings = sharings
Expand Down
1 change: 0 additions & 1 deletion sos21-use-case/src/model/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ impl Form {
items: form
.into_items()
.into_items()
.into_iter()
.map(FormItem::from_entity)
.collect(),
condition,
Expand Down
1 change: 0 additions & 1 deletion sos21-use-case/src/model/registration_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ impl RegistrationForm {
items: registratiion_form
.items
.into_items()
.into_iter()
.map(FormItem::from_entity)
.collect(),
query: ProjectQuery::from_entity(registratiion_form.query),
Expand Down

0 comments on commit 06c9779

Please sign in to comment.