diff --git a/server/Cargo.lock b/server/Cargo.lock index 9458c2e6..2133ab3b 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -993,6 +993,7 @@ dependencies = [ "sea-orm", "strum", "thiserror", + "uuid 1.4.1", ] [[package]] diff --git a/server/Cargo.toml b/server/Cargo.toml index 4c850680..2e25ed2f 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -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" diff --git a/server/entrypoint/src/main.rs b/server/entrypoint/src/main.rs index 8ef85688..730dde24 100644 --- a/server/entrypoint/src/main.rs +++ b/server/entrypoint/src/main.rs @@ -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, }; diff --git a/server/errors/Cargo.toml b/server/errors/Cargo.toml index 4e3b9097..b0ba8a25 100644 --- a/server/errors/Cargo.toml +++ b/server/errors/Cargo.toml @@ -9,3 +9,4 @@ edition = "2021" sea-orm = { workspace = true } strum = { workspace = true } thiserror = "1.0.48" +uuid = { workspace = true } diff --git a/server/errors/src/infra.rs b/server/errors/src/infra.rs index d6f5625d..a6219e4b 100644 --- a/server/errors/src/infra.rs +++ b/server/errors/src/infra.rs @@ -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)] diff --git a/server/infra/resource/Cargo.toml b/server/infra/resource/Cargo.toml index d2e51aa9..547366fb 100644 --- a/server/infra/resource/Cargo.toml +++ b/server/infra/resource/Cargo.toml @@ -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 } diff --git a/server/infra/resource/src/database/form.rs b/server/infra/resource/src/database/form.rs index a6a57db3..6c840480 100644 --- a/server/infra/resource/src/database/form.rs +++ b/server/infra/resource/src/database/form.rs @@ -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, @@ -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] @@ -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) @@ -455,12 +453,7 @@ impl FormDatabase for ConnectionPool { .collect_vec(); Ok(PostedAnswersDto { - uuid: answer - .user - .chunks_exact(16) - .map(Uuid::from_slice) - .collect::>() - .unwrap(), + uuid: Uuid::from_slice(answer.user.as_slice())?, timestamp: answer.time_stamp, form_id: 1, // TODO: answersテーブルにはform_idが存在しないので、追加して取得できるようにしたい title: Some(answer.title), diff --git a/server/infra/resource/src/dto.rs b/server/infra/resource/src/dto.rs index ca942ba6..3c89ffcd 100644 --- a/server/infra/resource/src/dto.rs +++ b/server/infra/resource/src/dto.rs @@ -1,6 +1,5 @@ use chrono::{DateTime, Utc}; use domain::form::models::{FormSettings, ResponsePeriod}; -use itertools::Itertools; use uuid::Uuid; pub struct QuestionDto { diff --git a/server/presentation/src/form_handler.rs b/server/presentation/src/form_handler.rs index 55e18b45..f058db93 100644 --- a/server/presentation/src/form_handler.rs +++ b/server/presentation/src/form_handler.rs @@ -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(