Skip to content

Commit

Permalink
Merge pull request #29 from KusitmsHDmedi/feature/28-survey
Browse files Browse the repository at this point in the history
[refactor] 코드 정리
  • Loading branch information
RyuKwanKon authored Sep 16, 2023
2 parents 854aa4a + 0c782ac commit 3a0d67e
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 183 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
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));
}
}
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();
}
}
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);
}
}
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();
}

}
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;
}

This file was deleted.

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;
}
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;
}

This file was deleted.

This file was deleted.

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);
}

This file was deleted.

Loading

0 comments on commit 3a0d67e

Please sign in to comment.