From 0a1470c9d13a67dda9ee282f36c56ee46605ef23 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Sat, 16 Sep 2023 21:07:20 +0900 Subject: [PATCH 01/12] =?UTF-8?q?[del]=20#28=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/survey/domain/SurveyDto.java | 23 ------------ .../dto/response/SurveyResultResponseDto.java | 11 ------ .../domain/survey/repository/Survey.java | 36 ------------------- .../service/ResourceNotFoundException.java | 13 ------- 4 files changed, 83 deletions(-) delete mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/SurveyDto.java delete mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/response/SurveyResultResponseDto.java delete mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/survey/repository/Survey.java delete mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/survey/service/ResourceNotFoundException.java diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/SurveyDto.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/SurveyDto.java deleted file mode 100644 index bc36c60..0000000 --- a/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/SurveyDto.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.kusithm.hdmedi_server.domain.survey.domain; - -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import lombok.*; - -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -@Builder -@Getter -@Entity -public class SurveyDto { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - private String question; - - private String answer; -} diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/response/SurveyResultResponseDto.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/response/SurveyResultResponseDto.java deleted file mode 100644 index 080ee11..0000000 --- a/src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/response/SurveyResultResponseDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.kusithm.hdmedi_server.domain.survey.dto.response; - -import lombok.Builder; -import lombok.Getter; - -@Getter -@Builder -public class SurveyResultResponseDto { - private String message; - private int score; -} diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/repository/Survey.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/repository/Survey.java deleted file mode 100644 index da25fc1..0000000 --- a/src/main/java/com/kusithm/hdmedi_server/domain/survey/repository/Survey.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.kusithm.hdmedi_server.domain.survey.repository; - - -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import org.springframework.data.annotation.Id; - -@Entity -public class Survey { - @jakarta.persistence.Id - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; // 엔터티의 식별자 - - private String question; - private String answer; - - // Getter와 Setter 메서드 - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public void setQuestion(String question) { - this.question = question; - } - - public void setAnswer(String answer) { - this.answer = answer; - } - -} diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/service/ResourceNotFoundException.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/service/ResourceNotFoundException.java deleted file mode 100644 index 216ebe4..0000000 --- a/src/main/java/com/kusithm/hdmedi_server/domain/survey/service/ResourceNotFoundException.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.kusithm.hdmedi_server.domain.survey.service; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(HttpStatus.NOT_FOUND) -public class ResourceNotFoundException extends RuntimeException { - - public ResourceNotFoundException(String message) { - super(message); - } -} - From 90dd309c86409954ff394079097a89073faead8b Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Sat, 16 Sep 2023 21:07:54 +0900 Subject: [PATCH 02/12] =?UTF-8?q?[chore]=20#28=20mongo=20db=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index 3b12466..f447aaf 100644 --- a/build.gradle +++ b/build.gradle @@ -55,6 +55,9 @@ dependencies { // redis implementation 'org.springframework.boot:spring-boot-starter-data-redis:2.3.1.RELEASE' + + //mongoDB + implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' } tasks.named('test') { From 0eaec74b703b8ddea556b41faadb60c097343598 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Sat, 16 Sep 2023 21:08:16 +0900 Subject: [PATCH 03/12] =?UTF-8?q?[chore]=20#28=20mongo=20db=20config=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/MongoConfig.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/com/kusithm/hdmedi_server/global/config/MongoConfig.java diff --git a/src/main/java/com/kusithm/hdmedi_server/global/config/MongoConfig.java b/src/main/java/com/kusithm/hdmedi_server/global/config/MongoConfig.java new file mode 100644 index 0000000..5013597 --- /dev/null +++ b/src/main/java/com/kusithm/hdmedi_server/global/config/MongoConfig.java @@ -0,0 +1,29 @@ +package com.kusithm.hdmedi_server.global.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.mongodb.MongoDatabaseFactory; +import org.springframework.data.mongodb.core.convert.DbRefResolver; +import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver; +import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper; +import org.springframework.data.mongodb.core.convert.MappingMongoConverter; +import org.springframework.data.mongodb.core.mapping.MongoMappingContext; + +@Configuration +public class MongoConfig { + // MongoDB 에 "_class" 들어가지 않게 설정 + @Autowired + private MongoMappingContext mongoMappingContext; + + @Bean + public MappingMongoConverter mappingMongoConverter( + MongoDatabaseFactory mongoDatabaseFactory, + MongoMappingContext mongoMappingContext + ) { + DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDatabaseFactory); + MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext); + converter.setTypeMapper(new DefaultMongoTypeMapper(null)); + return converter; + } +} From 0638639f6cebbbf77cea5497451d715fdc21170f Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Sat, 16 Sep 2023 21:46:56 +0900 Subject: [PATCH 04/12] =?UTF-8?q?[del]=20#28=20=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/MongoConfig.java | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 src/main/java/com/kusithm/hdmedi_server/global/config/MongoConfig.java diff --git a/src/main/java/com/kusithm/hdmedi_server/global/config/MongoConfig.java b/src/main/java/com/kusithm/hdmedi_server/global/config/MongoConfig.java deleted file mode 100644 index 5013597..0000000 --- a/src/main/java/com/kusithm/hdmedi_server/global/config/MongoConfig.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.kusithm.hdmedi_server.global.config; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.mongodb.MongoDatabaseFactory; -import org.springframework.data.mongodb.core.convert.DbRefResolver; -import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver; -import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper; -import org.springframework.data.mongodb.core.convert.MappingMongoConverter; -import org.springframework.data.mongodb.core.mapping.MongoMappingContext; - -@Configuration -public class MongoConfig { - // MongoDB 에 "_class" 들어가지 않게 설정 - @Autowired - private MongoMappingContext mongoMappingContext; - - @Bean - public MappingMongoConverter mappingMongoConverter( - MongoDatabaseFactory mongoDatabaseFactory, - MongoMappingContext mongoMappingContext - ) { - DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDatabaseFactory); - MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext); - converter.setTypeMapper(new DefaultMongoTypeMapper(null)); - return converter; - } -} From ffd1faf6359e110bd4af427a9b59c02359c076f6 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Sat, 16 Sep 2023 21:47:16 +0900 Subject: [PATCH 05/12] =?UTF-8?q?[chore]=20#28=20mongo=20=EC=95=A0?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/kusithm/hdmedi_server/HDmediServerApplication.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/kusithm/hdmedi_server/HDmediServerApplication.java b/src/main/java/com/kusithm/hdmedi_server/HDmediServerApplication.java index eb196bc..258aa3a 100644 --- a/src/main/java/com/kusithm/hdmedi_server/HDmediServerApplication.java +++ b/src/main/java/com/kusithm/hdmedi_server/HDmediServerApplication.java @@ -3,8 +3,14 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.data.mongodb.config.EnableMongoAuditing; +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; @SpringBootApplication +@EnableMongoAuditing public class HDmediServerApplication { // aws sdk 연동 static { From b8d1524ee225da82b9c02c1e360e0b93f71a9e7a Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Sat, 16 Sep 2023 21:47:45 +0900 Subject: [PATCH 06/12] =?UTF-8?q?[feat]=20#28=20mongo=20=EC=8A=A4=ED=82=A4?= =?UTF-8?q?=EB=A7=88=20=EA=B5=AC=EC=A1=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/survey/domain/BaseSurvey.java | 19 +++++++++++++++++ .../domain/survey/domain/EachSurvey.java | 21 +++++++++++++++++++ .../domain/survey/domain/Survey.java | 19 +++++++++++++++++ .../survey/dto/request/BaseSurveyDto.java | 12 +++++++++++ 4 files changed, 71 insertions(+) create mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/BaseSurvey.java create mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/EachSurvey.java create mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/Survey.java create mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/request/BaseSurveyDto.java diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/BaseSurvey.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/BaseSurvey.java new file mode 100644 index 0000000..fed115b --- /dev/null +++ b/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/BaseSurvey.java @@ -0,0 +1,19 @@ +package com.kusithm.hdmedi_server.domain.survey.domain; + +import lombok.Builder; +import lombok.Data; +import org.springframework.data.mongodb.core.mapping.Document; + +@Builder +@Data +public class BaseSurvey { + private String question; + private int score; + + public static BaseSurvey createBaseSurvey(String question, int score){ + return BaseSurvey.builder() + .question(question) + .score(score) + .build(); + } +} diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/EachSurvey.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/EachSurvey.java new file mode 100644 index 0000000..f9b3d3f --- /dev/null +++ b/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/EachSurvey.java @@ -0,0 +1,21 @@ +package com.kusithm.hdmedi_server.domain.survey.domain; + +import com.kusithm.hdmedi_server.global.common.BaseTimeEntity; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +public class EachSurvey { + private List parentsSurveyList = new ArrayList<>(); + private List teacherSurveyList = new ArrayList<>(); + + public void addParentsSurveyList(Respondent parentsSurvey){ + this.parentsSurveyList.add(parentsSurvey); + } + + public void addTeacherSurveyList(Respondent teacherSurvey){ + this.teacherSurveyList.add(teacherSurvey); + } +} diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/Survey.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/Survey.java new file mode 100644 index 0000000..3bb1888 --- /dev/null +++ b/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/Survey.java @@ -0,0 +1,19 @@ +package com.kusithm.hdmedi_server.domain.survey.domain; + +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.util.List; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Builder +@Getter +@Document(collection = "survey") +public class Survey { + @Id + private String id; + private Long userId; + private EachSurvey eachSurvey; +} diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/request/BaseSurveyDto.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/request/BaseSurveyDto.java new file mode 100644 index 0000000..1e14cc5 --- /dev/null +++ b/src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/request/BaseSurveyDto.java @@ -0,0 +1,12 @@ +package com.kusithm.hdmedi_server.domain.survey.dto.request; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +public class BaseSurveyDto { + private String question; + private int score; +} From efc491252be90665fd1cd5974916351c8e037418 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Sat, 16 Sep 2023 21:47:59 +0900 Subject: [PATCH 07/12] =?UTF-8?q?[feat]=20#28=20baseTimeEntity=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/common/BaseTimeEntity.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/com/kusithm/hdmedi_server/global/common/BaseTimeEntity.java diff --git a/src/main/java/com/kusithm/hdmedi_server/global/common/BaseTimeEntity.java b/src/main/java/com/kusithm/hdmedi_server/global/common/BaseTimeEntity.java new file mode 100644 index 0000000..46caf8c --- /dev/null +++ b/src/main/java/com/kusithm/hdmedi_server/global/common/BaseTimeEntity.java @@ -0,0 +1,22 @@ +package com.kusithm.hdmedi_server.global.common; + +import jakarta.persistence.Column; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; + +@Getter +@EntityListeners(AuditingEntityListener.class) +@MappedSuperclass +public abstract class BaseTimeEntity { + @CreatedDate + @Column(updatable = false) + private LocalDateTime createDate; + @LastModifiedDate + private LocalDateTime lastModifiedDate; +} From eaa43b563311c8f18876fc2d894a76fa2bc2feca Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Sat, 16 Sep 2023 21:48:16 +0900 Subject: [PATCH 08/12] =?UTF-8?q?[feat]=20#28=20create=20survey=20dto=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/survey/dto/request/CreateSurveyDto.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/request/CreateSurveyDto.java diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/request/CreateSurveyDto.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/request/CreateSurveyDto.java new file mode 100644 index 0000000..fe1b1c8 --- /dev/null +++ b/src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/request/CreateSurveyDto.java @@ -0,0 +1,14 @@ +package com.kusithm.hdmedi_server.domain.survey.dto.request; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +public class CreateSurveyDto { + private List questionList; + private int totalScore; +} From a7966dc58332525e3a5e4445708159dc4b0f8a1d Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Sat, 16 Sep 2023 21:48:40 +0900 Subject: [PATCH 09/12] =?UTF-8?q?[feat]=20#28=20mongo=20=EC=8A=A4=ED=82=A4?= =?UTF-8?q?=EB=A7=88=20=EA=B5=AC=EC=A1=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/survey/domain/Respondent.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/Respondent.java diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/Respondent.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/Respondent.java new file mode 100644 index 0000000..6f4ceab --- /dev/null +++ b/src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/Respondent.java @@ -0,0 +1,23 @@ +package com.kusithm.hdmedi_server.domain.survey.domain; + +import com.kusithm.hdmedi_server.global.common.BaseTimeEntity; +import lombok.Builder; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Builder +@Data +public class Respondent extends BaseTimeEntity { + private List baseSurveyList = new ArrayList<>(); + private int totalScore; + + public static Respondent createRespondent(List baseSurveyList, int totalScore){ + return Respondent.builder() + .baseSurveyList(baseSurveyList) + .totalScore(totalScore) + .build(); + } + +} From 51de802c63eeeb140410411e2ac8b82dfa1a8ea4 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Sat, 16 Sep 2023 21:49:06 +0900 Subject: [PATCH 10/12] =?UTF-8?q?[feat]=20#28=20survey=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20controller=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../survey/controller/SurveyController.java | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/controller/SurveyController.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/controller/SurveyController.java index de1e958..ddb72f0 100644 --- a/src/main/java/com/kusithm/hdmedi_server/domain/survey/controller/SurveyController.java +++ b/src/main/java/com/kusithm/hdmedi_server/domain/survey/controller/SurveyController.java @@ -1,54 +1,57 @@ package com.kusithm.hdmedi_server.domain.survey.controller; -import com.kusithm.hdmedi_server.domain.survey.domain.SurveyDto; -import com.kusithm.hdmedi_server.domain.survey.dto.response.SurveyResultResponseDto; -import com.kusithm.hdmedi_server.domain.survey.repository.Survey; +import com.kusithm.hdmedi_server.domain.survey.dto.request.CreateSurveyDto; import com.kusithm.hdmedi_server.domain.survey.service.SurveyService; +import com.kusithm.hdmedi_server.global.common.BaseResponse; +import com.kusithm.hdmedi_server.global.common.HDmediUser; +import com.kusithm.hdmedi_server.global.common.SuccessCode; +import com.kusithm.hdmedi_server.global.config.auth.AuthenticatedUserId; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import java.util.List; -@RestController -@RequestMapping("/surveys") +@RequiredArgsConstructor +@RequestMapping("/api/survey") +@Controller public class SurveyController { - private final SurveyService surveyService; - public SurveyController(SurveyService surveyService) { - this.surveyService = surveyService; + @PostMapping + public ResponseEntity> submitSurvey(@AuthenticatedUserId final HDmediUser hDmediUser, + @RequestBody final CreateSurveyDto requestDto) { + surveyService.processSurvey(hDmediUser, requestDto); + return ResponseEntity.status(HttpStatus.CREATED) + .body(BaseResponse.of(SuccessCode.CREATED, null)); } - //설문 결과 저장 - @PostMapping("/submit-survey") - public ResponseEntity submitSurvey(@ModelAttribute SurveyDto surveyDTO) { - SurveyResultResponseDto result = surveyService.processSurvey(surveyDTO); - return ResponseEntity.ok(result); - } - // 설문 결과를 전송 - @GetMapping("/get-survey-result") - public ResponseEntity getSurveyResult() { - SurveyResultResponseDto result = surveyService.getSurveyResult(); - return ResponseEntity.ok(result); + @GetMapping + public ResponseEntity> getSurveyResult() { + + return ResponseEntity.status(HttpStatus.OK) + .body(BaseResponse.of(SuccessCode.OK, null)); } - // 모든 설문 데이터를 조회 - @GetMapping("/") - public ResponseEntity> getAllSurveys() { - List surveys = surveyService.getAllSurveys(); - return ResponseEntity.ok(surveys); + + @GetMapping("/all") + public ResponseEntity> getAllSurveys() { + + return ResponseEntity.status(HttpStatus.OK) + .body(BaseResponse.of(SuccessCode.OK, null)); } - // 설문 상세 조회 - 결과 조회 - @GetMapping("/{surveyId}/result") - public ResponseEntity getSurveyResult(@PathVariable Long surveyId) { - SurveyResultResponseDto result = surveyService.getSurveyResultById(surveyId); - return ResponseEntity.ok(result); + @GetMapping("/result") + public ResponseEntity> getSurveyResult(@RequestParam final Long surveyId) { + + return ResponseEntity.status(HttpStatus.OK) + .body(BaseResponse.of(SuccessCode.OK, null)); } - // 설문 상세 조회 - 내용 조회 - @GetMapping("/{surveyId}/content") - public ResponseEntity getSurveyContent(@PathVariable Long surveyId) { - Survey survey = surveyService.getSurveyById(surveyId); - return ResponseEntity.ok(survey); + @GetMapping("/detail") + public ResponseEntity> getSurveyContent(@RequestParam final Long surveyId) { + return ResponseEntity.status(HttpStatus.OK) + .body(BaseResponse.of(SuccessCode.OK, null)); } } \ No newline at end of file From fe0efa794d2aa306c9354d83f956f30d38c3ae82 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Sat, 16 Sep 2023 21:49:21 +0900 Subject: [PATCH 11/12] =?UTF-8?q?[feat]=20#28=20survey=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20repository=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/survey/repository/SurveyRepository.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/repository/SurveyRepository.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/repository/SurveyRepository.java index da788b1..71323f3 100644 --- a/src/main/java/com/kusithm/hdmedi_server/domain/survey/repository/SurveyRepository.java +++ b/src/main/java/com/kusithm/hdmedi_server/domain/survey/repository/SurveyRepository.java @@ -1,7 +1,10 @@ package com.kusithm.hdmedi_server.domain.survey.repository; -import org.springframework.data.jpa.repository.JpaRepository; +import com.kusithm.hdmedi_server.domain.survey.domain.Survey; +import org.springframework.data.mongodb.repository.MongoRepository; +import java.util.Optional; -public interface SurveyRepository extends JpaRepository { -} \ No newline at end of file +public interface SurveyRepository extends MongoRepository { + Optional findByUserId(Long userId); +} From 0c782acd836017fa850f004374e024f4f86216c5 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Sat, 16 Sep 2023 21:49:30 +0900 Subject: [PATCH 12/12] =?UTF-8?q?[feat]=20#28=20survey=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20service=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/survey/service/SurveyService.java | 93 ++++++------------- 1 file changed, 30 insertions(+), 63 deletions(-) diff --git a/src/main/java/com/kusithm/hdmedi_server/domain/survey/service/SurveyService.java b/src/main/java/com/kusithm/hdmedi_server/domain/survey/service/SurveyService.java index f9e9e29..dee4b50 100644 --- a/src/main/java/com/kusithm/hdmedi_server/domain/survey/service/SurveyService.java +++ b/src/main/java/com/kusithm/hdmedi_server/domain/survey/service/SurveyService.java @@ -1,79 +1,46 @@ package com.kusithm.hdmedi_server.domain.survey.service; -import com.kusithm.hdmedi_server.domain.survey.domain.SurveyDto; -import com.kusithm.hdmedi_server.domain.survey.dto.response.SurveyResultResponseDto; -import com.kusithm.hdmedi_server.domain.survey.repository.Survey; +import com.kusithm.hdmedi_server.domain.survey.domain.BaseSurvey; +import com.kusithm.hdmedi_server.domain.survey.domain.Respondent; +import com.kusithm.hdmedi_server.domain.survey.domain.Survey; +import com.kusithm.hdmedi_server.domain.survey.dto.request.BaseSurveyDto; +import com.kusithm.hdmedi_server.domain.survey.dto.request.CreateSurveyDto; import com.kusithm.hdmedi_server.domain.survey.repository.SurveyRepository; -import org.springframework.beans.factory.annotation.Autowired; +import com.kusithm.hdmedi_server.global.common.HDmediUser; +import com.kusithm.hdmedi_server.global.error.exception.EntityNotFoundException; +import com.kusithm.hdmedi_server.global.error.exception.ErrorCode; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.stereotype.Service; import java.util.List; +import java.util.stream.Collectors; +@RequiredArgsConstructor +@Transactional @Service public class SurveyService { - - @Autowired - private SurveyRepository surveyRepository; - - public SurveyResultResponseDto processSurvey(SurveyDto surveyDTO) { - Survey survey = new Survey(); - survey.setQuestion(surveyDTO.getQuestion()); - survey.setAnswer(surveyDTO.getAnswer()); - - surveyRepository.save(survey); - - // 저장된 점수 계산 또는 다른 작업 수행 - int score = calculateScore(survey); - - // SurveyResultResponseDto 빌더를 사용하여 결과 생성 - return SurveyResultResponseDto.builder() - .message("설문 결과가 성공적으로 저장되었습니다.") - .score(score) - .build(); } - - // 설문 결과를 조회하는 메서드 추가 - public SurveyResultResponseDto getSurveyResult() { - // 데이터베이스에서 설문 결과를 조회하고, 결과 메시지와 저장된 점수를 생성하여 반환 - // 여기서는 임의의 값을 반환하도록 가정 - int score = 42; - return SurveyResultResponseDto.builder() - .message("설문 결과 조회가 성공적으로 완료되었습니다.") - .score(score) - .build(); - } - private int calculateScore(Survey survey) { - // 저장된 점수 계산 또는 다른 로직 수행 - // 여기서는 임의의 값을 반환하도록 가정 - return 42; - } - - public List getAllSurveys() { - // 모든 설문 데이터를 조회하여 반환 - return surveyRepository.findAll(); + private final SurveyRepository surveyRepository; + + public void processSurvey(HDmediUser hDmediUser, CreateSurveyDto createSurveyDto) { + List baseSurveyList = createBaseSurvey(createSurveyDto.getQuestionList()); + Respondent respondent = Respondent.createRespondent(baseSurveyList, createSurveyDto.getTotalScore()); + Survey currentSurvey = surveyRepository.findByUserId(hDmediUser.getId()).orElseThrow(() -> new EntityNotFoundException(ErrorCode.USER_NOT_FOUND)); + if(hDmediUser.getIsGuest()){ + currentSurvey.getEachSurvey().addTeacherSurveyList(respondent); + }else { + currentSurvey.getEachSurvey().addParentsSurveyList(respondent); + } } - public SurveyResultResponseDto getSurveyResultById(Long surveyId) { - // surveyId를 사용하여 해당 설문 결과를 데이터베이스에서 조회 - // 조회한 결과를 SurveyResultResponseDto로 변환하여 반환 - Survey survey = surveyRepository.findById(surveyId) - .orElseThrow(() -> new ResourceNotFoundException("설문 데이터가 없습니다. ID: " + surveyId)); - - // 저장된 점수 계산 또는 다른 작업 수행 - int score = calculateScore(survey); - - // SurveyResultResponseDto 빌더를 사용하여 결과 생성 - return SurveyResultResponseDto.builder() - .message("설문 결과 조회가 성공적으로 완료되었습니다.") - .score(score) - .build(); + private List createBaseSurvey(List questionList){ + return questionList.stream() + .map(baseSurveyDto -> + BaseSurvey.createBaseSurvey(baseSurveyDto.getQuestion(), baseSurveyDto.getScore())) + .collect(Collectors.toList()); } - public Survey getSurveyById(Long surveyId) { - // surveyId를 사용하여 해당 설문 데이터를 데이터베이스에서 조회 - // 만약 해당 설문 데이터가 존재하지 않으면 예외를 던질 수 있습니다. - return surveyRepository.findById(surveyId) - .orElseThrow(() -> new ResourceNotFoundException("설문 데이터가 없습니다. ID: " + surveyId)); - } }