Skip to content

Commit

Permalink
フォームの回答をすべて取得するエントリポイントの実装
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Sep 16, 2023
1 parent 7524e2e commit 4eff579
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 22 deletions.
1 change: 1 addition & 0 deletions server/Cargo.lock

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

2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ serde_json = "1.0.107"
itertools = "0.11.0"
chrono = { version = "0.4.30" }
futures = "0.3.28"
uuid = "1.4.1"
uuid = { version = "1.4.1", features = ["v4"] }
deriving_via = "1.5.0"
reqwest = { version = "0.11.20", default-features = false, features = ["rustls"] }
num-traits = "0.2.16"
Expand Down
3 changes: 1 addition & 2 deletions server/entrypoint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ use axum::{
};
use common::config::{ENV, HTTP};
use hyper::header::AUTHORIZATION;
use presentation::form_handler::get_all_answers;
use presentation::{
auth::auth,
form_handler::{
create_form_handler, create_question_handler, delete_form_handler, form_list_handler,
get_form_handler, post_answer_handler, update_form_handler,
get_all_answers, get_form_handler, post_answer_handler, update_form_handler,
},
health_check_handler::health_check,
};
Expand Down
1 change: 1 addition & 0 deletions server/errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ edition = "2021"
sea-orm = { workspace = true }
strum = { workspace = true }
thiserror = "1.0.48"
uuid = { workspace = true }
7 changes: 5 additions & 2 deletions server/errors/src/infra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ pub enum InfraError {
#[from]
source: sea_orm::error::DbErr,
},
#[error("Uuid Parse Error: {}", .cause)]
UuidParse { cause: String },
#[error("Uuid Parse Error: {}", .source)]
UuidParse {
#[from]
source: uuid::Error,
},
#[error("Form Not Found: id = {}", .id)]
FormNotFound { id: i32 },
#[error("Outgoing Error: {}", .cause)]
Expand Down
2 changes: 1 addition & 1 deletion server/infra/resource/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ serde = { workspace = true }
tracing = { workspace = true }
num-traits = { workspace = true }
regex = { workspace = true }
uuid = { version = "1.4.1", features = ["v4"] }
uuid = { workspace = true }
21 changes: 7 additions & 14 deletions server/infra/resource/src/database/form.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use async_trait::async_trait;
use chrono::Utc;
use domain::form::models::{
Answer, DefaultAnswerTitle, FormDescription, FormId, FormQuestionUpdateSchema, FormTitle,
DefaultAnswerTitle, FormDescription, FormId, FormQuestionUpdateSchema, FormTitle,
FormUpdateTargets, OffsetAndLimit, PostedAnswers,
};
use entities::prelude::Answers;
use entities::{
answers, default_answer_titles, form_choices, form_meta_data, form_questions, form_webhooks,
prelude::{
DefaultAnswerTitles, FormChoices, FormMetaData, FormQuestions, FormWebhooks, RealAnswers,
Answers, DefaultAnswerTitles, FormChoices, FormMetaData, FormQuestions, FormWebhooks,
RealAnswers,
},
real_answers, response_period,
sea_orm_active_enums::QuestionType,
Expand All @@ -18,19 +18,17 @@ use futures::{stream, stream::StreamExt};
use itertools::Itertools;
use num_traits::cast::FromPrimitive;
use regex::Regex;
use sea_orm::prelude::Uuid;
use sea_orm::{
prelude::Uuid,
sea_query::{Expr, SimpleExpr},
ActiveEnum, ActiveModelTrait, ActiveValue,
ActiveValue::Set,
ColumnTrait, EntityTrait, ModelTrait, QueryFilter, QueryOrder, QuerySelect,
};
use std::fmt::Error;

use crate::dto::{AnswerDto, PostedAnswersDto};
use crate::{
database::{components::FormDatabase, connection::ConnectionPool},
dto::{FormDto, QuestionDto},
dto::{AnswerDto, FormDto, PostedAnswersDto, QuestionDto},
};

#[async_trait]
Expand Down Expand Up @@ -442,7 +440,7 @@ impl FormDatabase for ConnectionPool {
.all(&self.pool)
.await?,
)
.then(|answer| async {
.then(|answer| async move {
let answers = RealAnswers::find()
.filter(Expr::col(real_answers::Column::AnswerId).eq(answer.id))
.all(&self.pool)
Expand All @@ -455,12 +453,7 @@ impl FormDatabase for ConnectionPool {
.collect_vec();

Ok(PostedAnswersDto {
uuid: answer
.user
.chunks_exact(16)
.map(Uuid::from_slice)
.collect::<Result<_, _>>()
.unwrap(),
uuid: Uuid::from_slice(answer.user.as_slice())?,
timestamp: answer.time_stamp,
form_id: 1, // TODO: answersテーブルにはform_idが存在しないので、追加して取得できるようにしたい
title: Some(answer.title),
Expand Down
1 change: 0 additions & 1 deletion server/infra/resource/src/dto.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use chrono::{DateTime, Utc};
use domain::form::models::{FormSettings, ResponsePeriod};
use itertools::Itertools;
use uuid::Uuid;

pub struct QuestionDto {
Expand Down
1 change: 0 additions & 1 deletion server/presentation/src/form_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use domain::{
use errors::{infra::InfraError, Error};
use resource::repository::RealInfrastructureRepository;
use serde_json::json;
use std::os::unix::raw::mode_t;
use usecase::form::FormUseCase;

pub async fn create_form_handler(
Expand Down

0 comments on commit 4eff579

Please sign in to comment.