Skip to content

Commit

Permalink
refactor: フォームリスト用ハンドラを一つに統一する
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Dec 17, 2024
1 parent c8ff91d commit bec8b6b
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 165 deletions.
4 changes: 3 additions & 1 deletion server/domain/src/form/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ impl ResponsePeriod {
}

#[cfg_attr(test, derive(Arbitrary))]
#[derive(Serialize, Deserialize, Debug, EnumString, Display, Default, PartialOrd, PartialEq)]
#[derive(
Serialize, Deserialize, Debug, EnumString, Display, Copy, Clone, Default, PartialOrd, PartialEq,
)]
pub enum Visibility {
PUBLIC,
#[default]
Expand Down
8 changes: 3 additions & 5 deletions server/entrypoint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use presentation::{
edit_label_for_answers, edit_label_for_forms, form_list_handler, get_all_answers,
get_answer_by_form_id_handler, get_answer_handler, get_form_handler,
get_labels_for_answers, get_labels_for_forms, get_messages_handler, get_questions_handler,
post_answer_handler, post_form_comment, post_message_handler, public_form_list_handler,
put_question_handler, replace_answer_labels, replace_form_labels, update_answer_handler,
update_form_handler, update_message_handler,
post_answer_handler, post_form_comment, post_message_handler, put_question_handler,
replace_answer_labels, replace_form_labels, update_answer_handler, update_form_handler,
update_message_handler,
},
health_check_handler::health_check,
notification_handler::{fetch_by_request_user, update_read_state},
Expand Down Expand Up @@ -77,8 +77,6 @@ async fn main() -> anyhow::Result<()> {
let router = Router::new()
.route("/forms", post(create_form_handler).get(form_list_handler))
.with_state(shared_repository.to_owned())
.route("/forms/public", get(public_form_list_handler))
.with_state(shared_repository.to_owned())
.route(
"/forms/:id",
get(get_form_handler)
Expand Down
1 change: 0 additions & 1 deletion server/presentation/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ pub async fn auth(
};

let static_endpoints_allowed_for_standard_users = [
(&Method::GET, "/forms/public"),
(&Method::POST, "/forms/answers"),
(&Method::POST, "/forms/answers/comment"),
(&Method::GET, "/users"),
Expand Down
31 changes: 9 additions & 22 deletions server/presentation/src/form_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
FormQuestionUpdateSchema, FormUpdateSchema, LabelSchema, MessageUpdateSchema,
OffsetAndLimit, PostedMessageSchema, ReplaceAnswerLabelSchema,
},
form_response_schemas::{FormAnswer, MessageContentSchema, SenderSchema},
form_response_schemas::{FormAnswer, FormListSchema, MessageContentSchema, SenderSchema},
},
};

Expand Down Expand Up @@ -56,26 +56,6 @@ pub async fn create_form_handler(
}
}

pub async fn public_form_list_handler(
State(repository): State<RealInfrastructureRepository>,
Query(offset_and_limit): Query<OffsetAndLimit>,
) -> impl IntoResponse {
let form_use_case = FormUseCase {
form_repository: repository.form_repository(),
notification_repository: repository.notification_repository(),
};

// FIXME: public_form_list を実装する
todo!();
// match form_use_case
// .public_form_list(offset_and_limit.offset, offset_and_limit.limit)
// .await
// {
// Ok(forms) => (StatusCode::OK, Json(forms)).into_response(),
// Err(err) => handle_error(err).into_response(),
// }
}

pub async fn form_list_handler(
Extension(user): Extension<User>,
State(repository): State<RealInfrastructureRepository>,
Expand All @@ -90,7 +70,14 @@ pub async fn form_list_handler(
.form_list(&user, offset_and_limit.offset, offset_and_limit.limit)
.await
{
Ok(forms) => (StatusCode::OK, Json(forms)).into_response(),
Ok(forms) => {
let form_list_schema = forms
.into_iter()
.map(Into::<FormListSchema>::into)
.collect_vec();

(StatusCode::OK, Json(form_list_schema)).into_response()
}
Err(err) => handle_error(err).into_response(),
}
}
Expand Down
Loading

0 comments on commit bec8b6b

Please sign in to comment.