-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from KusitmsHDmedi/feature/28-survey
[refactor] 코드 정리
- Loading branch information
Showing
16 changed files
with
212 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 37 additions & 34 deletions
71
src/main/java/com/kusithm/hdmedi_server/domain/survey/controller/SurveyController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BaseResponse<?>> 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<SurveyResultResponseDto> submitSurvey(@ModelAttribute SurveyDto surveyDTO) { | ||
SurveyResultResponseDto result = surveyService.processSurvey(surveyDTO); | ||
return ResponseEntity.ok(result); | ||
} | ||
// 설문 결과를 전송 | ||
@GetMapping("/get-survey-result") | ||
public ResponseEntity<Object> getSurveyResult() { | ||
SurveyResultResponseDto result = surveyService.getSurveyResult(); | ||
return ResponseEntity.ok(result); | ||
@GetMapping | ||
public ResponseEntity<BaseResponse<?>> getSurveyResult() { | ||
|
||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(BaseResponse.of(SuccessCode.OK, null)); | ||
} | ||
// 모든 설문 데이터를 조회 | ||
@GetMapping("/") | ||
public ResponseEntity<List<Survey>> getAllSurveys() { | ||
List<Survey> surveys = surveyService.getAllSurveys(); | ||
return ResponseEntity.ok(surveys); | ||
|
||
@GetMapping("/all") | ||
public ResponseEntity<BaseResponse<?>> getAllSurveys() { | ||
|
||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(BaseResponse.of(SuccessCode.OK, null)); | ||
} | ||
|
||
// 설문 상세 조회 - 결과 조회 | ||
@GetMapping("/{surveyId}/result") | ||
public ResponseEntity<SurveyResultResponseDto> getSurveyResult(@PathVariable Long surveyId) { | ||
SurveyResultResponseDto result = surveyService.getSurveyResultById(surveyId); | ||
return ResponseEntity.ok(result); | ||
@GetMapping("/result") | ||
public ResponseEntity<BaseResponse<?>> getSurveyResult(@RequestParam final Long surveyId) { | ||
|
||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(BaseResponse.of(SuccessCode.OK, null)); | ||
} | ||
|
||
// 설문 상세 조회 - 내용 조회 | ||
@GetMapping("/{surveyId}/content") | ||
public ResponseEntity<Survey> getSurveyContent(@PathVariable Long surveyId) { | ||
Survey survey = surveyService.getSurveyById(surveyId); | ||
return ResponseEntity.ok(survey); | ||
@GetMapping("/detail") | ||
public ResponseEntity<BaseResponse<?>> getSurveyContent(@RequestParam final Long surveyId) { | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(BaseResponse.of(SuccessCode.OK, null)); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/BaseSurvey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/EachSurvey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Respondent> parentsSurveyList = new ArrayList<>(); | ||
private List<Respondent> teacherSurveyList = new ArrayList<>(); | ||
|
||
public void addParentsSurveyList(Respondent parentsSurvey){ | ||
this.parentsSurveyList.add(parentsSurvey); | ||
} | ||
|
||
public void addTeacherSurveyList(Respondent teacherSurvey){ | ||
this.teacherSurveyList.add(teacherSurvey); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/Respondent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BaseSurvey> baseSurveyList = new ArrayList<>(); | ||
private int totalScore; | ||
|
||
public static Respondent createRespondent(List<BaseSurvey> baseSurveyList, int totalScore){ | ||
return Respondent.builder() | ||
.baseSurveyList(baseSurveyList) | ||
.totalScore(totalScore) | ||
.build(); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/Survey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
23 changes: 0 additions & 23 deletions
23
src/main/java/com/kusithm/hdmedi_server/domain/survey/domain/SurveyDto.java
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/request/BaseSurveyDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/kusithm/hdmedi_server/domain/survey/dto/request/CreateSurveyDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BaseSurveyDto> questionList; | ||
private int totalScore; | ||
} |
11 changes: 0 additions & 11 deletions
11
...in/java/com/kusithm/hdmedi_server/domain/survey/dto/response/SurveyResultResponseDto.java
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
src/main/java/com/kusithm/hdmedi_server/domain/survey/repository/Survey.java
This file was deleted.
Oops, something went wrong.
9 changes: 6 additions & 3 deletions
9
src/main/java/com/kusithm/hdmedi_server/domain/survey/repository/SurveyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Survey, Long> { | ||
} | ||
public interface SurveyRepository extends MongoRepository<Survey, String> { | ||
Optional<Survey> findByUserId(Long userId); | ||
} |
13 changes: 0 additions & 13 deletions
13
src/main/java/com/kusithm/hdmedi_server/domain/survey/service/ResourceNotFoundException.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.