-
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.
- Loading branch information
1 parent
2b69894
commit 4e4f18a
Showing
13 changed files
with
245 additions
and
43 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
2 changes: 2 additions & 0 deletions
2
...va/net/skhu/likelion12thteam03be/SelectColor/domain/repository/SelectColorRepository.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,9 @@ | ||
/* | ||
package net.skhu.likelion12thteam03be.SelectColor.domain.repository; | ||
import net.skhu.likelion12thteam03be.SelectColor.domain.SelectColor; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
public interface SelectColorRepository extends JpaRepository<SelectColor, Long> { | ||
} | ||
*/ |
23 changes: 23 additions & 0 deletions
23
src/main/java/net/skhu/likelion12thteam03be/emotion/application/EmotionService.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 net.skhu.likelion12thteam03be.emotion.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import net.skhu.likelion12thteam03be.emotion.domain.Emotion; | ||
import net.skhu.likelion12thteam03be.emotion.domain.Emotions; | ||
import net.skhu.likelion12thteam03be.emotion.domain.repository.EmotionRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class EmotionService { | ||
private EmotionRepository emotionRepository; | ||
|
||
/* public void saveEmotions(){ | ||
Emotion emotion = Emotion.builder() | ||
.name(Emotions.행복한) | ||
.furniture("모던 쇼파, 커피 테이블") | ||
.type("돌고래") | ||
.animalPic("~~~~~~~~~~~~~~~~~/post/1_dolphin.png") | ||
.build(); | ||
emotionRepository.save(emotion); | ||
}*/ | ||
} |
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
25 changes: 2 additions & 23 deletions
25
src/main/java/net/skhu/likelion12thteam03be/emotion/domain/Emotions.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,26 +1,5 @@ | ||
package net.skhu.likelion12thteam03be.emotion.domain; | ||
|
||
public enum Emotions { // converter | ||
HAPPY("행복한"), | ||
HURRIED("괴로운"), | ||
DULL("암울한"), | ||
TOUCHED("감동적인"), | ||
EXCITING("신나는"), | ||
RELAXED("편안한"), | ||
FEARFUL("두려운"), | ||
INTERESTING("흥미로운"), | ||
NERVOUS("긴장한"), | ||
ANXIOUS("불안한"), | ||
JOYFUL("기쁜"), | ||
CONCERNED("걱정되는"), | ||
EXCITED("설레는"), | ||
WEAPON("무기력한"), | ||
FRUSTRATED("답답한"), | ||
FRESH("상쾌한"); | ||
|
||
private final String name; | ||
|
||
Emotions(String name) { | ||
this.name = name; | ||
} | ||
public enum Emotions { | ||
행복한, 괴로운, 암울한, 감동적인, 신나는, 편안한, 두려운, 흥미로운, 긴장한, 불안한, 기쁜, 걱정되는, 설레는, 무기력한, 답답한, 상쾌한 | ||
} |
42 changes: 40 additions & 2 deletions
42
src/main/java/net/skhu/likelion12thteam03be/survey/api/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,7 +1,45 @@ | ||
package net.skhu.likelion12thteam03be.survey.api; | ||
|
||
import org.springframework.web.bind.annotation.RestController; | ||
import lombok.RequiredArgsConstructor; | ||
import net.skhu.likelion12thteam03be.survey.api.request.SurveySaveReqDto; | ||
import net.skhu.likelion12thteam03be.survey.api.response.SurveyResDto; | ||
import net.skhu.likelion12thteam03be.survey.application.SurveyService; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.security.Principal; | ||
|
||
@RestController | ||
@RequestMapping("/psy-test") | ||
@RequiredArgsConstructor | ||
public class SurveyController { | ||
} | ||
private final SurveyService surveyService; | ||
@PostMapping | ||
public ResponseEntity<SurveyResDto> createSurvey(@RequestBody SurveySaveReqDto reqDto, Principal principal) { | ||
SurveyResDto surveyResDto = surveyService.save(reqDto, principal); | ||
return new ResponseEntity<>(surveyResDto, HttpStatus.CREATED); | ||
} | ||
|
||
@DeleteMapping | ||
public ResponseEntity<String> deleteSurvey(Principal principal) { | ||
surveyService.delete(principal); | ||
return new ResponseEntity<>("설문조사 결과가 정상적으로 삭제되었습니다.", HttpStatus.OK); | ||
} | ||
|
||
/* @PatchMapping("/{surveyId}") | ||
public ResponseEntity<SurveyResDto> updateSurvey( | ||
@PathVariable Long surveyId, | ||
@RequestBody SurveySaveReqDto surveySaveReqDto, | ||
Principal principal) { | ||
SurveyResDto response = surveyService.update(surveyId, surveySaveReqDto, principal); | ||
return new ResponseEntity<>(response, HttpStatus.OK); | ||
} | ||
@GetMapping("/{surveyId}") | ||
public ResponseEntity<SurveyResDto> findByIdSurvey(@PathVariable Long surveyId) { | ||
SurveyResDto response = surveyService.findById(surveyId); | ||
return new ResponseEntity<>(response, HttpStatus.OK); | ||
}*/ | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/net/skhu/likelion12thteam03be/survey/api/request/SurveySaveReqDto.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,10 @@ | ||
package net.skhu.likelion12thteam03be.survey.api.request; | ||
|
||
import java.util.List; | ||
|
||
public record SurveySaveReqDto( | ||
Long emotionId, | ||
List<Long> colorIds, | ||
int score | ||
) { | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/net/skhu/likelion12thteam03be/survey/api/response/SurveyResDto.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,24 @@ | ||
package net.skhu.likelion12thteam03be.survey.api.response; | ||
|
||
import lombok.Builder; | ||
import net.skhu.likelion12thteam03be.post.domain.Post; | ||
import net.skhu.likelion12thteam03be.survey.domain.Survey; | ||
|
||
import java.util.List; | ||
|
||
@Builder | ||
public record SurveyResDto( | ||
String animalPic, | ||
String type, | ||
List<String> colorComments, // request 받을 때: List<Long> colorIds, | ||
List<Post> postList | ||
) { | ||
public static SurveyResDto from(Survey survey, List<String> colorComments) { | ||
return SurveyResDto.builder() | ||
.animalPic(survey.getEmotion().getAnimalPic()) | ||
.type(survey.getEmotion().getType()) | ||
.colorComments(colorComments) | ||
.postList(survey.getUser().getPosts()) | ||
.build(); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/main/java/net/skhu/likelion12thteam03be/survey/application/SurveyService.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,4 +1,105 @@ | ||
package net.skhu.likelion12thteam03be.survey.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import net.skhu.likelion12thteam03be.color.domian.Color; | ||
import net.skhu.likelion12thteam03be.color.domian.repository.ColorRepository; | ||
import net.skhu.likelion12thteam03be.emotion.domain.Emotion; | ||
import net.skhu.likelion12thteam03be.emotion.domain.repository.EmotionRepository; | ||
import net.skhu.likelion12thteam03be.survey.api.request.SurveySaveReqDto; | ||
import net.skhu.likelion12thteam03be.survey.api.response.SurveyResDto; | ||
import net.skhu.likelion12thteam03be.survey.domain.Survey; | ||
import net.skhu.likelion12thteam03be.survey.domain.repository.SurveyRepository; | ||
import net.skhu.likelion12thteam03be.survey.exception.SurveyAlreadyExistsException; | ||
import net.skhu.likelion12thteam03be.user.domain.User; | ||
import net.skhu.likelion12thteam03be.user.domain.repository.UserRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.security.Principal; | ||
import java.util.List; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class SurveyService { | ||
private final SurveyRepository surveyRepository; | ||
private final UserRepository userRepository; | ||
private final EmotionRepository emotionRepository; | ||
private final ColorRepository colorRepository; | ||
|
||
@Transactional | ||
public SurveyResDto save(SurveySaveReqDto surveySaveReqDto, Principal principal) { | ||
String loginId = principal.getName(); | ||
if (surveyRepository.existsByUserLoginId(loginId)){ | ||
throw new SurveyAlreadyExistsException("이미 설문조사 결과가 존재합니다. 유저 아이디 = " + loginId); | ||
} | ||
User user = userRepository.findByLoginId(loginId) | ||
.orElseThrow(() -> new IllegalArgumentException("유저 정보를 찾을 수 없습니다: " + loginId)); | ||
Emotion emotion = emotionRepository.findById(surveySaveReqDto.emotionId()) | ||
.orElseThrow(() -> new IllegalArgumentException("해당 감정을 찾을 수 없습니다: " + surveySaveReqDto.emotionId())); | ||
List<Color> colors = colorRepository.findAllById(surveySaveReqDto.colorIds()); | ||
|
||
Survey survey = Survey.builder() | ||
.score(surveySaveReqDto.score()) | ||
.emotion(emotion) | ||
.colors(colors) | ||
.user(user) | ||
.build(); | ||
surveyRepository.save(survey); | ||
|
||
List<String> colorComments = colors.stream() | ||
.map(Color::getComment) | ||
.toList(); | ||
|
||
return SurveyResDto.from(survey, colorComments); | ||
} | ||
|
||
@Transactional | ||
public void delete(Principal principal) { | ||
String loginId = principal.getName(); | ||
Survey survey = surveyRepository.findByUserLoginId(loginId); | ||
if (survey == null) { | ||
throw new IllegalArgumentException("삭제할 설문조사가 존재하지 않습니다: " + loginId); | ||
} | ||
surveyRepository.delete(survey); | ||
} | ||
|
||
/* @Transactional | ||
public SurveyResDto update(Long surveyId, SurveySaveReqDto surveySaveReqDto, Principal principal) { | ||
String loginId = principal.getName(); | ||
Survey survey = surveyRepository.findById(surveyId) | ||
.orElseThrow(() -> new IllegalArgumentException("설문조사 결과를 찾을 수 없습니다: " + surveyId)); | ||
if (!survey.getUser().getLoginId().equals(loginId)) { | ||
throw new IllegalArgumentException("해당 설문조사를 수정할 권한이 없습니다."); | ||
} | ||
Emotion emotion = emotionRepository.findById(surveySaveReqDto.emotionId()) | ||
.orElseThrow(() -> new IllegalArgumentException("해당 감정을 찾을 수 없습니다: " + surveySaveReqDto.emotionId())); | ||
List<Color> colors = colorRepository.findAllById(surveySaveReqDto.colorIds()); | ||
survey.update(surveySaveReqDto.score(), emotion, colors); | ||
surveyRepository.save(survey); | ||
List<String> colorComments = colors.stream() | ||
.map(Color::getComment) | ||
.toList(); | ||
return SurveyResDto.from(survey, colorComments); | ||
} | ||
public SurveyResDto findById(Long surveyId) { | ||
Survey survey = surveyRepository.findById(surveyId) | ||
.orElseThrow(() -> new IllegalArgumentException("설문조사 결과를 찾을 수 없습니다: " + surveyId)); | ||
List<Color> colors = survey.getColors(); | ||
List<String> colorComments = colors.stream() | ||
.map(Color::getComment) | ||
.toList(); | ||
return SurveyResDto.from(survey, colorComments); | ||
}*/ | ||
} |
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
7 changes: 7 additions & 0 deletions
7
...ain/java/net/skhu/likelion12thteam03be/survey/exception/SurveyAlreadyExistsException.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,7 @@ | ||
package net.skhu.likelion12thteam03be.survey.exception; | ||
|
||
public class SurveyAlreadyExistsException extends RuntimeException { | ||
public SurveyAlreadyExistsException(String message) { | ||
super(message); | ||
} | ||
} |
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