From 0a5cfa6b355bcfc2ed3b7d1d501cfdfbecc543c6 Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 15:30:28 +0900 Subject: [PATCH 01/27] =?UTF-8?q?refactor(#48):=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../najasin/domain/answer/dto/AnswerDTO.java | 13 - .../domain/answer/service/AnswerService.java | 65 ----- .../character/dto/AllCharacterItems.java | 31 --- .../domain/character/dto/CharacterItem.java | 18 -- .../domain/character/dto/CharacterItems.java | 19 -- .../character/{body => }/entity/Body.java | 8 +- .../entity/CharacterSet.java | 2 +- .../{expression => }/entity/Expression.java | 7 +- .../character/{face => }/entity/Face.java | 8 +- .../{body => }/repository/BodyRepository.java | 4 +- .../repository/CharacterSetRepository.java | 4 +- .../repository/ExpressionRepository.java | 4 +- .../{face => }/repository/FaceRepository.java | 4 +- .../{ => service}/CharacterService.java | 4 +- .../comment/service/CommentService.java | 60 ----- .../domain/keyword/dto/KeywordDTO.java | 15 -- .../keyword/service/KeywordService.java | 21 -- .../domain/question/entity/Question.java | 2 +- .../repository/QuestionRepository.java | 2 +- .../question/service/QuestionService.java | 33 --- .../user/controller/AuthController.java | 31 +++ .../user/controller/UserController.java | 241 ++---------------- .../com/najasin/domain/user/dto/Manual.java | 59 ----- .../com/najasin/domain/user/dto/Page.java | 60 ----- .../domain/user/dto/PageUpdateRequestDTO.java | 31 --- .../najasin/domain/user/dto/PutAnswer.java | 16 -- .../dto/message/UserTypeMessage.java | 2 +- .../dto/request/UserTypeUpdateRequest.java | 2 +- .../dto/response/UserTypeResponse.java | 2 +- .../com/najasin/domain/user/entity/User.java | 4 +- .../entity/userType}/UserType.java | 3 +- .../user/entity/userType/UserUserType.java | 36 +++ .../entity/userType}/UserUserTypeId.java | 4 +- .../repository/UserTypeRepository.java | 4 +- .../repository/UserUserTypeRepository.java | 6 +- .../domain/user/service/UserService.java | 13 +- .../service/UserTypeService.java | 6 +- .../user/service/UserUserTypeService.java | 47 ++++ .../service/UserKeywordService.java | 85 ------ .../controller/UserUserTypeController.java | 35 --- .../userUserType/entity/UserUserType.java | 58 ----- .../service/UserUserTypeService.java | 182 ------------- .../najasin/service/AnswerServiceTest.java | 5 +- .../najasin/service/CharacterServiceTest.java | 19 +- .../najasin/service/CommentServiceTest.java | 5 +- .../najasin/service/KeywordServiceTest.java | 20 +- .../najasin/service/QuestionServiceTest.java | 8 +- .../com/najasin/service/UserServiceTest.java | 16 +- .../najasin/service/UserTypeServiceTest.java | 6 +- .../service/UserUserTypeServiceTest.java | 28 +- 50 files changed, 235 insertions(+), 1123 deletions(-) delete mode 100644 src/main/java/com/najasin/domain/answer/dto/AnswerDTO.java delete mode 100644 src/main/java/com/najasin/domain/answer/service/AnswerService.java delete mode 100644 src/main/java/com/najasin/domain/character/dto/AllCharacterItems.java delete mode 100644 src/main/java/com/najasin/domain/character/dto/CharacterItem.java delete mode 100644 src/main/java/com/najasin/domain/character/dto/CharacterItems.java rename src/main/java/com/najasin/domain/character/{body => }/entity/Body.java (73%) rename src/main/java/com/najasin/domain/character/{characterset => }/entity/CharacterSet.java (90%) rename src/main/java/com/najasin/domain/character/{expression => }/entity/Expression.java (74%) rename src/main/java/com/najasin/domain/character/{face => }/entity/Face.java (73%) rename src/main/java/com/najasin/domain/character/{body => }/repository/BodyRepository.java (55%) rename src/main/java/com/najasin/domain/character/{characterset => }/repository/CharacterSetRepository.java (53%) rename src/main/java/com/najasin/domain/character/{expression => }/repository/ExpressionRepository.java (53%) rename src/main/java/com/najasin/domain/character/{face => }/repository/FaceRepository.java (55%) rename src/main/java/com/najasin/domain/character/{ => service}/CharacterService.java (96%) delete mode 100644 src/main/java/com/najasin/domain/comment/service/CommentService.java delete mode 100644 src/main/java/com/najasin/domain/keyword/dto/KeywordDTO.java delete mode 100644 src/main/java/com/najasin/domain/keyword/service/KeywordService.java delete mode 100644 src/main/java/com/najasin/domain/question/service/QuestionService.java create mode 100644 src/main/java/com/najasin/domain/user/controller/AuthController.java delete mode 100644 src/main/java/com/najasin/domain/user/dto/Manual.java delete mode 100644 src/main/java/com/najasin/domain/user/dto/Page.java delete mode 100644 src/main/java/com/najasin/domain/user/dto/PageUpdateRequestDTO.java delete mode 100644 src/main/java/com/najasin/domain/user/dto/PutAnswer.java rename src/main/java/com/najasin/domain/{userUserType => user}/dto/message/UserTypeMessage.java (80%) rename src/main/java/com/najasin/domain/{userUserType => user}/dto/request/UserTypeUpdateRequest.java (68%) rename src/main/java/com/najasin/domain/{userUserType => user}/dto/response/UserTypeResponse.java (73%) rename src/main/java/com/najasin/domain/{userType/entity => user/entity/userType}/UserType.java (86%) create mode 100644 src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java rename src/main/java/com/najasin/domain/{userUserType/entity => user/entity/userType}/UserUserTypeId.java (80%) rename src/main/java/com/najasin/domain/{userType => user}/repository/UserTypeRepository.java (68%) rename src/main/java/com/najasin/domain/{userUserType => user}/repository/UserUserTypeRepository.java (61%) rename src/main/java/com/najasin/domain/{userType => user}/service/UserTypeService.java (75%) create mode 100644 src/main/java/com/najasin/domain/user/service/UserUserTypeService.java delete mode 100644 src/main/java/com/najasin/domain/userKeyword/service/UserKeywordService.java delete mode 100644 src/main/java/com/najasin/domain/userUserType/controller/UserUserTypeController.java delete mode 100644 src/main/java/com/najasin/domain/userUserType/entity/UserUserType.java delete mode 100644 src/main/java/com/najasin/domain/userUserType/service/UserUserTypeService.java diff --git a/src/main/java/com/najasin/domain/answer/dto/AnswerDTO.java b/src/main/java/com/najasin/domain/answer/dto/AnswerDTO.java deleted file mode 100644 index 547e550..0000000 --- a/src/main/java/com/najasin/domain/answer/dto/AnswerDTO.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.najasin.domain.answer.dto; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -public class AnswerDTO { - private Long id; - private String answer; -} diff --git a/src/main/java/com/najasin/domain/answer/service/AnswerService.java b/src/main/java/com/najasin/domain/answer/service/AnswerService.java deleted file mode 100644 index c805272..0000000 --- a/src/main/java/com/najasin/domain/answer/service/AnswerService.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.najasin.domain.answer.service; - -import com.najasin.domain.answer.entity.Answer; -import com.najasin.domain.answer.entity.AnswerId; -import com.najasin.domain.answer.repository.AnswerRepository; -import com.najasin.domain.question.entity.Question; -import com.najasin.domain.question.repository.QuestionRepository; -import com.najasin.domain.user.dto.PageUpdateRequestDTO; -import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.userType.entity.UserType; -import com.najasin.domain.userType.repository.UserTypeRepository; -import jakarta.persistence.EntityNotFoundException; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -@Service -@RequiredArgsConstructor -public class AnswerService { - private final AnswerRepository answerRepository; - private final UserRepository userRepository; - private final QuestionRepository questionRepository; - private final UserTypeRepository userTypeRepository; - - @Transactional - public Answer save(String userId, Long questionId, String answer) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - Question question = questionRepository.findById(questionId).orElseThrow(EntityNotFoundException::new); - return answerRepository.save(new Answer(user, question, answer)); - } - @Transactional - public void deleteAnswers(String userId, String userTypeName) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - UserType userType = userTypeRepository.findByName(userTypeName).orElseThrow(EntityNotFoundException::new); - List answersToDelete = answerRepository.findByUser_Id(userId); - List answersLeft = new ArrayList<>(); - for (Answer answer : answersToDelete) { - if (answer.getQuestion().getUserType() == userType) { - answersLeft.add(answer); - } - } - answersToDelete = answersToDelete.stream().filter(answer -> answer.getQuestion().getUserType()==userType).collect(Collectors.toList()); - user.updateAnswer(answersLeft); - answerRepository.deleteAll(answersToDelete); - } - - @Transactional - public void updateAnswers(String userId, List dtos) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - List answers = new ArrayList<>(); - for (PageUpdateRequestDTO.AnswerDTO dto : dtos) { - Question question = questionRepository.findById(dto.getId()).orElseThrow(EntityNotFoundException::new); - Answer answer = new Answer(user, question, dto.getAnswer()); - answers.add(answer); - answerRepository.save(answer); - } - user.updateAnswer(answers); - } - -} diff --git a/src/main/java/com/najasin/domain/character/dto/AllCharacterItems.java b/src/main/java/com/najasin/domain/character/dto/AllCharacterItems.java deleted file mode 100644 index 2674494..0000000 --- a/src/main/java/com/najasin/domain/character/dto/AllCharacterItems.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.najasin.domain.character.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import java.util.ArrayList; -import java.util.List; - -@Getter -@Setter -@JsonInclude(JsonInclude.Include.NON_NULL) -public class AllCharacterItems { - String baseImage; - CharacterItems characterItems; - - @Getter - @Setter - @JsonInclude(JsonInclude.Include.NON_NULL) - static public class CharacterItems{ - List face = new ArrayList<>(); - List body = new ArrayList<>(); - List expression = new ArrayList<>(); - List set = new ArrayList<>(); - } - - -} - diff --git a/src/main/java/com/najasin/domain/character/dto/CharacterItem.java b/src/main/java/com/najasin/domain/character/dto/CharacterItem.java deleted file mode 100644 index ec0dbae..0000000 --- a/src/main/java/com/najasin/domain/character/dto/CharacterItem.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.najasin.domain.character.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.*; - -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -@Builder -@JsonInclude(JsonInclude.Include.NON_NULL) -public class CharacterItem { - private Long id; - private String name; - private String showCase; - private String layoutCase; -} - diff --git a/src/main/java/com/najasin/domain/character/dto/CharacterItems.java b/src/main/java/com/najasin/domain/character/dto/CharacterItems.java deleted file mode 100644 index 08266c7..0000000 --- a/src/main/java/com/najasin/domain/character/dto/CharacterItems.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.najasin.domain.character.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class CharacterItems { - private CharacterItem face; - private CharacterItem body; - private CharacterItem expression; - private CharacterItem set; -} diff --git a/src/main/java/com/najasin/domain/character/body/entity/Body.java b/src/main/java/com/najasin/domain/character/entity/Body.java similarity index 73% rename from src/main/java/com/najasin/domain/character/body/entity/Body.java rename to src/main/java/com/najasin/domain/character/entity/Body.java index 98653fb..fab89c5 100644 --- a/src/main/java/com/najasin/domain/character/body/entity/Body.java +++ b/src/main/java/com/najasin/domain/character/entity/Body.java @@ -1,4 +1,6 @@ -package com.najasin.domain.character.body.entity; +package com.najasin.domain.character.entity; + +import com.najasin.domain.character.dto.response.CharacterItem; import jakarta.persistence.*; import lombok.AccessLevel; @@ -24,4 +26,8 @@ public class Body { @Column(name = "body_layout_url",columnDefinition = "TEXT") private String layout_url; + + public CharacterItem toCharacterItem() { + return new CharacterItem(id, show_url, layout_url); + } } diff --git a/src/main/java/com/najasin/domain/character/characterset/entity/CharacterSet.java b/src/main/java/com/najasin/domain/character/entity/CharacterSet.java similarity index 90% rename from src/main/java/com/najasin/domain/character/characterset/entity/CharacterSet.java rename to src/main/java/com/najasin/domain/character/entity/CharacterSet.java index 381148e..f23a918 100644 --- a/src/main/java/com/najasin/domain/character/characterset/entity/CharacterSet.java +++ b/src/main/java/com/najasin/domain/character/entity/CharacterSet.java @@ -1,4 +1,4 @@ -package com.najasin.domain.character.characterset.entity; +package com.najasin.domain.character.entity; import jakarta.persistence.*; import lombok.AccessLevel; diff --git a/src/main/java/com/najasin/domain/character/expression/entity/Expression.java b/src/main/java/com/najasin/domain/character/entity/Expression.java similarity index 74% rename from src/main/java/com/najasin/domain/character/expression/entity/Expression.java rename to src/main/java/com/najasin/domain/character/entity/Expression.java index eb35ba8..a2fddff 100644 --- a/src/main/java/com/najasin/domain/character/expression/entity/Expression.java +++ b/src/main/java/com/najasin/domain/character/entity/Expression.java @@ -1,4 +1,6 @@ -package com.najasin.domain.character.expression.entity; +package com.najasin.domain.character.entity; + +import com.najasin.domain.character.dto.response.CharacterItem; import jakarta.persistence.*; import lombok.AccessLevel; @@ -25,4 +27,7 @@ public class Expression { @Column(name = "expression_layout_url",columnDefinition = "TEXT") private String layout_url; + public CharacterItem toCharacterItem() { + return new CharacterItem(id, show_url, layout_url); + } } diff --git a/src/main/java/com/najasin/domain/character/face/entity/Face.java b/src/main/java/com/najasin/domain/character/entity/Face.java similarity index 73% rename from src/main/java/com/najasin/domain/character/face/entity/Face.java rename to src/main/java/com/najasin/domain/character/entity/Face.java index 5bb02cd..34477cf 100644 --- a/src/main/java/com/najasin/domain/character/face/entity/Face.java +++ b/src/main/java/com/najasin/domain/character/entity/Face.java @@ -1,4 +1,6 @@ -package com.najasin.domain.character.face.entity; +package com.najasin.domain.character.entity; + +import com.najasin.domain.character.dto.response.CharacterItem; import jakarta.persistence.*; import lombok.AccessLevel; @@ -24,4 +26,8 @@ public class Face { @Column(name = "face_layout_url",columnDefinition = "TEXT") private String layout_url; + + public CharacterItem toCharacterItem() { + return new CharacterItem(id, show_url, layout_url); + } } diff --git a/src/main/java/com/najasin/domain/character/body/repository/BodyRepository.java b/src/main/java/com/najasin/domain/character/repository/BodyRepository.java similarity index 55% rename from src/main/java/com/najasin/domain/character/body/repository/BodyRepository.java rename to src/main/java/com/najasin/domain/character/repository/BodyRepository.java index 1812973..4c8816f 100644 --- a/src/main/java/com/najasin/domain/character/body/repository/BodyRepository.java +++ b/src/main/java/com/najasin/domain/character/repository/BodyRepository.java @@ -1,6 +1,6 @@ -package com.najasin.domain.character.body.repository; +package com.najasin.domain.character.repository; -import com.najasin.domain.character.body.entity.Body; +import com.najasin.domain.character.entity.Body; import org.springframework.data.jpa.repository.JpaRepository; public interface BodyRepository extends JpaRepository { diff --git a/src/main/java/com/najasin/domain/character/characterset/repository/CharacterSetRepository.java b/src/main/java/com/najasin/domain/character/repository/CharacterSetRepository.java similarity index 53% rename from src/main/java/com/najasin/domain/character/characterset/repository/CharacterSetRepository.java rename to src/main/java/com/najasin/domain/character/repository/CharacterSetRepository.java index a3924a0..0d9c67d 100644 --- a/src/main/java/com/najasin/domain/character/characterset/repository/CharacterSetRepository.java +++ b/src/main/java/com/najasin/domain/character/repository/CharacterSetRepository.java @@ -1,6 +1,6 @@ -package com.najasin.domain.character.characterset.repository; +package com.najasin.domain.character.repository; -import com.najasin.domain.character.characterset.entity.CharacterSet; +import com.najasin.domain.character.entity.CharacterSet; import org.springframework.data.jpa.repository.JpaRepository; public interface CharacterSetRepository extends JpaRepository { diff --git a/src/main/java/com/najasin/domain/character/expression/repository/ExpressionRepository.java b/src/main/java/com/najasin/domain/character/repository/ExpressionRepository.java similarity index 53% rename from src/main/java/com/najasin/domain/character/expression/repository/ExpressionRepository.java rename to src/main/java/com/najasin/domain/character/repository/ExpressionRepository.java index cba6e28..e21372d 100644 --- a/src/main/java/com/najasin/domain/character/expression/repository/ExpressionRepository.java +++ b/src/main/java/com/najasin/domain/character/repository/ExpressionRepository.java @@ -1,6 +1,6 @@ -package com.najasin.domain.character.expression.repository; +package com.najasin.domain.character.repository; -import com.najasin.domain.character.expression.entity.Expression; +import com.najasin.domain.character.entity.Expression; import org.springframework.data.jpa.repository.JpaRepository; public interface ExpressionRepository extends JpaRepository { diff --git a/src/main/java/com/najasin/domain/character/face/repository/FaceRepository.java b/src/main/java/com/najasin/domain/character/repository/FaceRepository.java similarity index 55% rename from src/main/java/com/najasin/domain/character/face/repository/FaceRepository.java rename to src/main/java/com/najasin/domain/character/repository/FaceRepository.java index 7684356..1bf9d18 100644 --- a/src/main/java/com/najasin/domain/character/face/repository/FaceRepository.java +++ b/src/main/java/com/najasin/domain/character/repository/FaceRepository.java @@ -1,6 +1,6 @@ -package com.najasin.domain.character.face.repository; +package com.najasin.domain.character.repository; -import com.najasin.domain.character.face.entity.Face; +import com.najasin.domain.character.entity.Face; import org.springframework.data.jpa.repository.JpaRepository; public interface FaceRepository extends JpaRepository { diff --git a/src/main/java/com/najasin/domain/character/CharacterService.java b/src/main/java/com/najasin/domain/character/service/CharacterService.java similarity index 96% rename from src/main/java/com/najasin/domain/character/CharacterService.java rename to src/main/java/com/najasin/domain/character/service/CharacterService.java index 2b1fc5c..7fa3166 100644 --- a/src/main/java/com/najasin/domain/character/CharacterService.java +++ b/src/main/java/com/najasin/domain/character/service/CharacterService.java @@ -1,6 +1,6 @@ package com.najasin.domain.character; -import com.najasin.domain.character.body.entity.Body; +import com.najasin.domain.character.entity.Body; import com.najasin.domain.character.body.repository.BodyRepository; import com.najasin.domain.character.characterset.entity.CharacterSet; import com.najasin.domain.character.characterset.repository.CharacterSetRepository; @@ -10,7 +10,7 @@ import com.najasin.domain.character.expression.repository.ExpressionRepository; import com.najasin.domain.character.face.entity.Face; import com.najasin.domain.character.face.repository.FaceRepository; -import com.najasin.domain.user.dto.Page; + import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/najasin/domain/comment/service/CommentService.java b/src/main/java/com/najasin/domain/comment/service/CommentService.java deleted file mode 100644 index 04d41b5..0000000 --- a/src/main/java/com/najasin/domain/comment/service/CommentService.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.najasin.domain.comment.service; - -import com.najasin.domain.comment.entity.Comment; -import com.najasin.domain.comment.entity.CommentId; -import com.najasin.domain.comment.repository.CommentRepository; -import com.najasin.domain.question.entity.Question; -import com.najasin.domain.question.repository.QuestionRepository; -import com.najasin.domain.user.dto.Page; -import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.userType.entity.UserType; -import com.najasin.domain.userType.repository.UserTypeRepository; -import com.najasin.global.audit.AuditEntity; -import jakarta.persistence.EntityNotFoundException; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.List; - -@Service -@RequiredArgsConstructor -public class CommentService { - private final CommentRepository commentRepository; - private final QuestionRepository questionRepository; - private final UserTypeRepository userTypeRepository; - private final UserRepository userRepository; - - @Transactional - public Comment save(String userId, Long questionId, String nickname, String comment) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - Question question = questionRepository.findById(questionId).orElseThrow(EntityNotFoundException::new); - Comment newComment = Comment.builder() - .user(user) - .question(question) - .comment(comment) - .nickname(nickname) - .auditEntity(new AuditEntity()) - .build(); - - commentRepository.save(newComment); - user.getComments().add(newComment); - question.getComments().add(newComment); - return newComment; - } - - @Transactional - public boolean delete(String userId, Long questionId) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - Question question = questionRepository.findById(questionId).orElseThrow(EntityNotFoundException::new); - Comment comment = commentRepository.findById(new CommentId(user, question)).orElseThrow(EntityNotFoundException::new); - user.getComments().remove(comment); - question.getComments().remove(comment); - commentRepository.delete(comment); - return true; - } - - -} diff --git a/src/main/java/com/najasin/domain/keyword/dto/KeywordDTO.java b/src/main/java/com/najasin/domain/keyword/dto/KeywordDTO.java deleted file mode 100644 index 45663a2..0000000 --- a/src/main/java/com/najasin/domain/keyword/dto/KeywordDTO.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.najasin.domain.keyword.dto; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@RequiredArgsConstructor -@AllArgsConstructor -public class KeywordDTO { - private Long keywordID; - private int percent; -} diff --git a/src/main/java/com/najasin/domain/keyword/service/KeywordService.java b/src/main/java/com/najasin/domain/keyword/service/KeywordService.java deleted file mode 100644 index 844aa46..0000000 --- a/src/main/java/com/najasin/domain/keyword/service/KeywordService.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.najasin.domain.keyword.service; - -import com.najasin.domain.keyword.entity.Keyword; -import com.najasin.domain.keyword.repository.KeywordRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.List; - -@Service -@RequiredArgsConstructor -public class KeywordService { - private final KeywordRepository keywordRepository; - - @Transactional - public List getAllKeywords() { - return keywordRepository.findAll().stream().map(Keyword::getName).toList(); - } -} diff --git a/src/main/java/com/najasin/domain/question/entity/Question.java b/src/main/java/com/najasin/domain/question/entity/Question.java index 1ebe312..1abdeb6 100644 --- a/src/main/java/com/najasin/domain/question/entity/Question.java +++ b/src/main/java/com/najasin/domain/question/entity/Question.java @@ -1,7 +1,7 @@ package com.najasin.domain.question.entity; import com.najasin.domain.comment.entity.Comment; -import com.najasin.domain.userType.entity.UserType; +import com.najasin.domain.user.entity.userType.UserType; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/najasin/domain/question/repository/QuestionRepository.java b/src/main/java/com/najasin/domain/question/repository/QuestionRepository.java index af64ba1..b3274a8 100644 --- a/src/main/java/com/najasin/domain/question/repository/QuestionRepository.java +++ b/src/main/java/com/najasin/domain/question/repository/QuestionRepository.java @@ -2,7 +2,7 @@ import com.najasin.domain.question.entity.Question; import com.najasin.domain.question.entity.QuestionType; -import com.najasin.domain.userType.entity.UserType; +import com.najasin.domain.user.entity.userType.UserType; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; diff --git a/src/main/java/com/najasin/domain/question/service/QuestionService.java b/src/main/java/com/najasin/domain/question/service/QuestionService.java deleted file mode 100644 index a2cb609..0000000 --- a/src/main/java/com/najasin/domain/question/service/QuestionService.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.najasin.domain.question.service; - -import com.najasin.domain.question.entity.Question; -import com.najasin.domain.question.entity.QuestionType; -import com.najasin.domain.question.repository.QuestionRepository; -import com.najasin.domain.user.dto.Page; -import com.najasin.domain.userType.entity.UserType; -import com.najasin.domain.userType.repository.UserTypeRepository; -import jakarta.persistence.EntityNotFoundException; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Service -@RequiredArgsConstructor -public class QuestionService { - private final QuestionRepository questionRepository; - private final UserTypeRepository userTypeRepository; - @Transactional - public List getQuestionByQuestionTypeAndUserType(QuestionType questionType, String userTypeName) { - List ret = new ArrayList<>(); - UserType userType = userTypeRepository.findByName(userTypeName).orElseThrow(EntityNotFoundException::new); - for (Question question : questionRepository.getQuestionsByQuestionTypeAndUserType(questionType, userType)) { - ret.add(new Page.Questions(question.getId(), question.getQuestion())); - } - return ret; - } -} diff --git a/src/main/java/com/najasin/domain/user/controller/AuthController.java b/src/main/java/com/najasin/domain/user/controller/AuthController.java new file mode 100644 index 0000000..8d31376 --- /dev/null +++ b/src/main/java/com/najasin/domain/user/controller/AuthController.java @@ -0,0 +1,31 @@ +package com.najasin.domain.user.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import com.najasin.domain.user.dto.message.UserResponse; +import com.najasin.domain.user.service.UserService; +import com.najasin.global.annotation.AccessToken; +import com.najasin.global.annotation.RefreshToken; +import com.najasin.global.response.ApiResponse; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/auth") + +public class AuthController { + private final UserService userService; + + @PostMapping("/logout") + public ResponseEntity> logout(@AccessToken String accessToken, @RefreshToken String refreshToken) { + userService.logout(accessToken, refreshToken); + + return new ResponseEntity<>( + ApiResponse.createSuccess(UserResponse.SUCCESS_LOGOUT.getMessage()), + HttpStatus.OK + ); + } +} diff --git a/src/main/java/com/najasin/domain/user/controller/UserController.java b/src/main/java/com/najasin/domain/user/controller/UserController.java index 68a9428..2b7d4bf 100644 --- a/src/main/java/com/najasin/domain/user/controller/UserController.java +++ b/src/main/java/com/najasin/domain/user/controller/UserController.java @@ -1,231 +1,46 @@ package com.najasin.domain.user.controller; -import static java.util.Objects.*; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; -import com.najasin.domain.answer.service.AnswerService; -import com.najasin.domain.answer.dto.AnswerDTO; -import com.najasin.domain.character.CharacterService; -import com.najasin.domain.character.dto.AllCharacterItems; -import com.najasin.domain.character.dto.CharacterItems; -import com.najasin.domain.comment.service.CommentService; -import com.najasin.domain.keyword.repository.KeywordRepository; -import com.najasin.domain.keyword.service.KeywordService; -import com.najasin.domain.keyword.service.KeywordService; -import com.najasin.domain.question.entity.QuestionType; -import com.najasin.domain.question.service.QuestionService; -import com.najasin.domain.user.dto.*; -import com.najasin.domain.user.dto.message.UserInfoResponse; import com.najasin.domain.user.entity.User; -import com.najasin.domain.userKeyword.service.UserKeywordService; -import com.najasin.domain.userUserType.entity.UserUserType; -import com.najasin.domain.userUserType.service.UserUserTypeService; +import com.najasin.domain.user.dto.message.UserTypeMessage; +import com.najasin.domain.user.dto.request.UserTypeUpdateRequest; +import com.najasin.domain.user.dto.response.UserTypeResponse; +import com.najasin.domain.user.service.UserUserTypeService; import com.najasin.global.annotation.AuthorizeUser; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import com.najasin.domain.user.dto.message.UserResponse; -import com.najasin.domain.user.service.UserService; -import com.najasin.global.annotation.AccessToken; -import com.najasin.global.annotation.RefreshToken; import com.najasin.global.response.ApiResponse; import lombok.RequiredArgsConstructor; -import java.util.ArrayList; -import java.util.List; - -@RequiredArgsConstructor @RestController -@RequestMapping("/api") - +@RequestMapping("/api/user") +@RequiredArgsConstructor public class UserController { - private final UserService userService; - private final AnswerService answerService; - private final QuestionService questionService; - private final CommentService commentService; private final UserUserTypeService userUserTypeService; - private final UserKeywordService userKeywordService; - private final CharacterService characterService; - private final KeywordService keywordService; - private String basicURL = "https://najasin-images.s3.ap-northeast-2.amazonaws.com/characters/base-character.svg"; - - @PostMapping("/logout") - public ResponseEntity> logout(@AccessToken String accessToken, @RefreshToken String refreshToken) { - userService.logout(accessToken, refreshToken); - - return new ResponseEntity<>( - ApiResponse.createSuccess(UserResponse.SUCCESS_LOGOUT.getMessage()), - HttpStatus.OK - ); - } - - @PutMapping("/{userTypeName}/answers") - public ResponseEntity> putAnswers( - @PathVariable String userTypeName, - @RequestBody PutAnswer putAnswer, - @AuthorizeUser User user - ) { - String userId = user.getId(); - answerService.deleteAnswers(userId, userTypeName); - for (AnswerDTO dto : putAnswer.getAnswers()) { - answerService.save(userId, dto.getId(), dto.getAnswer()); - } - return new ResponseEntity<>( - ApiResponse.createSuccess(UserResponse.SUCCESS_UPDATE.getMessage()), - HttpStatus.OK - ); - } - - @PutMapping("/{userTypeName}/character") - public ResponseEntity> putCharacter( - @PathVariable String userTypeName, - @RequestBody CharacterItems dto, - @AuthorizeUser User user - - ) { - - String userId = user.getId(); - userUserTypeService.updateCharacter(userId, userTypeName, dto); - return new ResponseEntity<>( - ApiResponse.createSuccess(UserResponse.SUCCESS_UPDATE.getMessage()), - HttpStatus.OK - ); - } - - - @PutMapping("/{userTypeName}/nickname") - public ResponseEntity> putNickname( - @PathVariable String userTypeName, - @RequestBody String nickname, - @AuthorizeUser User user - - ) { - - String userId = user.getId(); - userService.updateNickname(userId, nickname); - return new ResponseEntity<>( - ApiResponse.createSuccess(UserResponse.SUCCESS_UPDATE.getMessage()), - HttpStatus.OK - ); - } - - @PostMapping("/{userTypeName}/my-manual") - public ResponseEntity> postMyManual( - @PathVariable String userTypeName, - @RequestBody PageUpdateRequestDTO dto, - @AuthorizeUser User user - ) { - - String userId = user.getId(); - userService.updateNickname(userId, dto.getNickname()); - userUserTypeService.updateCharacter(userId, userTypeName, dto.getCharacterItems()); - answerService.deleteAnswers(userId, userTypeName); - answerService.updateAnswers(userId, dto.getAnswers()); - userKeywordService.updateByUser(userId, dto.getKeywordPercents()); - return new ResponseEntity<>( - ApiResponse.createSuccessWithData(UserResponse.SUCCESS_UPDATE.getMessage(), new UserInfoResponse(userId, userTypeName)), - HttpStatus.OK - ); - } - - @PostMapping("/{userTypeName}/others-manual") - public ResponseEntity> postOthersManual( - @PathVariable String userTypeName, - @RequestParam String userId, - @RequestBody PageUpdateRequestDTO dto - ) { - for (PageUpdateRequestDTO.AnswerDTO answerDTO : dto.getAnswers()) { - commentService.save(userId, answerDTO.getId(), dto.getNickname(), answerDTO.getAnswer()); - } - for (String keyword : dto.getOtherKeywordPercents().keySet()) { - userKeywordService.updateByOthers(userId, keyword, dto.getOtherKeywordPercents().get(keyword)); - } - return new ResponseEntity<>( - ApiResponse.createSuccessWithData(UserResponse.SUCCESS_UPDATE.getMessage(), new UserInfoResponse(userId, userTypeName)), - HttpStatus.OK - ); - } - - @GetMapping("/{userTypeName}/my-manual") - public ResponseEntity> getMyManual( - @PathVariable String userTypeName, - @AuthorizeUser User user - ) { - Manual manual = new Manual(); - - String userId = user.getId(); - if(!isNull(user)) { - manual.setNickname(user.getId()); - } - manual.setBaseImage(basicURL); - manual.setExampleKeywords(keywordService.getAllKeywords()); - manual.setCharacterItems(characterService.getAllCharacterItems().getCharacterItems()); - manual.setQuestions(questionService.getQuestionByQuestionTypeAndUserType(QuestionType.FOR_USER, userTypeName)); - return new ResponseEntity<>( - ApiResponse.createSuccessWithData(UserResponse.SUCCESS_GET_PAGE.getMessage(), manual), - HttpStatus.OK - ); - } - - @GetMapping("/{userTypeName}/others-manual") - public ResponseEntity> getOthersPage(@PathVariable String userTypeName, @RequestParam String userId) { - Page page = new Page(); - User user = userService.findById(userId); - - page.setQuestions(questionService.getQuestionByQuestionTypeAndUserType(QuestionType.FOR_OTHERS, userTypeName)); - page.setNickname(user.getNickname()); - page.setBaseImage(basicURL); - CharacterItems characterInfoDTO = userUserTypeService.getCharacter(userId, userTypeName); - page.setCharacterItems(new CharacterItems(characterInfoDTO.getFace(), characterInfoDTO.getBody(), characterInfoDTO.getExpression(), characterInfoDTO.getSet())); - page.setMyManualQAPair(userUserTypeService.getQAByUserIdAndUserTypeForUser(userId, userTypeName, QuestionType.FOR_USER)); - - page.setOriginKeywordPercents(userKeywordService.getOriginKeywordPercents(userId)); - page.setOtherKeywordPercents(userKeywordService.getOtherKeywordPercents(userId)); - return new ResponseEntity<>( - ApiResponse.createSuccessWithData(UserResponse.SUCCESS_GET_PAGE.getMessage(), page), - HttpStatus.OK - ); - } - - @GetMapping("/{userTypeName}/mypage") + @GetMapping("/{userType}/mypage") public ResponseEntity> getMyPage( - @PathVariable String userTypeName, - @AuthorizeUser User user - ) { - String userId = user.getId(); - Page page = new Page(); - - List userTypes = new ArrayList<>(); - for (UserUserType uut : userUserTypeService.getUserUserTypesByUserId(userId)) { - userTypes.add(uut.getUserType().getName()); - } - page.setUserTypes(userTypes); - - page.setNickname(user.getNickname()); - page.setBaseImage(basicURL); - CharacterItems characterInfoDTO = userUserTypeService.getCharacter(userId, userTypeName); - page.setCharacterItems(new CharacterItems(characterInfoDTO.getFace(), characterInfoDTO.getBody(), characterInfoDTO.getExpression(), characterInfoDTO.getSet())); - - page.setMyManualQAPair(userUserTypeService.getQAByUserIdAndUserTypeForUser(userId, userTypeName, QuestionType.FOR_USER)); - page.setOthersManualQAPair(userUserTypeService.getOtherManualByUserIdAndUserType(userId, userTypeName, QuestionType.FOR_OTHERS)); - - page.setOriginKeywordPercents(userKeywordService.getOriginKeywordPercents(userId)); - page.setOtherKeywordPercents(userKeywordService.getOtherKeywordPercents(userId)); - - return new ResponseEntity<>( - ApiResponse.createSuccessWithData(UserResponse.SUCCESS_GET_PAGE.getMessage(), page), - HttpStatus.OK - ); + @AuthorizeUser User user, + @PathVariable String userType, + @RequestParam(name = "userId") String userId) { + return null; } - @GetMapping("/characterItems") - public ResponseEntity> getCharacterItems(){ - AllCharacterItems allCharacterItems = characterService.getAllCharacterItems(); - return new ResponseEntity<>( - ApiResponse.createSuccessWithData(UserResponse.SUCCESS_GET_PAGE.getMessage(), allCharacterItems), - HttpStatus.OK - ); + @PutMapping("/type") + public ResponseEntity> updateUserType(@AuthorizeUser User user, + @RequestBody @Validated UserTypeUpdateRequest request) { + String updatedUserType = userUserTypeService.updateUserType(user, request.userType()); + + return ResponseEntity.ok(ApiResponse.createSuccessWithData( + UserTypeMessage.SUCCESS_UPDATE_USER_TYPE.getMsg(), + UserTypeResponse.of(updatedUserType))); } } diff --git a/src/main/java/com/najasin/domain/user/dto/Manual.java b/src/main/java/com/najasin/domain/user/dto/Manual.java deleted file mode 100644 index 597fb48..0000000 --- a/src/main/java/com/najasin/domain/user/dto/Manual.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.najasin.domain.user.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.najasin.domain.character.dto.AllCharacterItems; -import com.najasin.domain.character.dto.CharacterItems; -import lombok.*; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -@Getter -@Setter -@JsonInclude(JsonInclude.Include.NON_NULL) -public class Manual { - private List userTypes; - private String nickname; - private String baseImage; - private AllCharacterItems.CharacterItems characterItems; - private List myManualQAPair; - private List othersManualQAPair; - private List questions; - private List exampleKeywords; - private Map originKeywordPercents; - private Map otherKeywordPercents; - public Manual() { - this.userTypes = new ArrayList<>(); - userTypes.add("JFF"); - userTypes.add("DF"); - } - - @Getter - @Setter - @Builder - public static class OtherManual{ - String nickname; - List qas; - } - - @Getter - @Setter - @AllArgsConstructor - @Builder - @JsonInclude(JsonInclude.Include.NON_NULL) - public static class QAPair { - private Long id; - private String question; - private String answer; - private String nickname; - - public QAPair(Long id, String question, String answer) { - this.id = id; - this.question = question; - this.answer = answer; - this.nickname = null; - } - } - -} diff --git a/src/main/java/com/najasin/domain/user/dto/Page.java b/src/main/java/com/najasin/domain/user/dto/Page.java deleted file mode 100644 index 7a930e7..0000000 --- a/src/main/java/com/najasin/domain/user/dto/Page.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.najasin.domain.user.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.najasin.domain.character.dto.CharacterItems; -import lombok.*; - -import java.util.List; -import java.util.Map; - -@Getter -@Setter -@JsonInclude(JsonInclude.Include.NON_NULL) -public class Page { - private List userTypes; - private String nickname; - private String baseImage; - private CharacterItems characterItems; - private List myManualQAPair; - private List othersManualQAPair; - private List questions; - private List exampleKeywords; - private Map originKeywordPercents; - private Map otherKeywordPercents; - - - @Getter - @Setter - @Builder - public static class OtherManual{ - String nickname; - List qas; - } - - @Getter - @Setter - @AllArgsConstructor - @Builder - @JsonInclude(JsonInclude.Include.NON_NULL) - public static class QAPair { - private Long id; - private String question; - private String answer; - private String nickname; - - public QAPair(Long id, String question, String answer) { - this.id = id; - this.question = question; - this.answer = answer; - this.nickname = null; - } - } - @Getter - @Setter - @NoArgsConstructor - @AllArgsConstructor - public static class Questions{ - private Long id; - private String question; - } -} diff --git a/src/main/java/com/najasin/domain/user/dto/PageUpdateRequestDTO.java b/src/main/java/com/najasin/domain/user/dto/PageUpdateRequestDTO.java deleted file mode 100644 index 52b2a6b..0000000 --- a/src/main/java/com/najasin/domain/user/dto/PageUpdateRequestDTO.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.najasin.domain.user.dto; - -import com.najasin.domain.character.dto.CharacterItems; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import java.util.List; -import java.util.Map; - -@Getter -@Setter -public class PageUpdateRequestDTO { - private String nickname; - private String baseImage; - private CharacterItems characterItems; - private List answers; - private Map keywordPercents; - private Map otherKeywordPercents; - - - @Getter - @Setter - @AllArgsConstructor - @NoArgsConstructor - public static class AnswerDTO { - private Long id; - private String answer; - } -} diff --git a/src/main/java/com/najasin/domain/user/dto/PutAnswer.java b/src/main/java/com/najasin/domain/user/dto/PutAnswer.java deleted file mode 100644 index 6e31fdc..0000000 --- a/src/main/java/com/najasin/domain/user/dto/PutAnswer.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.najasin.domain.user.dto; - -import com.najasin.domain.answer.dto.AnswerDTO; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -@Getter -@Setter -@AllArgsConstructor -public class PutAnswer { - private List answers; - private String userType; -} diff --git a/src/main/java/com/najasin/domain/userUserType/dto/message/UserTypeMessage.java b/src/main/java/com/najasin/domain/user/dto/message/UserTypeMessage.java similarity index 80% rename from src/main/java/com/najasin/domain/userUserType/dto/message/UserTypeMessage.java rename to src/main/java/com/najasin/domain/user/dto/message/UserTypeMessage.java index 6ffcd04..7c3840e 100644 --- a/src/main/java/com/najasin/domain/userUserType/dto/message/UserTypeMessage.java +++ b/src/main/java/com/najasin/domain/user/dto/message/UserTypeMessage.java @@ -1,4 +1,4 @@ -package com.najasin.domain.userUserType.dto.message; +package com.najasin.domain.user.dto.message; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/najasin/domain/userUserType/dto/request/UserTypeUpdateRequest.java b/src/main/java/com/najasin/domain/user/dto/request/UserTypeUpdateRequest.java similarity index 68% rename from src/main/java/com/najasin/domain/userUserType/dto/request/UserTypeUpdateRequest.java rename to src/main/java/com/najasin/domain/user/dto/request/UserTypeUpdateRequest.java index ab24ffa..c0252aa 100644 --- a/src/main/java/com/najasin/domain/userUserType/dto/request/UserTypeUpdateRequest.java +++ b/src/main/java/com/najasin/domain/user/dto/request/UserTypeUpdateRequest.java @@ -1,4 +1,4 @@ -package com.najasin.domain.userUserType.dto.request; +package com.najasin.domain.user.dto.request; import jakarta.validation.constraints.NotBlank; diff --git a/src/main/java/com/najasin/domain/userUserType/dto/response/UserTypeResponse.java b/src/main/java/com/najasin/domain/user/dto/response/UserTypeResponse.java similarity index 73% rename from src/main/java/com/najasin/domain/userUserType/dto/response/UserTypeResponse.java rename to src/main/java/com/najasin/domain/user/dto/response/UserTypeResponse.java index d515bac..caf697d 100644 --- a/src/main/java/com/najasin/domain/userUserType/dto/response/UserTypeResponse.java +++ b/src/main/java/com/najasin/domain/user/dto/response/UserTypeResponse.java @@ -1,4 +1,4 @@ -package com.najasin.domain.userUserType.dto.response; +package com.najasin.domain.user.dto.response; public record UserTypeResponse(String userType) { diff --git a/src/main/java/com/najasin/domain/user/entity/User.java b/src/main/java/com/najasin/domain/user/entity/User.java index 927f231..2abe46c 100644 --- a/src/main/java/com/najasin/domain/user/entity/User.java +++ b/src/main/java/com/najasin/domain/user/entity/User.java @@ -5,9 +5,9 @@ import com.najasin.domain.answer.entity.Answer; import com.najasin.domain.comment.entity.Comment; +import com.najasin.domain.user.entity.userType.UserType; import com.najasin.domain.userKeyword.entity.UserKeyword; -import com.najasin.domain.userType.entity.UserType; -import com.najasin.domain.userUserType.entity.UserUserType; +import com.najasin.domain.user.entity.userType.UserUserType; import jakarta.persistence.*; import lombok.*; import org.springframework.data.jpa.domain.support.AuditingEntityListener; diff --git a/src/main/java/com/najasin/domain/userType/entity/UserType.java b/src/main/java/com/najasin/domain/user/entity/userType/UserType.java similarity index 86% rename from src/main/java/com/najasin/domain/userType/entity/UserType.java rename to src/main/java/com/najasin/domain/user/entity/userType/UserType.java index 84a3449..8c20cfc 100644 --- a/src/main/java/com/najasin/domain/userType/entity/UserType.java +++ b/src/main/java/com/najasin/domain/user/entity/userType/UserType.java @@ -1,6 +1,5 @@ -package com.najasin.domain.userType.entity; +package com.najasin.domain.user.entity.userType; -import com.najasin.domain.userUserType.entity.UserUserType; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java b/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java new file mode 100644 index 0000000..78befda --- /dev/null +++ b/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java @@ -0,0 +1,36 @@ +package com.najasin.domain.user.entity.userType; + +import com.najasin.domain.character.entity.CharacterSet; +import com.najasin.domain.user.entity.User; + +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity(name = "user_userType") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@IdClass(UserUserTypeId.class) +public class UserUserType { + @Id + @ManyToOne + @JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) + private User user; + + @Id + @ManyToOne + @JoinColumn(name = "user_type_id", referencedColumnName = "user_type_id", insertable = false, updatable = false) + private UserType userType; + + @ManyToOne + @JoinColumn(name = "character_set_id", referencedColumnName = "set_id") + private CharacterSet set; + + public UserUserType(User user, UserType userType) { + this.user = user; + this.userType = userType; + } +} diff --git a/src/main/java/com/najasin/domain/userUserType/entity/UserUserTypeId.java b/src/main/java/com/najasin/domain/user/entity/userType/UserUserTypeId.java similarity index 80% rename from src/main/java/com/najasin/domain/userUserType/entity/UserUserTypeId.java rename to src/main/java/com/najasin/domain/user/entity/userType/UserUserTypeId.java index ca3954b..a7623c1 100644 --- a/src/main/java/com/najasin/domain/userUserType/entity/UserUserTypeId.java +++ b/src/main/java/com/najasin/domain/user/entity/userType/UserUserTypeId.java @@ -1,7 +1,7 @@ -package com.najasin.domain.userUserType.entity; +package com.najasin.domain.user.entity.userType; import com.najasin.domain.user.entity.User; -import com.najasin.domain.userType.entity.UserType; + import jakarta.persistence.Embeddable; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/najasin/domain/userType/repository/UserTypeRepository.java b/src/main/java/com/najasin/domain/user/repository/UserTypeRepository.java similarity index 68% rename from src/main/java/com/najasin/domain/userType/repository/UserTypeRepository.java rename to src/main/java/com/najasin/domain/user/repository/UserTypeRepository.java index e52892b..e68eb2b 100644 --- a/src/main/java/com/najasin/domain/userType/repository/UserTypeRepository.java +++ b/src/main/java/com/najasin/domain/user/repository/UserTypeRepository.java @@ -1,10 +1,10 @@ -package com.najasin.domain.userType.repository; +package com.najasin.domain.user.repository; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import com.najasin.domain.userType.entity.UserType; +import com.najasin.domain.user.entity.userType.UserType; public interface UserTypeRepository extends JpaRepository { Optional findByName(String name); diff --git a/src/main/java/com/najasin/domain/userUserType/repository/UserUserTypeRepository.java b/src/main/java/com/najasin/domain/user/repository/UserUserTypeRepository.java similarity index 61% rename from src/main/java/com/najasin/domain/userUserType/repository/UserUserTypeRepository.java rename to src/main/java/com/najasin/domain/user/repository/UserUserTypeRepository.java index 0c767a2..3a13b97 100644 --- a/src/main/java/com/najasin/domain/userUserType/repository/UserUserTypeRepository.java +++ b/src/main/java/com/najasin/domain/user/repository/UserUserTypeRepository.java @@ -1,8 +1,8 @@ -package com.najasin.domain.userUserType.repository; +package com.najasin.domain.user.repository; import com.najasin.domain.user.entity.User; -import com.najasin.domain.userUserType.entity.UserUserType; -import com.najasin.domain.userUserType.entity.UserUserTypeId; +import com.najasin.domain.user.entity.userType.UserUserType; +import com.najasin.domain.user.entity.userType.UserUserTypeId; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; diff --git a/src/main/java/com/najasin/domain/user/service/UserService.java b/src/main/java/com/najasin/domain/user/service/UserService.java index 757e997..854eff0 100644 --- a/src/main/java/com/najasin/domain/user/service/UserService.java +++ b/src/main/java/com/najasin/domain/user/service/UserService.java @@ -1,14 +1,11 @@ package com.najasin.domain.user.service; -import java.util.ArrayList; import java.util.UUID; -import com.najasin.domain.character.body.repository.BodyRepository; -import com.najasin.domain.character.characterset.repository.CharacterSetRepository; -import com.najasin.domain.character.expression.repository.ExpressionRepository; -import com.najasin.domain.character.face.repository.FaceRepository; -import com.najasin.domain.userKeyword.service.UserKeywordService; -import com.najasin.domain.comment.service.CommentService; +import com.najasin.domain.character.repository.BodyRepository; +import com.najasin.domain.character.repository.CharacterSetRepository; +import com.najasin.domain.character.repository.ExpressionRepository; +import com.najasin.domain.character.repository.FaceRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,8 +26,6 @@ public class UserService { private final FaceRepository faceRepository; private final BodyRepository bodyRepository; private final ExpressionRepository expressionRepository; - private final UserKeywordService userKeywordService; - private final CommentService commentService; private final RedisBlackListUtil redisBlackListUtil; diff --git a/src/main/java/com/najasin/domain/userType/service/UserTypeService.java b/src/main/java/com/najasin/domain/user/service/UserTypeService.java similarity index 75% rename from src/main/java/com/najasin/domain/userType/service/UserTypeService.java rename to src/main/java/com/najasin/domain/user/service/UserTypeService.java index bc70662..25bd48b 100644 --- a/src/main/java/com/najasin/domain/userType/service/UserTypeService.java +++ b/src/main/java/com/najasin/domain/user/service/UserTypeService.java @@ -1,10 +1,10 @@ -package com.najasin.domain.userType.service; +package com.najasin.domain.user.service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.najasin.domain.userType.entity.UserType; -import com.najasin.domain.userType.repository.UserTypeRepository; +import com.najasin.domain.user.entity.userType.UserType; +import com.najasin.domain.user.repository.UserTypeRepository; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java new file mode 100644 index 0000000..4ae2cc2 --- /dev/null +++ b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java @@ -0,0 +1,47 @@ +package com.najasin.domain.user.service; + +import com.najasin.domain.character.repository.BodyRepository; +import com.najasin.domain.character.repository.CharacterSetRepository; +import com.najasin.domain.character.repository.ExpressionRepository; +import com.najasin.domain.character.repository.FaceRepository; +import com.najasin.domain.user.entity.User; +import com.najasin.domain.user.repository.UserRepository; +import com.najasin.domain.user.entity.userType.UserType; +import com.najasin.domain.user.repository.UserTypeRepository; +import com.najasin.domain.user.entity.userType.UserUserType; +import com.najasin.domain.user.repository.UserUserTypeRepository; + +import lombok.RequiredArgsConstructor; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class UserUserTypeService { + private final UserUserTypeRepository userUserTypeRepository; + private final UserTypeService userTypeService; + + @Transactional + public String updateUserType(User user, String userTypeName) { + UserType userType = userTypeService.findByName(userTypeName); + + if (!checkAlreadyExist(user.getUserUserTypes(), userType)) { + save(user, userType); + } + + user.updateLastUserType(userType); + return userTypeName; + } + + @Transactional + public UserUserType save(User user, UserType userType) { + return userUserTypeRepository.save(new UserUserType(user, userType)); + } + + private boolean checkAlreadyExist(List userUserTypes, UserType userType) { + return userUserTypes.stream().map(UserUserType::getUserType).toList().contains(userType); + } +} diff --git a/src/main/java/com/najasin/domain/userKeyword/service/UserKeywordService.java b/src/main/java/com/najasin/domain/userKeyword/service/UserKeywordService.java deleted file mode 100644 index 1c02e00..0000000 --- a/src/main/java/com/najasin/domain/userKeyword/service/UserKeywordService.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.najasin.domain.userKeyword.service; - -import com.najasin.domain.keyword.entity.Keyword; -import com.najasin.domain.keyword.repository.KeywordRepository; -import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.entity.enums.Role; -import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.userKeyword.entity.UserKeyword; -import com.najasin.domain.userKeyword.repository.UserKeywordRepository; -import jakarta.persistence.EntityNotFoundException; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.*; - -@Service -@RequiredArgsConstructor -public class UserKeywordService { - private final UserKeywordRepository userKeywordRepository; - private final KeywordRepository keywordRepository; - private final UserRepository userRepository; - - @Transactional - public UserKeyword save(String userId, Long keywordId, int percent) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - Keyword keyword = keywordRepository.findById(keywordId).orElseThrow(EntityNotFoundException::new); - UserKeyword newUK = new UserKeyword(user, keyword, percent); - user.updateKeyword(newUK); - return userKeywordRepository.save(newUK); - } - - @Transactional - public Map getOriginKeywordPercents(String userId) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - Map originKeywordPercents = new HashMap<>(); - for (UserKeyword UK : user.getUserKeywords()) { - String keyword = UK.getKeyword().getName(); - Integer originPercent = UK.getOriginPercent(); - originKeywordPercents.put(keyword, originPercent); - } - return originKeywordPercents; - } - - @Transactional - public Map getOtherKeywordPercents(String userId) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - Map otherKeywordPercents = new HashMap<>(); - for (UserKeyword UK : user.getUserKeywords()) { - String keyword = UK.getKeyword().getName(); - Long otherPercent = Long.valueOf(UK.getOriginPercent() + UK.getOthersPercent()) / (UK.getOthersCount() + 1); - otherKeywordPercents.put(keyword, otherPercent); - } - return otherKeywordPercents; - } - - - @Transactional - public UserKeyword updateByOthers(String userId, String keywordName, int percent) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - Keyword keyword = keywordRepository.findKeywordByName(keywordName); - UserKeyword prevUK = null; - for(UserKeyword userKeyword: user.getUserKeywords()) { - if (userKeyword.getKeyword().getName().equals(keywordName)) { - prevUK = userKeyword; - } - } - UserKeyword newUK = new UserKeyword(user, keyword, prevUK.getOriginPercent(), prevUK.getOthersPercent() + percent, prevUK.getOthersCount() + 1); - user.updateKeyword(newUK); - return userKeywordRepository.save(newUK); - } - - @Transactional - public void updateByUser(String userId, Map dto) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - userKeywordRepository.deleteAll(user.getUserKeywords()); - user.deleteKeywords(); - for (String keywordName : dto.keySet()) { - Keyword keyword = keywordRepository.findKeywordByName(keywordName); - UserKeyword userKeyword = new UserKeyword(user, keyword, dto.get(keywordName)); - user.updateKeyword(userKeyword); - userKeywordRepository.save(userKeyword); - } - } -} diff --git a/src/main/java/com/najasin/domain/userUserType/controller/UserUserTypeController.java b/src/main/java/com/najasin/domain/userUserType/controller/UserUserTypeController.java deleted file mode 100644 index 8b80f53..0000000 --- a/src/main/java/com/najasin/domain/userUserType/controller/UserUserTypeController.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.najasin.domain.userUserType.controller; - -import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.najasin.domain.user.entity.User; -import com.najasin.domain.userUserType.dto.message.UserTypeMessage; -import com.najasin.domain.userUserType.dto.request.UserTypeUpdateRequest; -import com.najasin.domain.userUserType.dto.response.UserTypeResponse; -import com.najasin.domain.userUserType.service.UserUserTypeService; -import com.najasin.global.annotation.AuthorizeUser; -import com.najasin.global.response.ApiResponse; - -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -@RestController -@RequestMapping("/api/user/type") -public class UserUserTypeController { - private final UserUserTypeService userUserTypeService; - - @PutMapping - public ResponseEntity> modify(@AuthorizeUser User user, - @RequestBody @Validated UserTypeUpdateRequest request) { - String updatedUserType = userUserTypeService.updateUserType(user, request.userType()); - - return ResponseEntity.ok(ApiResponse.createSuccessWithData( - UserTypeMessage.SUCCESS_UPDATE_USER_TYPE.getMsg(), - UserTypeResponse.of(updatedUserType))); - } -} diff --git a/src/main/java/com/najasin/domain/userUserType/entity/UserUserType.java b/src/main/java/com/najasin/domain/userUserType/entity/UserUserType.java deleted file mode 100644 index ed6301a..0000000 --- a/src/main/java/com/najasin/domain/userUserType/entity/UserUserType.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.najasin.domain.userUserType.entity; - -import com.najasin.domain.character.body.entity.Body; -import com.najasin.domain.character.characterset.entity.CharacterSet; -import com.najasin.domain.character.expression.entity.Expression; -import com.najasin.domain.character.face.entity.Face; -import com.najasin.domain.user.entity.User; -import com.najasin.domain.userType.entity.UserType; -import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@Entity(name = "user_userType") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -@IdClass(UserUserTypeId.class) -public class UserUserType { - @Id - @ManyToOne - @JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) - private User user; - - @Id - @ManyToOne - @JoinColumn(name = "user_type_id", referencedColumnName = "user_type_id", insertable = false, updatable = false) - private UserType userType; - - @ManyToOne - @JoinColumn(name = "character_set_id", referencedColumnName = "set_id") - private CharacterSet set; - - @ManyToOne - @JoinColumn(name = "face_id", referencedColumnName = "face_id") - private Face face; - - @ManyToOne - @JoinColumn(name = "body_id", referencedColumnName = "body_id") - private Body body; - - @ManyToOne - @JoinColumn(name = "expression_id", referencedColumnName = "expression_id") - private Expression expression; - - public UserUserType(User user, UserType userType) { - this.user = user; - this.userType = userType; - } - - public void updateCharacter(Face face, Body body, Expression expression, CharacterSet characterSet) { - this.face = face; - this.body = body; - this.expression = expression; - this.set = characterSet; - } -} diff --git a/src/main/java/com/najasin/domain/userUserType/service/UserUserTypeService.java b/src/main/java/com/najasin/domain/userUserType/service/UserUserTypeService.java deleted file mode 100644 index 7f24813..0000000 --- a/src/main/java/com/najasin/domain/userUserType/service/UserUserTypeService.java +++ /dev/null @@ -1,182 +0,0 @@ -package com.najasin.domain.userUserType.service; - -import com.najasin.domain.answer.entity.Answer; -import com.najasin.domain.character.body.entity.Body; -import com.najasin.domain.character.body.repository.BodyRepository; -import com.najasin.domain.character.characterset.entity.CharacterSet; -import com.najasin.domain.character.characterset.repository.CharacterSetRepository; -import com.najasin.domain.character.dto.CharacterItem; -import com.najasin.domain.character.dto.CharacterItems; -import com.najasin.domain.character.expression.entity.Expression; -import com.najasin.domain.character.expression.repository.ExpressionRepository; -import com.najasin.domain.character.face.entity.Face; -import com.najasin.domain.character.face.repository.FaceRepository; -import com.najasin.domain.comment.entity.Comment; -import com.najasin.domain.question.entity.QuestionType; -import com.najasin.domain.user.dto.Page; -import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.userType.entity.UserType; -import com.najasin.domain.userType.repository.UserTypeRepository; -import com.najasin.domain.userUserType.entity.UserUserType; -import com.najasin.domain.userUserType.entity.UserUserTypeId; -import com.najasin.domain.userUserType.repository.UserUserTypeRepository; -import jakarta.persistence.EntityNotFoundException; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.Duration; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import com.najasin.domain.userType.service.UserTypeService; - - -@Service -@RequiredArgsConstructor -public class UserUserTypeService { - private final UserUserTypeRepository userUserTypeRepository; - private final UserRepository userRepository; - private final UserTypeRepository userTypeRepository; - private final FaceRepository faceRepository; - private final BodyRepository bodyRepository; - private final ExpressionRepository expressionRepository; - private final CharacterSetRepository characterSetRepository; - private final UserTypeService userTypeService; - - - @Transactional - public List getUserUserTypesByUserId(String userId) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - return userUserTypeRepository.findAllByUser(user); - } - - @Transactional - public UserUserType getUserUserTypeById(String userId, String userTypeName) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - UserType userType = userTypeRepository.findByName(userTypeName).orElseThrow(EntityNotFoundException::new); - return userUserTypeRepository.findById(new UserUserTypeId(user, userType)).orElse(new UserUserType(user, userType)); - } - - @Transactional - public List getQAByUserIdAndUserTypeForUser(String userId, String userTypeName, QuestionType questionType) { - UserUserType userUserType = this.getUserUserTypeById(userId, userTypeName); - List myQaParis = new ArrayList<>(); - for (Answer answer : userUserType.getUser().getAnswers()) { - Page.QAPair qaPair = new Page.QAPair(answer.getQuestion().getId(), answer.getQuestion().getQuestion(), answer.getAnswer()); - myQaParis.add(qaPair); - } - return myQaParis; - } - - @Transactional - public List getOtherManualByUserIdAndUserType(String userId, String userTypeName, QuestionType questionType) { - UserUserType userUserType = this.getUserUserTypeById(userId, userTypeName); - if (userUserType.getUser().getComments().size() == 0) { - return null; - } - List temp = new ArrayList<>(); - String prevNickname = userUserType.getUser().getComments().get(0).getNickname(); - LocalDateTime prevTime = userUserType.getUser().getComments().get(0).getAuditEntity().getCreatedAt(); - for (Comment comment : userUserType.getUser().getComments()) { - Page.QAPair qaPair = Page.QAPair.builder() - .id(comment.getQuestion().getId()) - .question(comment.getQuestion().getQuestion()) - .answer(comment.getComment()) - .build(); - if (prevNickname.equals(comment.getNickname()) && temp.size() != 0&&Duration.between(prevTime,comment.getAuditEntity().getCreatedAt()).getSeconds()<=10) { - temp.get(temp.size() - 1).getQas().add(qaPair); - - } else { - prevNickname = comment.getNickname(); - prevTime = comment.getAuditEntity().getCreatedAt(); - temp.add(Page.OtherManual.builder() - .nickname(prevNickname) - .qas(new ArrayList<>()) - .build()); - temp.get(temp.size() - 1).getQas().add(qaPair); - } - } - return temp; - } - - - @Transactional - public UserUserType updateCharacter(String userId, String userTypeName , CharacterItems dto) { - User user = userRepository.findById(userId).orElseThrow(EntityNotFoundException::new); - UserUserType userUserType = this.getUserUserTypeById(userId, userTypeName); - - if (dto.getSet()== null) { - Face face = null; Body body = null; Expression expression = null; - if (dto.getFace()!=null) face = faceRepository.findById(dto.getFace().getId()).orElse(null); - if (dto.getBody()!=null) body = bodyRepository.findById(dto.getBody().getId()).orElse(null); - if (dto.getExpression()!=null) expression = expressionRepository.findById(dto.getExpression().getId()).orElse(null); - userUserType.updateCharacter(face, body, expression, null); - } - else{ - CharacterSet characterSet = characterSetRepository.findById(dto.getSet().getId()).orElseThrow(EntityNotFoundException::new); - userUserType.updateCharacter(null, null, null, characterSet); - } - - user.updateUserUserType(userUserType); - return userUserTypeRepository.save(userUserType); - } - - @Transactional - public CharacterItems getCharacter(String userId, String userTypeName) { - UserUserType userUserType = this.getUserUserTypeById(userId, userTypeName); - Face face = userUserType.getFace(); - Body body = userUserType.getBody(); - Expression expression = userUserType.getExpression(); - CharacterSet characterSet = userUserType.getSet(); - - if (characterSet != null) { - CharacterItem characterItem = CharacterItem.builder() - .id(characterSet.getId()) - .showCase(characterSet.getUrl()) - .layoutCase(characterSet.getUrl()) - .build(); - return new CharacterItems(null, null, null, characterItem); - } - - CharacterItem faceItem = (face!=null)? - CharacterItem.builder() - .id(face.getId()) - .showCase(face.getShow_url()) - .layoutCase(face.getLayout_url()) - .build() : null; - CharacterItem bodyItem = (body!=null)?CharacterItem.builder() - .id(body.getId()) - .showCase(body.getShow_url()) - .layoutCase(body.getLayout_url()) - .build() : null; - CharacterItem expressionItem = (expression!=null)? CharacterItem.builder() - .id(expression.getId()) - .showCase(expression.getShow_url()) - .layoutCase(expression.getLayout_url()) - .build() : null; - return new CharacterItems(faceItem, bodyItem, expressionItem, null); - } - - @Transactional - public String updateUserType(User user, String userTypeName) { - UserType userType = userTypeService.findByName(userTypeName); - - if (!checkAlreadyExist(user.getUserUserTypes(), userType)) { - save(user, userType); - } - - user.updateLastUserType(userType); - return userTypeName; - } - - @Transactional - public UserUserType save(User user, UserType userType) { - return userUserTypeRepository.save(new UserUserType(user, userType)); - } - - private boolean checkAlreadyExist(List userUserTypes, UserType userType) { - return userUserTypes.stream().map(UserUserType::getUserType).toList().contains(userType); - } -} diff --git a/src/test/java/com/najasin/service/AnswerServiceTest.java b/src/test/java/com/najasin/service/AnswerServiceTest.java index 26e7919..5133e76 100644 --- a/src/test/java/com/najasin/service/AnswerServiceTest.java +++ b/src/test/java/com/najasin/service/AnswerServiceTest.java @@ -11,8 +11,8 @@ import com.najasin.domain.user.entity.User; import com.najasin.domain.user.entity.enums.Provider; import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.userType.entity.UserType; -import com.najasin.domain.userType.repository.UserTypeRepository; +import com.najasin.domain.user.entity.userType.UserType; +import com.najasin.domain.user.repository.UserTypeRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -32,7 +32,6 @@ import static junit.framework.TestCase.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.times; @ExtendWith(MockitoExtension.class) public class AnswerServiceTest { diff --git a/src/test/java/com/najasin/service/CharacterServiceTest.java b/src/test/java/com/najasin/service/CharacterServiceTest.java index e44d557..4c27be2 100644 --- a/src/test/java/com/najasin/service/CharacterServiceTest.java +++ b/src/test/java/com/najasin/service/CharacterServiceTest.java @@ -1,15 +1,15 @@ package com.najasin.service; -import com.najasin.domain.character.CharacterService; -import com.najasin.domain.character.body.entity.Body; -import com.najasin.domain.character.body.repository.BodyRepository; -import com.najasin.domain.character.characterset.entity.CharacterSet; -import com.najasin.domain.character.characterset.repository.CharacterSetRepository; +import com.najasin.domain.character.service.CharacterService; +import com.najasin.domain.character.entity.Body; +import com.najasin.domain.character.repository.BodyRepository; +import com.najasin.domain.character.entity.CharacterSet; +import com.najasin.domain.character.repository.CharacterSetRepository; import com.najasin.domain.character.dto.AllCharacterItems; -import com.najasin.domain.character.expression.entity.Expression; -import com.najasin.domain.character.expression.repository.ExpressionRepository; -import com.najasin.domain.character.face.entity.Face; -import com.najasin.domain.character.face.repository.FaceRepository; +import com.najasin.domain.character.entity.Expression; +import com.najasin.domain.character.repository.ExpressionRepository; +import com.najasin.domain.character.entity.Face; +import com.najasin.domain.character.repository.FaceRepository; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -23,7 +23,6 @@ import static junit.framework.TestCase.assertEquals; import static org.mockito.Mockito.when; -import static junit.framework.TestCase.*; @ExtendWith(MockitoExtension.class) public class CharacterServiceTest { diff --git a/src/test/java/com/najasin/service/CommentServiceTest.java b/src/test/java/com/najasin/service/CommentServiceTest.java index 0525b7b..d71ff27 100644 --- a/src/test/java/com/najasin/service/CommentServiceTest.java +++ b/src/test/java/com/najasin/service/CommentServiceTest.java @@ -3,7 +3,6 @@ import com.najasin.domain.comment.entity.Comment; import com.najasin.domain.comment.repository.CommentRepository; import com.najasin.domain.comment.service.CommentService; -import com.najasin.domain.keyword.entity.Keyword; import com.najasin.domain.question.entity.Question; import com.najasin.domain.question.entity.QuestionType; import com.najasin.domain.question.repository.QuestionRepository; @@ -12,8 +11,7 @@ import com.najasin.domain.user.entity.enums.Provider; import com.najasin.domain.user.entity.enums.Role; import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.userKeyword.entity.UserKeyword; -import com.najasin.domain.userType.entity.UserType; +import com.najasin.domain.user.entity.userType.UserType; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -27,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.when; import static org.mockito.Mockito.*; import java.util.ArrayList; diff --git a/src/test/java/com/najasin/service/KeywordServiceTest.java b/src/test/java/com/najasin/service/KeywordServiceTest.java index f73ab16..a2902e9 100644 --- a/src/test/java/com/najasin/service/KeywordServiceTest.java +++ b/src/test/java/com/najasin/service/KeywordServiceTest.java @@ -1,41 +1,23 @@ package com.najasin.service; -import com.najasin.domain.answer.entity.Answer; -import com.najasin.domain.answer.repository.AnswerRepository; -import com.najasin.domain.answer.service.AnswerService; import com.najasin.domain.keyword.entity.Keyword; import com.najasin.domain.keyword.repository.KeywordRepository; import com.najasin.domain.keyword.service.KeywordService; -import com.najasin.domain.question.entity.Question; -import com.najasin.domain.question.entity.QuestionType; -import com.najasin.domain.question.repository.QuestionRepository; -import com.najasin.domain.user.dto.PageUpdateRequestDTO; -import com.najasin.domain.user.entity.Oauth2Entity; -import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.entity.enums.Provider; -import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.userType.entity.UserType; -import com.najasin.domain.userType.repository.UserTypeRepository; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import static org.mockito.Mockito.*; import org.mockito.junit.jupiter.MockitoExtension; import java.util.ArrayList; import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; import static junit.framework.TestCase.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.times; @ExtendWith(MockitoExtension.class) public class KeywordServiceTest { diff --git a/src/test/java/com/najasin/service/QuestionServiceTest.java b/src/test/java/com/najasin/service/QuestionServiceTest.java index d70deac..78e3566 100644 --- a/src/test/java/com/najasin/service/QuestionServiceTest.java +++ b/src/test/java/com/najasin/service/QuestionServiceTest.java @@ -1,15 +1,12 @@ package com.najasin.service; -import com.najasin.domain.answer.repository.AnswerRepository; -import com.najasin.domain.answer.service.AnswerService; import com.najasin.domain.question.entity.Question; import com.najasin.domain.question.entity.QuestionType; import com.najasin.domain.question.repository.QuestionRepository; import com.najasin.domain.question.service.QuestionService; import com.najasin.domain.user.dto.Page; -import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.userType.entity.UserType; -import com.najasin.domain.userType.repository.UserTypeRepository; +import com.najasin.domain.user.entity.userType.UserType; +import com.najasin.domain.user.repository.UserTypeRepository; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -21,7 +18,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Optional; @ExtendWith(MockitoExtension.class) diff --git a/src/test/java/com/najasin/service/UserServiceTest.java b/src/test/java/com/najasin/service/UserServiceTest.java index c83e294..35c9fb7 100644 --- a/src/test/java/com/najasin/service/UserServiceTest.java +++ b/src/test/java/com/najasin/service/UserServiceTest.java @@ -8,15 +8,15 @@ import java.util.List; import java.util.Optional; -import com.najasin.domain.character.body.entity.Body; -import com.najasin.domain.character.body.repository.BodyRepository; -import com.najasin.domain.character.characterset.entity.CharacterSet; -import com.najasin.domain.character.characterset.repository.CharacterSetRepository; +import com.najasin.domain.character.entity.Body; +import com.najasin.domain.character.repository.BodyRepository; +import com.najasin.domain.character.entity.CharacterSet; +import com.najasin.domain.character.repository.CharacterSetRepository; import com.najasin.domain.keyword.dto.KeywordDTO; -import com.najasin.domain.character.expression.entity.Expression; -import com.najasin.domain.character.expression.repository.ExpressionRepository; -import com.najasin.domain.character.face.entity.Face; -import com.najasin.domain.character.face.repository.FaceRepository; +import com.najasin.domain.character.entity.Expression; +import com.najasin.domain.character.repository.ExpressionRepository; +import com.najasin.domain.character.entity.Face; +import com.najasin.domain.character.repository.FaceRepository; import com.najasin.domain.keyword.entity.Keyword; import com.najasin.domain.userKeyword.entity.UserKeyword; import com.najasin.domain.userKeyword.service.UserKeywordService; diff --git a/src/test/java/com/najasin/service/UserTypeServiceTest.java b/src/test/java/com/najasin/service/UserTypeServiceTest.java index ecb28d3..c164f12 100644 --- a/src/test/java/com/najasin/service/UserTypeServiceTest.java +++ b/src/test/java/com/najasin/service/UserTypeServiceTest.java @@ -14,9 +14,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.najasin.domain.userType.entity.UserType; -import com.najasin.domain.userType.repository.UserTypeRepository; -import com.najasin.domain.userType.service.UserTypeService; +import com.najasin.domain.user.entity.userType.UserType; +import com.najasin.domain.user.repository.UserTypeRepository; +import com.najasin.domain.user.service.UserTypeService; import jakarta.persistence.EntityNotFoundException; diff --git a/src/test/java/com/najasin/service/UserUserTypeServiceTest.java b/src/test/java/com/najasin/service/UserUserTypeServiceTest.java index d8eb70b..eba0aa6 100644 --- a/src/test/java/com/najasin/service/UserUserTypeServiceTest.java +++ b/src/test/java/com/najasin/service/UserUserTypeServiceTest.java @@ -8,22 +8,22 @@ import java.util.Optional; import com.najasin.domain.answer.entity.Answer; -import com.najasin.domain.character.body.entity.Body; -import com.najasin.domain.character.body.repository.BodyRepository; -import com.najasin.domain.character.characterset.entity.CharacterSet; -import com.najasin.domain.character.characterset.repository.CharacterSetRepository; +import com.najasin.domain.character.entity.Body; +import com.najasin.domain.character.repository.BodyRepository; +import com.najasin.domain.character.entity.CharacterSet; +import com.najasin.domain.character.repository.CharacterSetRepository; import com.najasin.domain.character.dto.CharacterItem; -import com.najasin.domain.character.expression.entity.Expression; -import com.najasin.domain.character.expression.repository.ExpressionRepository; -import com.najasin.domain.character.face.entity.Face; -import com.najasin.domain.character.face.repository.FaceRepository; +import com.najasin.domain.character.entity.Expression; +import com.najasin.domain.character.repository.ExpressionRepository; +import com.najasin.domain.character.entity.Face; +import com.najasin.domain.character.repository.FaceRepository; import com.najasin.domain.comment.entity.Comment; import com.najasin.domain.question.entity.Question; import com.najasin.domain.question.entity.QuestionType; import com.najasin.domain.character.dto.CharacterItems; import com.najasin.domain.user.dto.Page; import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.userType.repository.UserTypeRepository; +import com.najasin.domain.user.repository.UserTypeRepository; import com.najasin.global.audit.AuditEntity; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -36,11 +36,11 @@ import com.najasin.domain.user.entity.Oauth2Entity; import com.najasin.domain.user.entity.User; -import com.najasin.domain.userType.entity.UserType; -import com.najasin.domain.userType.service.UserTypeService; -import com.najasin.domain.userUserType.entity.UserUserType; -import com.najasin.domain.userUserType.repository.UserUserTypeRepository; -import com.najasin.domain.userUserType.service.UserUserTypeService; +import com.najasin.domain.user.entity.userType.UserType; +import com.najasin.domain.user.service.UserTypeService; +import com.najasin.domain.user.entity.userType.UserUserType; +import com.najasin.domain.user.repository.UserUserTypeRepository; +import com.najasin.domain.user.service.UserUserTypeService; @ExtendWith(MockitoExtension.class) public class UserUserTypeServiceTest { From 533c7e603da4ed6197c5ea5b84fffc2b564ad5a2 Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 15:36:26 +0900 Subject: [PATCH 02/27] =?UTF-8?q?feature(#48):=20=EC=BA=90=EB=A6=AD?= =?UTF-8?q?=ED=84=B0=20=EC=95=84=EC=9D=B4=ED=85=9C=20api=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 --- .../com/najasin/config/SecurityConfig.java | 5 ++- .../controller/CharacterController.java | 35 +++++++++++++++++++ .../dto/message/CharacterItemResponse.java | 12 +++++++ .../character/dto/response/CharacterItem.java | 6 ++++ .../dto/response/CharacterItems.java | 12 +++++++ .../dto/response/CharacterItemsResponse.java | 8 +++++ src/main/resources/application-local.yml | 4 ++- src/main/resources/application-prod.yml | 4 ++- 8 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/najasin/domain/character/controller/CharacterController.java create mode 100644 src/main/java/com/najasin/domain/character/dto/message/CharacterItemResponse.java create mode 100644 src/main/java/com/najasin/domain/character/dto/response/CharacterItem.java create mode 100644 src/main/java/com/najasin/domain/character/dto/response/CharacterItems.java create mode 100644 src/main/java/com/najasin/domain/character/dto/response/CharacterItemsResponse.java diff --git a/src/main/java/com/najasin/config/SecurityConfig.java b/src/main/java/com/najasin/config/SecurityConfig.java index ce0c25f..303e6e9 100644 --- a/src/main/java/com/najasin/config/SecurityConfig.java +++ b/src/main/java/com/najasin/config/SecurityConfig.java @@ -57,11 +57,10 @@ private Customizer.AuthorizationMa return requests -> requests.requestMatchers( new AntPathRequestMatcher("/swagger-ui/index.html"), - new AntPathRequestMatcher("/success/**"), - new AntPathRequestMatcher("/api/auth"), new AntPathRequestMatcher("/auth2/**"), new AntPathRequestMatcher("/login/**"), - new AntPathRequestMatcher("/api/*/my-manual", "GET") + new AntPathRequestMatcher("/api/*/my-manual", "GET"), + new AntPathRequestMatcher("/api/characterItems") ).permitAll() .requestMatchers(new AntPathRequestMatcher("/api/**")).hasAnyRole("ADMIN", "MEMBER") .anyRequest().authenticated(); diff --git a/src/main/java/com/najasin/domain/character/controller/CharacterController.java b/src/main/java/com/najasin/domain/character/controller/CharacterController.java new file mode 100644 index 0000000..5bb1824 --- /dev/null +++ b/src/main/java/com/najasin/domain/character/controller/CharacterController.java @@ -0,0 +1,35 @@ +package com.najasin.domain.character.controller; + +import static com.najasin.global.response.ApiResponse.*; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.najasin.domain.character.dto.message.CharacterItemResponse; +import com.najasin.domain.character.dto.response.CharacterItems; +import com.najasin.domain.character.dto.response.CharacterItemsResponse; +import com.najasin.domain.character.service.CharacterService; +import com.najasin.global.response.ApiResponse; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequestMapping("/api/characterItems") +@RequiredArgsConstructor +public class CharacterController { + + private final CharacterService characterService; + @Value("${base-image}") + private String baseImage; + + @GetMapping + public ResponseEntity> getCharacterItems() { + CharacterItems characterItems = characterService.findAllItems(); + return ResponseEntity.ok(createSuccessWithData( + CharacterItemResponse.FIND_ALL_ITEMS_SUCCESS.getMsg(), + CharacterItemsResponse.of(baseImage, characterItems))); + } +} diff --git a/src/main/java/com/najasin/domain/character/dto/message/CharacterItemResponse.java b/src/main/java/com/najasin/domain/character/dto/message/CharacterItemResponse.java new file mode 100644 index 0000000..44102a1 --- /dev/null +++ b/src/main/java/com/najasin/domain/character/dto/message/CharacterItemResponse.java @@ -0,0 +1,12 @@ +package com.najasin.domain.character.dto.message; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public enum CharacterItemResponse { + FIND_ALL_ITEMS_SUCCESS("모든 아이템 조회에 성공하셨습니다."); + + private final String msg; +} diff --git a/src/main/java/com/najasin/domain/character/dto/response/CharacterItem.java b/src/main/java/com/najasin/domain/character/dto/response/CharacterItem.java new file mode 100644 index 0000000..cffb93a --- /dev/null +++ b/src/main/java/com/najasin/domain/character/dto/response/CharacterItem.java @@ -0,0 +1,6 @@ +package com.najasin.domain.character.dto.response; + +public record CharacterItem(Long id, + String showCase, + String layoutCase) { +} diff --git a/src/main/java/com/najasin/domain/character/dto/response/CharacterItems.java b/src/main/java/com/najasin/domain/character/dto/response/CharacterItems.java new file mode 100644 index 0000000..8f035ab --- /dev/null +++ b/src/main/java/com/najasin/domain/character/dto/response/CharacterItems.java @@ -0,0 +1,12 @@ +package com.najasin.domain.character.dto.response; + +import java.util.List; + +import lombok.Builder; + +public record CharacterItems(List face, + List body, + List expression) { + @Builder + public CharacterItems {} +} diff --git a/src/main/java/com/najasin/domain/character/dto/response/CharacterItemsResponse.java b/src/main/java/com/najasin/domain/character/dto/response/CharacterItemsResponse.java new file mode 100644 index 0000000..591e61b --- /dev/null +++ b/src/main/java/com/najasin/domain/character/dto/response/CharacterItemsResponse.java @@ -0,0 +1,8 @@ +package com.najasin.domain.character.dto.response; + +public record CharacterItemsResponse(String baseImage, CharacterItems characterItems) { + + public static CharacterItemsResponse of(String baseImage, CharacterItems characterItems) { + return new CharacterItemsResponse(baseImage, characterItems); + } +} diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index a0daf9b..dcd4656 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -70,4 +70,6 @@ cloud: client: host: localhost url: http://localhost:3000 - endpoint: success \ No newline at end of file + endpoint: success + +base-image: ${BASE_IMAGE} \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index e3173ce..be3dea1 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -61,4 +61,6 @@ cloud: client: url: ${CLIENT_URL} - endpoint: success \ No newline at end of file + endpoint: success + +base-image: ${BASE_IMAGE} \ No newline at end of file From 7de30bb3debba00e7c03cf432e4b2a304deeed63 Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 15:36:51 +0900 Subject: [PATCH 03/27] =?UTF-8?q?feature(#48):=20=EC=BA=90=EB=A6=AD?= =?UTF-8?q?=ED=84=B0=20=EC=95=84=EC=9D=B4=ED=85=9C=20=EB=B9=84=EC=A6=88?= =?UTF-8?q?=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../character/service/CharacterService.java | 93 +++++++++---------- 1 file changed, 42 insertions(+), 51 deletions(-) diff --git a/src/main/java/com/najasin/domain/character/service/CharacterService.java b/src/main/java/com/najasin/domain/character/service/CharacterService.java index 7fa3166..c89973a 100644 --- a/src/main/java/com/najasin/domain/character/service/CharacterService.java +++ b/src/main/java/com/najasin/domain/character/service/CharacterService.java @@ -1,62 +1,53 @@ -package com.najasin.domain.character; +package com.najasin.domain.character.service; +import java.util.List; + +import com.najasin.domain.character.dto.response.CharacterItem; +import com.najasin.domain.character.dto.response.CharacterItems; import com.najasin.domain.character.entity.Body; -import com.najasin.domain.character.body.repository.BodyRepository; -import com.najasin.domain.character.characterset.entity.CharacterSet; -import com.najasin.domain.character.characterset.repository.CharacterSetRepository; -import com.najasin.domain.character.dto.AllCharacterItems; -import com.najasin.domain.character.dto.CharacterItem; -import com.najasin.domain.character.expression.entity.Expression; -import com.najasin.domain.character.expression.repository.ExpressionRepository; -import com.najasin.domain.character.face.entity.Face; -import com.najasin.domain.character.face.repository.FaceRepository; +import com.najasin.domain.character.repository.BodyRepository; +import com.najasin.domain.character.entity.Expression; +import com.najasin.domain.character.repository.ExpressionRepository; +import com.najasin.domain.character.entity.Face; +import com.najasin.domain.character.repository.FaceRepository; import lombok.RequiredArgsConstructor; + import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor public class CharacterService { - private final FaceRepository faceRepository; - private final BodyRepository bodyRepository; - private final ExpressionRepository expressionRepository; - private final CharacterSetRepository characterSetRepository; - - @Transactional - public AllCharacterItems getAllCharacterItems() { - AllCharacterItems allCharacterItems = new AllCharacterItems(); - allCharacterItems.setBaseImage("기본 이미지 url"); - AllCharacterItems.CharacterItems characterItems = new AllCharacterItems.CharacterItems(); - for (Face face : faceRepository.findAll()) { - characterItems.getFace().add(CharacterItem.builder() - .id(face.getId()) - .showCase(face.getShow_url()) - .layoutCase(face.getLayout_url()) - .build()); - } - for (Body body : bodyRepository.findAll()) { - characterItems.getBody().add(CharacterItem.builder() - .id(body.getId()) - .showCase(body.getShow_url()) - .layoutCase(body.getLayout_url()) - .build()); - } - for (Expression expression : expressionRepository.findAll()) { - characterItems.getExpression().add(CharacterItem.builder() - .id(expression.getId()) - .showCase(expression.getShow_url()) - .layoutCase(expression.getLayout_url()) - .build()); - } - for (CharacterSet characterSet : characterSetRepository.findAll()) { - characterItems.getSet().add(CharacterItem.builder() - .id(characterSet.getId()) - .showCase(characterSet.getUrl()) - .layoutCase(characterSet.getUrl()) - .build()); - } - allCharacterItems.setCharacterItems(characterItems); - return allCharacterItems; - } + private final FaceRepository faceRepository; + private final BodyRepository bodyRepository; + private final ExpressionRepository expressionRepository; + + @Transactional(readOnly = true) + public CharacterItems findAllItems() { + List faceList = findFaceAll().stream().map(Face::toCharacterItem).toList(); + List bodyList = findBodyAll().stream().map(Body::toCharacterItem).toList(); + List expressionList = findExpressionAll().stream().map(Expression::toCharacterItem).toList(); + + return CharacterItems.builder() + .face(faceList) + .body(bodyList) + .expression(expressionList) + .build(); + } + + @Transactional(readOnly = true) + public List findFaceAll() { + return faceRepository.findAll(); + } + + @Transactional(readOnly = true) + public List findBodyAll() { + return bodyRepository.findAll(); + } + + @Transactional(readOnly = true) + public List findExpressionAll() { + return expressionRepository.findAll(); + } } From 3fd2ed03225204daac036ffa6cdf8faaf3ab7eed Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 15:43:46 +0900 Subject: [PATCH 04/27] =?UTF-8?q?refactor(#48):=20domain=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/najasin/domain/answer/entity/Answer.java | 2 +- .../java/com/najasin/domain/answer/entity/AnswerId.java | 2 +- .../java/com/najasin/domain/comment/entity/Comment.java | 2 +- .../java/com/najasin/domain/comment/entity/CommentId.java | 2 +- .../domain/{ => myManual}/keyword/entity/Keyword.java | 2 +- .../keyword/repository/KeywordRepository.java | 4 ++-- .../domain/{ => myManual}/question/entity/Question.java | 2 +- .../domain/{ => myManual}/question/entity/QuestionType.java | 2 +- .../question/repository/QuestionRepository.java | 6 +++--- .../com/najasin/domain/userKeyword/entity/UserKeyword.java | 2 +- .../najasin/domain/userKeyword/entity/UserKeywordId.java | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) rename src/main/java/com/najasin/domain/{ => myManual}/keyword/entity/Keyword.java (92%) rename src/main/java/com/najasin/domain/{ => myManual}/keyword/repository/KeywordRepository.java (61%) rename src/main/java/com/najasin/domain/{ => myManual}/question/entity/Question.java (94%) rename src/main/java/com/najasin/domain/{ => myManual}/question/entity/QuestionType.java (52%) rename src/main/java/com/najasin/domain/{ => myManual}/question/repository/QuestionRepository.java (64%) diff --git a/src/main/java/com/najasin/domain/answer/entity/Answer.java b/src/main/java/com/najasin/domain/answer/entity/Answer.java index 42c6706..8f10503 100644 --- a/src/main/java/com/najasin/domain/answer/entity/Answer.java +++ b/src/main/java/com/najasin/domain/answer/entity/Answer.java @@ -1,6 +1,6 @@ package com.najasin.domain.answer.entity; -import com.najasin.domain.question.entity.Question; +import com.najasin.domain.myManual.question.entity.Question; import com.najasin.domain.user.entity.User; import jakarta.persistence.*; import lombok.AccessLevel; diff --git a/src/main/java/com/najasin/domain/answer/entity/AnswerId.java b/src/main/java/com/najasin/domain/answer/entity/AnswerId.java index 7995f49..9a4c2ec 100644 --- a/src/main/java/com/najasin/domain/answer/entity/AnswerId.java +++ b/src/main/java/com/najasin/domain/answer/entity/AnswerId.java @@ -1,6 +1,6 @@ package com.najasin.domain.answer.entity; -import com.najasin.domain.question.entity.Question; +import com.najasin.domain.myManual.question.entity.Question; import com.najasin.domain.user.entity.User; import jakarta.persistence.Embeddable; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/najasin/domain/comment/entity/Comment.java b/src/main/java/com/najasin/domain/comment/entity/Comment.java index b66f3b6..5fc9230 100644 --- a/src/main/java/com/najasin/domain/comment/entity/Comment.java +++ b/src/main/java/com/najasin/domain/comment/entity/Comment.java @@ -1,6 +1,6 @@ package com.najasin.domain.comment.entity; -import com.najasin.domain.question.entity.Question; +import com.najasin.domain.myManual.question.entity.Question; import com.najasin.domain.user.entity.User; import com.najasin.global.audit.AuditEntity; import jakarta.persistence.*; diff --git a/src/main/java/com/najasin/domain/comment/entity/CommentId.java b/src/main/java/com/najasin/domain/comment/entity/CommentId.java index e7b6307..444410e 100644 --- a/src/main/java/com/najasin/domain/comment/entity/CommentId.java +++ b/src/main/java/com/najasin/domain/comment/entity/CommentId.java @@ -1,6 +1,6 @@ package com.najasin.domain.comment.entity; -import com.najasin.domain.question.entity.Question; +import com.najasin.domain.myManual.question.entity.Question; import com.najasin.domain.user.entity.User; import jakarta.persistence.Embeddable; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/najasin/domain/keyword/entity/Keyword.java b/src/main/java/com/najasin/domain/myManual/keyword/entity/Keyword.java similarity index 92% rename from src/main/java/com/najasin/domain/keyword/entity/Keyword.java rename to src/main/java/com/najasin/domain/myManual/keyword/entity/Keyword.java index d876f4b..b1c1fd7 100644 --- a/src/main/java/com/najasin/domain/keyword/entity/Keyword.java +++ b/src/main/java/com/najasin/domain/myManual/keyword/entity/Keyword.java @@ -1,4 +1,4 @@ -package com.najasin.domain.keyword.entity; +package com.najasin.domain.myManual.keyword.entity; import com.najasin.domain.user.entity.User; import com.najasin.domain.userKeyword.entity.UserKeyword; diff --git a/src/main/java/com/najasin/domain/keyword/repository/KeywordRepository.java b/src/main/java/com/najasin/domain/myManual/keyword/repository/KeywordRepository.java similarity index 61% rename from src/main/java/com/najasin/domain/keyword/repository/KeywordRepository.java rename to src/main/java/com/najasin/domain/myManual/keyword/repository/KeywordRepository.java index 08da208..389ef1d 100644 --- a/src/main/java/com/najasin/domain/keyword/repository/KeywordRepository.java +++ b/src/main/java/com/najasin/domain/myManual/keyword/repository/KeywordRepository.java @@ -1,6 +1,6 @@ -package com.najasin.domain.keyword.repository; +package com.najasin.domain.myManual.keyword.repository; -import com.najasin.domain.keyword.entity.Keyword; +import com.najasin.domain.myManual.keyword.entity.Keyword; import org.springframework.data.jpa.repository.JpaRepository; public interface KeywordRepository extends JpaRepository { diff --git a/src/main/java/com/najasin/domain/question/entity/Question.java b/src/main/java/com/najasin/domain/myManual/question/entity/Question.java similarity index 94% rename from src/main/java/com/najasin/domain/question/entity/Question.java rename to src/main/java/com/najasin/domain/myManual/question/entity/Question.java index 1abdeb6..46c2224 100644 --- a/src/main/java/com/najasin/domain/question/entity/Question.java +++ b/src/main/java/com/najasin/domain/myManual/question/entity/Question.java @@ -1,4 +1,4 @@ -package com.najasin.domain.question.entity; +package com.najasin.domain.myManual.question.entity; import com.najasin.domain.comment.entity.Comment; import com.najasin.domain.user.entity.userType.UserType; diff --git a/src/main/java/com/najasin/domain/question/entity/QuestionType.java b/src/main/java/com/najasin/domain/myManual/question/entity/QuestionType.java similarity index 52% rename from src/main/java/com/najasin/domain/question/entity/QuestionType.java rename to src/main/java/com/najasin/domain/myManual/question/entity/QuestionType.java index cf45090..51ae4dd 100644 --- a/src/main/java/com/najasin/domain/question/entity/QuestionType.java +++ b/src/main/java/com/najasin/domain/myManual/question/entity/QuestionType.java @@ -1,4 +1,4 @@ -package com.najasin.domain.question.entity; +package com.najasin.domain.myManual.question.entity; public enum QuestionType { FOR_USER, diff --git a/src/main/java/com/najasin/domain/question/repository/QuestionRepository.java b/src/main/java/com/najasin/domain/myManual/question/repository/QuestionRepository.java similarity index 64% rename from src/main/java/com/najasin/domain/question/repository/QuestionRepository.java rename to src/main/java/com/najasin/domain/myManual/question/repository/QuestionRepository.java index b3274a8..550b791 100644 --- a/src/main/java/com/najasin/domain/question/repository/QuestionRepository.java +++ b/src/main/java/com/najasin/domain/myManual/question/repository/QuestionRepository.java @@ -1,7 +1,7 @@ -package com.najasin.domain.question.repository; +package com.najasin.domain.myManual.question.repository; -import com.najasin.domain.question.entity.Question; -import com.najasin.domain.question.entity.QuestionType; +import com.najasin.domain.myManual.question.entity.Question; +import com.najasin.domain.myManual.question.entity.QuestionType; import com.najasin.domain.user.entity.userType.UserType; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/najasin/domain/userKeyword/entity/UserKeyword.java b/src/main/java/com/najasin/domain/userKeyword/entity/UserKeyword.java index 5f1ee59..df5d84d 100644 --- a/src/main/java/com/najasin/domain/userKeyword/entity/UserKeyword.java +++ b/src/main/java/com/najasin/domain/userKeyword/entity/UserKeyword.java @@ -1,6 +1,6 @@ package com.najasin.domain.userKeyword.entity; -import com.najasin.domain.keyword.entity.Keyword; +import com.najasin.domain.myManual.keyword.entity.Keyword; import com.najasin.domain.user.entity.User; import jakarta.persistence.*; import lombok.AccessLevel; diff --git a/src/main/java/com/najasin/domain/userKeyword/entity/UserKeywordId.java b/src/main/java/com/najasin/domain/userKeyword/entity/UserKeywordId.java index bf008e3..12f8804 100644 --- a/src/main/java/com/najasin/domain/userKeyword/entity/UserKeywordId.java +++ b/src/main/java/com/najasin/domain/userKeyword/entity/UserKeywordId.java @@ -1,6 +1,6 @@ package com.najasin.domain.userKeyword.entity; -import com.najasin.domain.keyword.entity.Keyword; +import com.najasin.domain.myManual.keyword.entity.Keyword; import com.najasin.domain.user.entity.User; import jakarta.persistence.Embeddable; import lombok.Getter; From e1a5dba55f16befa7be6859653ffe5ee3625af8f Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 17:10:50 +0900 Subject: [PATCH 05/27] =?UTF-8?q?refactor(#48):=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../najasin/domain/answer/entity/Answer.java | 2 +- .../domain/answer/entity/AnswerId.java | 2 +- .../domain/comment/entity/Comment.java | 2 +- .../domain/comment/entity/CommentId.java | 2 +- .../domain/manual/keyword/entity/Keyword.java | 22 ++++++++++++++ .../keyword/repository/KeywordRepository.java | 4 +-- .../question/entity/Question.java | 12 ++++---- .../question/entity/QuestionType.java | 2 +- .../repository/QuestionRepository.java | 11 +++++++ .../question/service/QuestionService.java | 28 +++++++++++++++++ .../myManual/keyword/entity/Keyword.java | 30 ------------------- .../repository/QuestionRepository.java | 12 -------- .../userKeyword/entity/UserKeyword.java | 2 +- .../userKeyword/entity/UserKeywordId.java | 2 +- 14 files changed, 75 insertions(+), 58 deletions(-) create mode 100644 src/main/java/com/najasin/domain/manual/keyword/entity/Keyword.java rename src/main/java/com/najasin/domain/{myManual => manual}/keyword/repository/KeywordRepository.java (61%) rename src/main/java/com/najasin/domain/{myManual => manual}/question/entity/Question.java (78%) rename src/main/java/com/najasin/domain/{myManual => manual}/question/entity/QuestionType.java (52%) create mode 100644 src/main/java/com/najasin/domain/manual/question/repository/QuestionRepository.java create mode 100644 src/main/java/com/najasin/domain/manual/question/service/QuestionService.java delete mode 100644 src/main/java/com/najasin/domain/myManual/keyword/entity/Keyword.java delete mode 100644 src/main/java/com/najasin/domain/myManual/question/repository/QuestionRepository.java diff --git a/src/main/java/com/najasin/domain/answer/entity/Answer.java b/src/main/java/com/najasin/domain/answer/entity/Answer.java index 8f10503..8225bcb 100644 --- a/src/main/java/com/najasin/domain/answer/entity/Answer.java +++ b/src/main/java/com/najasin/domain/answer/entity/Answer.java @@ -1,6 +1,6 @@ package com.najasin.domain.answer.entity; -import com.najasin.domain.myManual.question.entity.Question; +import com.najasin.domain.manual.question.entity.Question; import com.najasin.domain.user.entity.User; import jakarta.persistence.*; import lombok.AccessLevel; diff --git a/src/main/java/com/najasin/domain/answer/entity/AnswerId.java b/src/main/java/com/najasin/domain/answer/entity/AnswerId.java index 9a4c2ec..5f4a425 100644 --- a/src/main/java/com/najasin/domain/answer/entity/AnswerId.java +++ b/src/main/java/com/najasin/domain/answer/entity/AnswerId.java @@ -1,6 +1,6 @@ package com.najasin.domain.answer.entity; -import com.najasin.domain.myManual.question.entity.Question; +import com.najasin.domain.manual.question.entity.Question; import com.najasin.domain.user.entity.User; import jakarta.persistence.Embeddable; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/najasin/domain/comment/entity/Comment.java b/src/main/java/com/najasin/domain/comment/entity/Comment.java index 5fc9230..fe70e99 100644 --- a/src/main/java/com/najasin/domain/comment/entity/Comment.java +++ b/src/main/java/com/najasin/domain/comment/entity/Comment.java @@ -1,6 +1,6 @@ package com.najasin.domain.comment.entity; -import com.najasin.domain.myManual.question.entity.Question; +import com.najasin.domain.manual.question.entity.Question; import com.najasin.domain.user.entity.User; import com.najasin.global.audit.AuditEntity; import jakarta.persistence.*; diff --git a/src/main/java/com/najasin/domain/comment/entity/CommentId.java b/src/main/java/com/najasin/domain/comment/entity/CommentId.java index 444410e..f99b82f 100644 --- a/src/main/java/com/najasin/domain/comment/entity/CommentId.java +++ b/src/main/java/com/najasin/domain/comment/entity/CommentId.java @@ -1,6 +1,6 @@ package com.najasin.domain.comment.entity; -import com.najasin.domain.myManual.question.entity.Question; +import com.najasin.domain.manual.question.entity.Question; import com.najasin.domain.user.entity.User; import jakarta.persistence.Embeddable; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/najasin/domain/manual/keyword/entity/Keyword.java b/src/main/java/com/najasin/domain/manual/keyword/entity/Keyword.java new file mode 100644 index 0000000..5f96497 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/keyword/entity/Keyword.java @@ -0,0 +1,22 @@ +package com.najasin.domain.manual.keyword.entity; + +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Keyword { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "keyword_id") + private Long id; + + @Column(name = "keyword_name") + private String name; + +} diff --git a/src/main/java/com/najasin/domain/myManual/keyword/repository/KeywordRepository.java b/src/main/java/com/najasin/domain/manual/keyword/repository/KeywordRepository.java similarity index 61% rename from src/main/java/com/najasin/domain/myManual/keyword/repository/KeywordRepository.java rename to src/main/java/com/najasin/domain/manual/keyword/repository/KeywordRepository.java index 389ef1d..2d36093 100644 --- a/src/main/java/com/najasin/domain/myManual/keyword/repository/KeywordRepository.java +++ b/src/main/java/com/najasin/domain/manual/keyword/repository/KeywordRepository.java @@ -1,6 +1,6 @@ -package com.najasin.domain.myManual.keyword.repository; +package com.najasin.domain.manual.keyword.repository; -import com.najasin.domain.myManual.keyword.entity.Keyword; +import com.najasin.domain.manual.keyword.entity.Keyword; import org.springframework.data.jpa.repository.JpaRepository; public interface KeywordRepository extends JpaRepository { diff --git a/src/main/java/com/najasin/domain/myManual/question/entity/Question.java b/src/main/java/com/najasin/domain/manual/question/entity/Question.java similarity index 78% rename from src/main/java/com/najasin/domain/myManual/question/entity/Question.java rename to src/main/java/com/najasin/domain/manual/question/entity/Question.java index 46c2224..3ee8381 100644 --- a/src/main/java/com/najasin/domain/myManual/question/entity/Question.java +++ b/src/main/java/com/najasin/domain/manual/question/entity/Question.java @@ -1,6 +1,6 @@ -package com.najasin.domain.myManual.question.entity; +package com.najasin.domain.manual.question.entity; -import com.najasin.domain.comment.entity.Comment; +import com.najasin.domain.manual.dto.response.JffMyQuestion; import com.najasin.domain.user.entity.userType.UserType; import jakarta.persistence.*; import lombok.AccessLevel; @@ -8,8 +8,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import java.util.List; - @Getter @Entity @AllArgsConstructor @@ -27,11 +25,11 @@ public class Question { @Enumerated(EnumType.STRING) private QuestionType questionType; - @OneToMany(mappedBy = "question") - private List comments; - @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_type_id", referencedColumnName = "user_type_id") private UserType userType; + public JffMyQuestion toJffMyQuestion() { + return new JffMyQuestion(id, question); + } } diff --git a/src/main/java/com/najasin/domain/myManual/question/entity/QuestionType.java b/src/main/java/com/najasin/domain/manual/question/entity/QuestionType.java similarity index 52% rename from src/main/java/com/najasin/domain/myManual/question/entity/QuestionType.java rename to src/main/java/com/najasin/domain/manual/question/entity/QuestionType.java index 51ae4dd..26fafc8 100644 --- a/src/main/java/com/najasin/domain/myManual/question/entity/QuestionType.java +++ b/src/main/java/com/najasin/domain/manual/question/entity/QuestionType.java @@ -1,4 +1,4 @@ -package com.najasin.domain.myManual.question.entity; +package com.najasin.domain.manual.question.entity; public enum QuestionType { FOR_USER, diff --git a/src/main/java/com/najasin/domain/manual/question/repository/QuestionRepository.java b/src/main/java/com/najasin/domain/manual/question/repository/QuestionRepository.java new file mode 100644 index 0000000..6204241 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/question/repository/QuestionRepository.java @@ -0,0 +1,11 @@ +package com.najasin.domain.manual.question.repository; + +import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.manual.question.entity.QuestionType; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface QuestionRepository extends JpaRepository { + List findAllByQuestionTypeAndUserTypeName(QuestionType questionType, String userTypeName); +} diff --git a/src/main/java/com/najasin/domain/manual/question/service/QuestionService.java b/src/main/java/com/najasin/domain/manual/question/service/QuestionService.java new file mode 100644 index 0000000..a0f27e9 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/question/service/QuestionService.java @@ -0,0 +1,28 @@ +package com.najasin.domain.manual.question.service; + +import static com.najasin.domain.manual.question.entity.QuestionType.*; + +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.najasin.domain.manual.dto.response.JffMyQuestion; +import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.manual.question.repository.QuestionRepository; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Service + +public class QuestionService { + private final QuestionRepository questionRepository; + + @Transactional(readOnly = true) + public List findAll(String userTypeName) { + List questionList = questionRepository.findAllByQuestionTypeAndUserTypeName(FOR_USER, userTypeName); + + return questionList.stream().map(Question::toJffMyQuestion).toList(); + } +} diff --git a/src/main/java/com/najasin/domain/myManual/keyword/entity/Keyword.java b/src/main/java/com/najasin/domain/myManual/keyword/entity/Keyword.java deleted file mode 100644 index b1c1fd7..0000000 --- a/src/main/java/com/najasin/domain/myManual/keyword/entity/Keyword.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.najasin.domain.myManual.keyword.entity; - -import com.najasin.domain.user.entity.User; -import com.najasin.domain.userKeyword.entity.UserKeyword; -import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.util.ArrayList; -import java.util.List; - -@Getter -@Entity -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -public class Keyword { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "keyword_id") - private Long id; - - @Column(name = "keyword_name") - private String name; - - - - -} diff --git a/src/main/java/com/najasin/domain/myManual/question/repository/QuestionRepository.java b/src/main/java/com/najasin/domain/myManual/question/repository/QuestionRepository.java deleted file mode 100644 index 550b791..0000000 --- a/src/main/java/com/najasin/domain/myManual/question/repository/QuestionRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.najasin.domain.myManual.question.repository; - -import com.najasin.domain.myManual.question.entity.Question; -import com.najasin.domain.myManual.question.entity.QuestionType; -import com.najasin.domain.user.entity.userType.UserType; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -public interface QuestionRepository extends JpaRepository { - List getQuestionsByQuestionTypeAndUserType(QuestionType questionType, UserType userType); -} diff --git a/src/main/java/com/najasin/domain/userKeyword/entity/UserKeyword.java b/src/main/java/com/najasin/domain/userKeyword/entity/UserKeyword.java index df5d84d..bca5980 100644 --- a/src/main/java/com/najasin/domain/userKeyword/entity/UserKeyword.java +++ b/src/main/java/com/najasin/domain/userKeyword/entity/UserKeyword.java @@ -1,6 +1,6 @@ package com.najasin.domain.userKeyword.entity; -import com.najasin.domain.myManual.keyword.entity.Keyword; +import com.najasin.domain.manual.keyword.entity.Keyword; import com.najasin.domain.user.entity.User; import jakarta.persistence.*; import lombok.AccessLevel; diff --git a/src/main/java/com/najasin/domain/userKeyword/entity/UserKeywordId.java b/src/main/java/com/najasin/domain/userKeyword/entity/UserKeywordId.java index 12f8804..f83cdc0 100644 --- a/src/main/java/com/najasin/domain/userKeyword/entity/UserKeywordId.java +++ b/src/main/java/com/najasin/domain/userKeyword/entity/UserKeywordId.java @@ -1,6 +1,6 @@ package com.najasin.domain.userKeyword.entity; -import com.najasin.domain.myManual.keyword.entity.Keyword; +import com.najasin.domain.manual.keyword.entity.Keyword; import com.najasin.domain.user.entity.User; import jakarta.persistence.Embeddable; import lombok.Getter; From 810c07a7cca8cf673146e281824bef1291f00cde Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 17:11:31 +0900 Subject: [PATCH 06/27] =?UTF-8?q?fix(#48):=20CharacterItems=20=EB=B9=84?= =?UTF-8?q?=EC=A6=88=EB=8B=88=EC=8A=A4=EB=A1=9C=EC=A7=81=EC=97=90=20Set=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 --- .../character/dto/response/CharacterItems.java | 3 ++- .../domain/character/entity/CharacterSet.java | 12 ++++++++++-- .../domain/character/service/CharacterService.java | 12 ++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/najasin/domain/character/dto/response/CharacterItems.java b/src/main/java/com/najasin/domain/character/dto/response/CharacterItems.java index 8f035ab..9dd2a63 100644 --- a/src/main/java/com/najasin/domain/character/dto/response/CharacterItems.java +++ b/src/main/java/com/najasin/domain/character/dto/response/CharacterItems.java @@ -6,7 +6,8 @@ public record CharacterItems(List face, List body, - List expression) { + List expression, + List set) { @Builder public CharacterItems {} } diff --git a/src/main/java/com/najasin/domain/character/entity/CharacterSet.java b/src/main/java/com/najasin/domain/character/entity/CharacterSet.java index f23a918..129cd5e 100644 --- a/src/main/java/com/najasin/domain/character/entity/CharacterSet.java +++ b/src/main/java/com/najasin/domain/character/entity/CharacterSet.java @@ -1,5 +1,7 @@ package com.najasin.domain.character.entity; +import com.najasin.domain.character.dto.response.CharacterItem; + import jakarta.persistence.*; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -19,7 +21,13 @@ public class CharacterSet { @Column(name = "set_name") private String name; - @Column(name = "set_url",columnDefinition = "TEXT") - private String url; + @Column(name = "set_show_url",columnDefinition = "TEXT") + private String show_url; + + @Column(name = "set_layout_url",columnDefinition = "TEXT") + private String layout_url; + public CharacterItem toCharacterItem() { + return new CharacterItem(id, show_url, layout_url); + } } diff --git a/src/main/java/com/najasin/domain/character/service/CharacterService.java b/src/main/java/com/najasin/domain/character/service/CharacterService.java index c89973a..9e2051d 100644 --- a/src/main/java/com/najasin/domain/character/service/CharacterService.java +++ b/src/main/java/com/najasin/domain/character/service/CharacterService.java @@ -5,8 +5,10 @@ import com.najasin.domain.character.dto.response.CharacterItem; import com.najasin.domain.character.dto.response.CharacterItems; import com.najasin.domain.character.entity.Body; +import com.najasin.domain.character.entity.CharacterSet; import com.najasin.domain.character.repository.BodyRepository; import com.najasin.domain.character.entity.Expression; +import com.najasin.domain.character.repository.CharacterSetRepository; import com.najasin.domain.character.repository.ExpressionRepository; import com.najasin.domain.character.entity.Face; import com.najasin.domain.character.repository.FaceRepository; @@ -22,17 +24,22 @@ public class CharacterService { private final FaceRepository faceRepository; private final BodyRepository bodyRepository; private final ExpressionRepository expressionRepository; + private final CharacterSetRepository characterSetRepository; @Transactional(readOnly = true) public CharacterItems findAllItems() { List faceList = findFaceAll().stream().map(Face::toCharacterItem).toList(); List bodyList = findBodyAll().stream().map(Body::toCharacterItem).toList(); List expressionList = findExpressionAll().stream().map(Expression::toCharacterItem).toList(); + List characterSetList = findCharacterSetAll().stream() + .map(CharacterSet::toCharacterItem) + .toList(); return CharacterItems.builder() .face(faceList) .body(bodyList) .expression(expressionList) + .set(characterSetList) .build(); } @@ -50,4 +57,9 @@ public List findBodyAll() { public List findExpressionAll() { return expressionRepository.findAll(); } + + @Transactional(readOnly = true) + public List findCharacterSetAll() { + return characterSetRepository.findAll(); + } } From a228a325b0cddb8f8032813d5ff2a0b72ed64ebe Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 21:49:58 +0900 Subject: [PATCH 07/27] =?UTF-8?q?refactor(#48):=20domain=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/najasin/domain/{ => manual}/answer/entity/Answer.java | 0 .../com/najasin/domain/{ => manual}/answer/entity/AnswerId.java | 0 .../domain/{ => manual}/answer/repository/AnswerRepository.java | 0 .../domain/{ => manual}/userKeyword/entity/UserKeyword.java | 0 .../domain/{ => manual}/userKeyword/entity/UserKeywordId.java | 0 .../userKeyword/repository/UserKeywordRepository.java | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename src/main/java/com/najasin/domain/{ => manual}/answer/entity/Answer.java (100%) rename src/main/java/com/najasin/domain/{ => manual}/answer/entity/AnswerId.java (100%) rename src/main/java/com/najasin/domain/{ => manual}/answer/repository/AnswerRepository.java (100%) rename src/main/java/com/najasin/domain/{ => manual}/userKeyword/entity/UserKeyword.java (100%) rename src/main/java/com/najasin/domain/{ => manual}/userKeyword/entity/UserKeywordId.java (100%) rename src/main/java/com/najasin/domain/{ => manual}/userKeyword/repository/UserKeywordRepository.java (100%) diff --git a/src/main/java/com/najasin/domain/answer/entity/Answer.java b/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java similarity index 100% rename from src/main/java/com/najasin/domain/answer/entity/Answer.java rename to src/main/java/com/najasin/domain/manual/answer/entity/Answer.java diff --git a/src/main/java/com/najasin/domain/answer/entity/AnswerId.java b/src/main/java/com/najasin/domain/manual/answer/entity/AnswerId.java similarity index 100% rename from src/main/java/com/najasin/domain/answer/entity/AnswerId.java rename to src/main/java/com/najasin/domain/manual/answer/entity/AnswerId.java diff --git a/src/main/java/com/najasin/domain/answer/repository/AnswerRepository.java b/src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java similarity index 100% rename from src/main/java/com/najasin/domain/answer/repository/AnswerRepository.java rename to src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java diff --git a/src/main/java/com/najasin/domain/userKeyword/entity/UserKeyword.java b/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java similarity index 100% rename from src/main/java/com/najasin/domain/userKeyword/entity/UserKeyword.java rename to src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java diff --git a/src/main/java/com/najasin/domain/userKeyword/entity/UserKeywordId.java b/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeywordId.java similarity index 100% rename from src/main/java/com/najasin/domain/userKeyword/entity/UserKeywordId.java rename to src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeywordId.java diff --git a/src/main/java/com/najasin/domain/userKeyword/repository/UserKeywordRepository.java b/src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java similarity index 100% rename from src/main/java/com/najasin/domain/userKeyword/repository/UserKeywordRepository.java rename to src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java From cf20bb4c16b321b1ff3dfec687e6090797035fe8 Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 21:50:38 +0900 Subject: [PATCH 08/27] =?UTF-8?q?feature(#48):=20MyManual=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20Dto=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manual/dto/message/ManualMessage.java | 12 +++++++++++ .../domain/manual/dto/param/JffMyAnswer.java | 13 ++++++++++++ .../domain/manual/dto/param/JffMyKeyword.java | 5 +++++ .../manual/dto/param/JffMyKeywordPercent.java | 13 ++++++++++++ .../manual/dto/param/JffMyQuestion.java | 5 +++++ .../dto/param/ManualCharacterItems.java | 7 +++++++ .../dto/request/MyAnswerCreateRequest.java | 5 +++++ .../dto/request/MyKeywordCreateRequest.java | 4 ++++ .../dto/request/MyManualCreateRequest.java | 21 +++++++++++++++++++ .../response/JffMyManualCreateResponse.java | 9 ++++++++ .../dto/response/JffMyManualResponse.java | 21 +++++++++++++++++++ 11 files changed, 115 insertions(+) create mode 100644 src/main/java/com/najasin/domain/manual/dto/message/ManualMessage.java create mode 100644 src/main/java/com/najasin/domain/manual/dto/param/JffMyAnswer.java create mode 100644 src/main/java/com/najasin/domain/manual/dto/param/JffMyKeyword.java create mode 100644 src/main/java/com/najasin/domain/manual/dto/param/JffMyKeywordPercent.java create mode 100644 src/main/java/com/najasin/domain/manual/dto/param/JffMyQuestion.java create mode 100644 src/main/java/com/najasin/domain/manual/dto/param/ManualCharacterItems.java create mode 100644 src/main/java/com/najasin/domain/manual/dto/request/MyAnswerCreateRequest.java create mode 100644 src/main/java/com/najasin/domain/manual/dto/request/MyKeywordCreateRequest.java create mode 100644 src/main/java/com/najasin/domain/manual/dto/request/MyManualCreateRequest.java create mode 100644 src/main/java/com/najasin/domain/manual/dto/response/JffMyManualCreateResponse.java create mode 100644 src/main/java/com/najasin/domain/manual/dto/response/JffMyManualResponse.java diff --git a/src/main/java/com/najasin/domain/manual/dto/message/ManualMessage.java b/src/main/java/com/najasin/domain/manual/dto/message/ManualMessage.java new file mode 100644 index 0000000..e15c8ba --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/message/ManualMessage.java @@ -0,0 +1,12 @@ +package com.najasin.domain.manual.dto.message; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum ManualMessage { + FIND_MY_MANUAL_SUCCESS("my manual 조회에 성공했습니다."), + CREATE_MY_MANUAL_SUCCESS("my manual 생성에 성공했습니다."); + private final String msg; +} diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffMyAnswer.java b/src/main/java/com/najasin/domain/manual/dto/param/JffMyAnswer.java new file mode 100644 index 0000000..c90e9e1 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/param/JffMyAnswer.java @@ -0,0 +1,13 @@ +package com.najasin.domain.manual.dto.param; + +import com.najasin.domain.manual.answer.entity.Answer; +import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.user.entity.User; + +public record JffMyAnswer(Long id, + String answer) { + + public Answer toAnswerEntity(User user, Question question) { + return new Answer(user, question, answer); + } +} diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffMyKeyword.java b/src/main/java/com/najasin/domain/manual/dto/param/JffMyKeyword.java new file mode 100644 index 0000000..18ade18 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/param/JffMyKeyword.java @@ -0,0 +1,5 @@ +package com.najasin.domain.manual.dto.param; + +public record JffMyKeyword(Long id, + String keyword) { +} diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffMyKeywordPercent.java b/src/main/java/com/najasin/domain/manual/dto/param/JffMyKeywordPercent.java new file mode 100644 index 0000000..f974238 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/param/JffMyKeywordPercent.java @@ -0,0 +1,13 @@ +package com.najasin.domain.manual.dto.param; + +import com.najasin.domain.manual.keyword.entity.Keyword; +import com.najasin.domain.manual.userKeyword.entity.UserKeyword; +import com.najasin.domain.user.entity.User; + +public record JffMyKeywordPercent(Long id, + Integer percent) { + + public UserKeyword toUserKeywordEntity(User user, Keyword keyword) { + return new UserKeyword(user, keyword, percent); + } +} diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffMyQuestion.java b/src/main/java/com/najasin/domain/manual/dto/param/JffMyQuestion.java new file mode 100644 index 0000000..0a9f78e --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/param/JffMyQuestion.java @@ -0,0 +1,5 @@ +package com.najasin.domain.manual.dto.param; + +public record JffMyQuestion(Long id, + String question) { +} diff --git a/src/main/java/com/najasin/domain/manual/dto/param/ManualCharacterItems.java b/src/main/java/com/najasin/domain/manual/dto/param/ManualCharacterItems.java new file mode 100644 index 0000000..08a9770 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/param/ManualCharacterItems.java @@ -0,0 +1,7 @@ +package com.najasin.domain.manual.dto.param; + +public record ManualCharacterItems(Long face, + Long body, + Long expression, + Long set) { +} diff --git a/src/main/java/com/najasin/domain/manual/dto/request/MyAnswerCreateRequest.java b/src/main/java/com/najasin/domain/manual/dto/request/MyAnswerCreateRequest.java new file mode 100644 index 0000000..6b15927 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/request/MyAnswerCreateRequest.java @@ -0,0 +1,5 @@ +package com.najasin.domain.manual.dto.request; + +public record MyAnswerCreateRequest(Long id, + String answer) { +} diff --git a/src/main/java/com/najasin/domain/manual/dto/request/MyKeywordCreateRequest.java b/src/main/java/com/najasin/domain/manual/dto/request/MyKeywordCreateRequest.java new file mode 100644 index 0000000..5479d3a --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/request/MyKeywordCreateRequest.java @@ -0,0 +1,4 @@ +package com.najasin.domain.manual.dto.request; + +public record MyKeywordCreateRequest() { +} diff --git a/src/main/java/com/najasin/domain/manual/dto/request/MyManualCreateRequest.java b/src/main/java/com/najasin/domain/manual/dto/request/MyManualCreateRequest.java new file mode 100644 index 0000000..97b7ddb --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/request/MyManualCreateRequest.java @@ -0,0 +1,21 @@ +package com.najasin.domain.manual.dto.request; + +import java.util.List; + +import com.najasin.domain.manual.dto.param.JffMyAnswer; +import com.najasin.domain.manual.dto.param.JffMyKeywordPercent; +import com.najasin.domain.manual.dto.param.ManualCharacterItems; + +public record MyManualCreateRequest(String nickname, + ManualCharacterItems characterItems, + List answers, + List keywordPercents) { + + public List getQuestionIdList() { + return answers.stream().map(JffMyAnswer::id).toList(); + } + + public List getKeywordIdList() { + return keywordPercents.stream().map(JffMyKeywordPercent::id).toList(); + } +} diff --git a/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualCreateResponse.java b/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualCreateResponse.java new file mode 100644 index 0000000..1e4d383 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualCreateResponse.java @@ -0,0 +1,9 @@ +package com.najasin.domain.manual.dto.response; + +public record JffMyManualCreateResponse(String userId, + String userType) { + + public static JffMyManualCreateResponse of(String userId, String userType) { + return new JffMyManualCreateResponse(userId, userType); + } +} diff --git a/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualResponse.java b/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualResponse.java new file mode 100644 index 0000000..fdd3af8 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualResponse.java @@ -0,0 +1,21 @@ +package com.najasin.domain.manual.dto.response; + +import java.util.List; + +import com.najasin.domain.character.dto.response.CharacterItems; +import com.najasin.domain.manual.dto.param.JffMyKeyword; +import com.najasin.domain.manual.dto.param.JffMyQuestion; + +public record JffMyManualResponse(String baseImage, + CharacterItems characterItems, + List questions, + List exampleKeywords) { + + public static JffMyManualResponse of( + String baseImage, + CharacterItems characterItems, + List questions, + List exampleKeywords) { + return new JffMyManualResponse(baseImage, characterItems, questions, exampleKeywords); + } +} From 73b137cb2bf48ccfa293cf66fa2e3499ce6ef1fc Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 21:51:14 +0900 Subject: [PATCH 09/27] =?UTF-8?q?feature(#48):=20MyManual=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/manual/answer/entity/Answer.java | 2 +- .../domain/manual/answer/entity/AnswerId.java | 2 +- .../answer/repository/AnswerRepository.java | 7 +- .../manual/answer/service/AnswerService.java | 37 ++++++++ .../manual/controller/MyManualController.java | 86 +++++++++++++++++++ .../domain/manual/keyword/entity/Keyword.java | 5 ++ .../keyword/service/KeywordService.java | 34 ++++++++ .../manual/question/entity/Question.java | 2 +- .../question/service/QuestionService.java | 13 ++- .../userKeyword/entity/UserKeyword.java | 2 +- .../userKeyword/entity/UserKeywordId.java | 2 +- .../repository/UserKeywordRepository.java | 6 +- .../service/UserKeywordService.java | 36 ++++++++ .../com/najasin/domain/user/entity/User.java | 4 +- 14 files changed, 223 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java create mode 100644 src/main/java/com/najasin/domain/manual/controller/MyManualController.java create mode 100644 src/main/java/com/najasin/domain/manual/keyword/service/KeywordService.java create mode 100644 src/main/java/com/najasin/domain/manual/userKeyword/service/UserKeywordService.java diff --git a/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java b/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java index 8225bcb..c2a3912 100644 --- a/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java +++ b/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java @@ -1,4 +1,4 @@ -package com.najasin.domain.answer.entity; +package com.najasin.domain.manual.answer.entity; import com.najasin.domain.manual.question.entity.Question; import com.najasin.domain.user.entity.User; diff --git a/src/main/java/com/najasin/domain/manual/answer/entity/AnswerId.java b/src/main/java/com/najasin/domain/manual/answer/entity/AnswerId.java index 5f4a425..022bf25 100644 --- a/src/main/java/com/najasin/domain/manual/answer/entity/AnswerId.java +++ b/src/main/java/com/najasin/domain/manual/answer/entity/AnswerId.java @@ -1,4 +1,4 @@ -package com.najasin.domain.answer.entity; +package com.najasin.domain.manual.answer.entity; import com.najasin.domain.manual.question.entity.Question; import com.najasin.domain.user.entity.User; diff --git a/src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java b/src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java index 3339c22..6e45f7e 100644 --- a/src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java +++ b/src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java @@ -1,9 +1,8 @@ -package com.najasin.domain.answer.repository; +package com.najasin.domain.manual.answer.repository; -import com.najasin.domain.answer.entity.Answer; -import com.najasin.domain.answer.entity.AnswerId; +import com.najasin.domain.manual.answer.entity.Answer; +import com.najasin.domain.manual.answer.entity.AnswerId; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; import java.util.List; diff --git a/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java b/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java new file mode 100644 index 0000000..d47f20e --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java @@ -0,0 +1,37 @@ +package com.najasin.domain.manual.answer.service; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.najasin.domain.manual.answer.entity.Answer; +import com.najasin.domain.manual.answer.repository.AnswerRepository; +import com.najasin.domain.manual.dto.param.JffMyAnswer; +import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.user.entity.User; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Service +public class AnswerService { + private final AnswerRepository answerRepository; + + @Transactional + public void saveAll(List answers, List questions, User user) { + answers.sort(Comparator.comparing(JffMyAnswer::id)); + questions.sort(Comparator.comparing(Question::getId)); + + for (int i = 0; i < answers.size(); i++) { + save(answers.get(i).toAnswerEntity(user, questions.get(i))); + } + } + + @Transactional + public Answer save(Answer answer) { + return answerRepository.save(answer); + } +} diff --git a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java new file mode 100644 index 0000000..1635668 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java @@ -0,0 +1,86 @@ +package com.najasin.domain.manual.controller; + +import static com.najasin.domain.manual.dto.message.ManualMessage.*; +import static com.najasin.global.response.ApiResponse.*; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.najasin.domain.character.dto.response.CharacterItems; +import com.najasin.domain.character.service.CharacterService; +import com.najasin.domain.manual.answer.service.AnswerService; +import com.najasin.domain.manual.dto.param.JffMyKeyword; +import com.najasin.domain.manual.dto.request.MyManualCreateRequest; +import com.najasin.domain.manual.dto.response.JffMyManualCreateResponse; +import com.najasin.domain.manual.dto.response.JffMyManualResponse; +import com.najasin.domain.manual.dto.param.JffMyQuestion; +import com.najasin.domain.manual.keyword.entity.Keyword; +import com.najasin.domain.manual.keyword.service.KeywordService; +import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.manual.question.service.QuestionService; +import com.najasin.domain.manual.userKeyword.service.UserKeywordService; +import com.najasin.domain.user.entity.User; +import com.najasin.domain.user.service.UserUserTypeService; +import com.najasin.global.annotation.AuthorizeUser; +import com.najasin.global.response.ApiResponse; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/{userType}/my-manual") +public class MyManualController { + private final CharacterService characterService; + private final QuestionService questionService; + private final KeywordService keywordService; + private final AnswerService answerService; + private final UserKeywordService userKeywordService; + private final UserUserTypeService userUserTypeService; + + @Value("${base-image}") + private String baseImage; + + @GetMapping + public ResponseEntity> getMyManual(@PathVariable String userType) { + CharacterItems characterItems = characterService.findAllItems(); + + // 추후에 다른 분기에 대한 처리 필요 + List questionList = questionService.findAll(userType); + List keywordList = keywordService.findAll(); + + return ResponseEntity.ok(createSuccessWithData( + FIND_MY_MANUAL_SUCCESS.getMsg(), + JffMyManualResponse.of(baseImage, characterItems, questionList, keywordList))); + } + + @PostMapping + public ResponseEntity> saveMyManual( + @AuthorizeUser User user, + @PathVariable String userType, + @RequestBody MyManualCreateRequest body) { + String saveUserType = userUserTypeService.updateUserType(user, userType); + + List questions = questionService.findAllByIdList(body.getQuestionIdList()); + answerService.saveAll(body.answers(), questions, user); + + List keywords = keywordService.findAllByIdList(body.getKeywordIdList()); + userKeywordService.saveAll(body.keywordPercents(), keywords, user); + + + return new ResponseEntity<>( + createSuccessWithData( + CREATE_MY_MANUAL_SUCCESS.getMsg(), + JffMyManualCreateResponse.of(user.getId(), saveUserType)), + HttpStatus.CREATED + ); + } +} diff --git a/src/main/java/com/najasin/domain/manual/keyword/entity/Keyword.java b/src/main/java/com/najasin/domain/manual/keyword/entity/Keyword.java index 5f96497..3cd3882 100644 --- a/src/main/java/com/najasin/domain/manual/keyword/entity/Keyword.java +++ b/src/main/java/com/najasin/domain/manual/keyword/entity/Keyword.java @@ -1,5 +1,7 @@ package com.najasin.domain.manual.keyword.entity; +import com.najasin.domain.manual.dto.param.JffMyKeyword; + import jakarta.persistence.*; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -19,4 +21,7 @@ public class Keyword { @Column(name = "keyword_name") private String name; + public JffMyKeyword toJffMyKeyword() { + return new JffMyKeyword(id, name); + } } diff --git a/src/main/java/com/najasin/domain/manual/keyword/service/KeywordService.java b/src/main/java/com/najasin/domain/manual/keyword/service/KeywordService.java new file mode 100644 index 0000000..1298631 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/keyword/service/KeywordService.java @@ -0,0 +1,34 @@ +package com.najasin.domain.manual.keyword.service; + +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.najasin.domain.manual.dto.param.JffMyKeyword; +import com.najasin.domain.manual.keyword.entity.Keyword; +import com.najasin.domain.manual.keyword.repository.KeywordRepository; + +import jakarta.persistence.EntityNotFoundException; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Service +public class KeywordService { + private final KeywordRepository keywordRepository; + + @Transactional(readOnly = true) + public List findAllByIdList(List keywordIds) { + return keywordIds.stream().map(this::findById).toList(); + } + + @Transactional(readOnly = true) + public Keyword findById(Long id) { + return keywordRepository.findById(id).orElseThrow(EntityNotFoundException::new); + } + + @Transactional(readOnly = true) + public List findAll() { + return keywordRepository.findAll().stream().map(Keyword::toJffMyKeyword).toList(); + } +} diff --git a/src/main/java/com/najasin/domain/manual/question/entity/Question.java b/src/main/java/com/najasin/domain/manual/question/entity/Question.java index 3ee8381..e6f8c76 100644 --- a/src/main/java/com/najasin/domain/manual/question/entity/Question.java +++ b/src/main/java/com/najasin/domain/manual/question/entity/Question.java @@ -1,6 +1,6 @@ package com.najasin.domain.manual.question.entity; -import com.najasin.domain.manual.dto.response.JffMyQuestion; +import com.najasin.domain.manual.dto.param.JffMyQuestion; import com.najasin.domain.user.entity.userType.UserType; import jakarta.persistence.*; import lombok.AccessLevel; diff --git a/src/main/java/com/najasin/domain/manual/question/service/QuestionService.java b/src/main/java/com/najasin/domain/manual/question/service/QuestionService.java index a0f27e9..346ba84 100644 --- a/src/main/java/com/najasin/domain/manual/question/service/QuestionService.java +++ b/src/main/java/com/najasin/domain/manual/question/service/QuestionService.java @@ -7,10 +7,11 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.najasin.domain.manual.dto.response.JffMyQuestion; +import com.najasin.domain.manual.dto.param.JffMyQuestion; import com.najasin.domain.manual.question.entity.Question; import com.najasin.domain.manual.question.repository.QuestionRepository; +import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @@ -25,4 +26,14 @@ public List findAll(String userTypeName) { return questionList.stream().map(Question::toJffMyQuestion).toList(); } + + @Transactional(readOnly = true) + public List findAllByIdList(List questionIds) { + return questionIds.stream().map(this::findById).toList(); + } + + @Transactional(readOnly = true) + public Question findById(Long id) { + return questionRepository.findById(id).orElseThrow(EntityNotFoundException::new); + } } diff --git a/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java b/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java index bca5980..3c3cd49 100644 --- a/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java +++ b/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java @@ -1,4 +1,4 @@ -package com.najasin.domain.userKeyword.entity; +package com.najasin.domain.manual.userKeyword.entity; import com.najasin.domain.manual.keyword.entity.Keyword; import com.najasin.domain.user.entity.User; diff --git a/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeywordId.java b/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeywordId.java index f83cdc0..538b107 100644 --- a/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeywordId.java +++ b/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeywordId.java @@ -1,4 +1,4 @@ -package com.najasin.domain.userKeyword.entity; +package com.najasin.domain.manual.userKeyword.entity; import com.najasin.domain.manual.keyword.entity.Keyword; import com.najasin.domain.user.entity.User; diff --git a/src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java b/src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java index 3352ac2..5184642 100644 --- a/src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java +++ b/src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java @@ -1,7 +1,7 @@ -package com.najasin.domain.userKeyword.repository; +package com.najasin.domain.manual.userKeyword.repository; -import com.najasin.domain.userKeyword.entity.UserKeyword; -import com.najasin.domain.userKeyword.entity.UserKeywordId; +import com.najasin.domain.manual.userKeyword.entity.UserKeyword; +import com.najasin.domain.manual.userKeyword.entity.UserKeywordId; import org.springframework.data.jpa.repository.JpaRepository; public interface UserKeywordRepository extends JpaRepository { diff --git a/src/main/java/com/najasin/domain/manual/userKeyword/service/UserKeywordService.java b/src/main/java/com/najasin/domain/manual/userKeyword/service/UserKeywordService.java new file mode 100644 index 0000000..3d5b80d --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/userKeyword/service/UserKeywordService.java @@ -0,0 +1,36 @@ +package com.najasin.domain.manual.userKeyword.service; + +import java.util.Comparator; +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.najasin.domain.manual.dto.param.JffMyKeywordPercent; +import com.najasin.domain.manual.keyword.entity.Keyword; +import com.najasin.domain.manual.userKeyword.entity.UserKeyword; +import com.najasin.domain.manual.userKeyword.repository.UserKeywordRepository; +import com.najasin.domain.user.entity.User; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Service +public class UserKeywordService { + private final UserKeywordRepository userKeywordRepository; + + @Transactional + public void saveAll(List keywordPercents, List keywords, User user) { + keywordPercents.sort(Comparator.comparing(JffMyKeywordPercent::id)); + keywords.sort(Comparator.comparing(Keyword::getId)); + + for (int i = 0; i < keywordPercents.size(); i++) { + save(keywordPercents.get(i).toUserKeywordEntity(user, keywords.get(i))); + } + } + + @Transactional + public UserKeyword save(UserKeyword userKeyword) { + return userKeywordRepository.save(userKeyword); + } +} diff --git a/src/main/java/com/najasin/domain/user/entity/User.java b/src/main/java/com/najasin/domain/user/entity/User.java index 2abe46c..7f85a45 100644 --- a/src/main/java/com/najasin/domain/user/entity/User.java +++ b/src/main/java/com/najasin/domain/user/entity/User.java @@ -3,10 +3,10 @@ import java.util.ArrayList; import java.util.List; -import com.najasin.domain.answer.entity.Answer; +import com.najasin.domain.manual.answer.entity.Answer; import com.najasin.domain.comment.entity.Comment; import com.najasin.domain.user.entity.userType.UserType; -import com.najasin.domain.userKeyword.entity.UserKeyword; +import com.najasin.domain.manual.userKeyword.entity.UserKeyword; import com.najasin.domain.user.entity.userType.UserUserType; import jakarta.persistence.*; import lombok.*; From 3c920e1a1d25db6600fc4a037185e5e2c3bd9a4d Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 22:16:35 +0900 Subject: [PATCH 10/27] =?UTF-8?q?fix(#48):=20MyManual=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=97=90=20=EC=BA=90=EB=A6=AD=ED=84=B0=20=EC=83=9D=EC=84=B1=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 --- .../character/service/CharacterService.java | 21 +++++ .../manual/controller/MyManualController.java | 4 + .../com/najasin/domain/user/entity/User.java | 92 +++++++++++++------ .../domain/user/service/UserService.java | 24 ++++- 4 files changed, 108 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/najasin/domain/character/service/CharacterService.java b/src/main/java/com/najasin/domain/character/service/CharacterService.java index 9e2051d..44aafa8 100644 --- a/src/main/java/com/najasin/domain/character/service/CharacterService.java +++ b/src/main/java/com/najasin/domain/character/service/CharacterService.java @@ -13,6 +13,7 @@ import com.najasin.domain.character.entity.Face; import com.najasin.domain.character.repository.FaceRepository; +import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -43,6 +44,26 @@ public CharacterItems findAllItems() { .build(); } + @Transactional(readOnly = true) + public Face findFaceById(Long id) { + return faceRepository.findById(id).orElseThrow(EntityNotFoundException::new); + } + + @Transactional(readOnly = true) + public Body findBodyById(Long id) { + return bodyRepository.findById(id).orElseThrow(EntityNotFoundException::new); + } + + @Transactional(readOnly = true) + public Expression findExpressionById(Long id) { + return expressionRepository.findById(id).orElseThrow(EntityNotFoundException::new); + } + + @Transactional(readOnly = true) + public CharacterSet findCharacterSetById(Long id) { + return characterSetRepository.findById(id).orElseThrow(EntityNotFoundException::new); + } + @Transactional(readOnly = true) public List findFaceAll() { return faceRepository.findAll(); diff --git a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java index 1635668..c01cf01 100644 --- a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java +++ b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java @@ -29,6 +29,7 @@ import com.najasin.domain.manual.question.service.QuestionService; import com.najasin.domain.manual.userKeyword.service.UserKeywordService; import com.najasin.domain.user.entity.User; +import com.najasin.domain.user.service.UserService; import com.najasin.domain.user.service.UserUserTypeService; import com.najasin.global.annotation.AuthorizeUser; import com.najasin.global.response.ApiResponse; @@ -44,6 +45,7 @@ public class MyManualController { private final KeywordService keywordService; private final AnswerService answerService; private final UserKeywordService userKeywordService; + private final UserService userService; private final UserUserTypeService userUserTypeService; @Value("${base-image}") @@ -69,6 +71,8 @@ public ResponseEntity> saveMyManual( @RequestBody MyManualCreateRequest body) { String saveUserType = userUserTypeService.updateUserType(user, userType); + userService.updateCharacter(user, body.characterItems()); + List questions = questionService.findAllByIdList(body.getQuestionIdList()); answerService.saveAll(body.answers(), questions, user); diff --git a/src/main/java/com/najasin/domain/user/entity/User.java b/src/main/java/com/najasin/domain/user/entity/User.java index 7f85a45..f92e502 100644 --- a/src/main/java/com/najasin/domain/user/entity/User.java +++ b/src/main/java/com/najasin/domain/user/entity/User.java @@ -3,6 +3,10 @@ import java.util.ArrayList; import java.util.List; +import com.najasin.domain.character.entity.Body; +import com.najasin.domain.character.entity.CharacterSet; +import com.najasin.domain.character.entity.Expression; +import com.najasin.domain.character.entity.Face; import com.najasin.domain.manual.answer.entity.Answer; import com.najasin.domain.comment.entity.Comment; import com.najasin.domain.user.entity.userType.UserType; @@ -41,14 +45,14 @@ public class User { private List role; - @OneToMany(mappedBy = "user") - private List userKeywords; - - @OneToMany(mappedBy = "user") - private List answers; - - @OneToMany(mappedBy = "user") - private List comments; + // @OneToMany(mappedBy = "user") + // private List userKeywords; + // + // @OneToMany(mappedBy = "user") + // private List answers; + // + // @OneToMany(mappedBy = "user") + // private List comments; @OneToMany(mappedBy = "user") private List userUserTypes; @@ -57,6 +61,22 @@ public class User { @JoinColumn(name = "last_user_type", referencedColumnName = "user_type_id") private UserType lastUserType; + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "face_id", referencedColumnName = "face_id") + private Face face; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "expression_id", referencedColumnName = "expression_id") + private Expression expression; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "body_id", referencedColumnName = "body_id") + private Body body; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "set_id", referencedColumnName = "set_id") + private CharacterSet set; + @Embedded private Oauth2Entity oauth2Entity; @@ -69,9 +89,9 @@ public User(String id, Oauth2Entity oauth2Entity) { this.role = new ArrayList<>(List.of(Role.ROLE_MEMBER)); this.auditEntity = new AuditEntity(); - userKeywords = new ArrayList<>(); - answers = new ArrayList<>(); - comments = new ArrayList<>(); + // userKeywords = new ArrayList<>(); + // answers = new ArrayList<>(); + // comments = new ArrayList<>(); userUserTypes = new ArrayList<>(); } @@ -79,31 +99,47 @@ public void updateLastUserType(UserType lastUserType) { this.lastUserType = lastUserType; } - public void updateAnswer(List answers) { - this.answers = answers; - } + public void updateCharacter(CharacterSet set) { + this.set = set; - public void updateNickname(String nickname) { - this.nickname = nickname; + this.face = null; + this.body = null; + this.expression = null; } - public void updateUserUserType(UserUserType userUserType) { - for (UserUserType uut : this.userUserTypes) { - if (uut.getUserType() == userUserType.getUserType()) { - this.userUserTypes.remove(uut); - break; - } - } - this.userUserTypes.add(userUserType); + public void updateCharacter(Face face, Body body, Expression expression) { + this.face = face; + this.body = body; + this.expression = expression; + + this.set = null; } - public void deleteKeywords(){ - this.userKeywords = new ArrayList<>();} + // public void updateAnswer(List answers) { + // this.answers = answers; + // } - public void updateKeyword(UserKeyword userKeyword) { - this.userKeywords.add(userKeyword); + public void updateNickname(String nickname) { + this.nickname = nickname; } + // public void updateUserUserType(UserUserType userUserType) { + // for (UserUserType uut : this.userUserTypes) { + // if (uut.getUserType() == userUserType.getUserType()) { + // this.userUserTypes.remove(uut); + // break; + // } + // } + // this.userUserTypes.add(userUserType); + // } + // + // public void deleteKeywords(){ + // this.userKeywords = new ArrayList<>();} + // + // public void updateKeyword(UserKeyword userKeyword) { + // this.userKeywords.add(userKeyword); + // } + public List getRole() { return role.stream() .map(Role::name) diff --git a/src/main/java/com/najasin/domain/user/service/UserService.java b/src/main/java/com/najasin/domain/user/service/UserService.java index 854eff0..ba656a3 100644 --- a/src/main/java/com/najasin/domain/user/service/UserService.java +++ b/src/main/java/com/najasin/domain/user/service/UserService.java @@ -1,14 +1,19 @@ package com.najasin.domain.user.service; +import static java.util.Objects.*; + import java.util.UUID; import com.najasin.domain.character.repository.BodyRepository; import com.najasin.domain.character.repository.CharacterSetRepository; import com.najasin.domain.character.repository.ExpressionRepository; import com.najasin.domain.character.repository.FaceRepository; + import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.najasin.domain.character.service.CharacterService; +import com.najasin.domain.manual.dto.param.ManualCharacterItems; import com.najasin.domain.user.entity.Oauth2Entity; import com.najasin.domain.user.entity.User; import com.najasin.domain.user.repository.UserRepository; @@ -22,17 +27,16 @@ @RequiredArgsConstructor public class UserService { private final UserRepository userRepository; - private final CharacterSetRepository characterSetRepository; + private final CharacterService characterService; private final FaceRepository faceRepository; private final BodyRepository bodyRepository; private final ExpressionRepository expressionRepository; private final RedisBlackListUtil redisBlackListUtil; - @Transactional public User saveIfNewUser(OAuth2Request request) { return userRepository.findUserByOauth2EntityProviderId(request.providerId()).orElseGet( - () -> save(request.toOauth2Entity())); + () -> save(request.toOauth2Entity())); } @Transactional @@ -51,6 +55,18 @@ public void logout(String accessToken, String refreshToken) { redisBlackListUtil.setBlackList(refreshToken, "refreshToken", 7); } + @Transactional + public void updateCharacter(User user, ManualCharacterItems items) { + if (!isNull(items.set())) { + user.updateCharacter(characterService.findCharacterSetById(items.set())); + } else { + user.updateCharacter( + characterService.findFaceById(items.face()), + characterService.findBodyById(items.body()), + characterService.findExpressionById(items.expression())); + } + } + @Transactional public User updateNickname(String id, String nickname) { User user = this.findById(id); @@ -58,7 +74,6 @@ public User updateNickname(String id, String nickname) { return user; } - public String generateUUID() { String uuid = UUID.randomUUID().toString(); @@ -69,7 +84,6 @@ public String generateUUID() { return uuid; } - public boolean checkDuplicatedUUID(String uuid) { return userRepository.findById(uuid).isPresent(); } From 9ec5d0a58a5d97de3577852cdbdbda702ee02e6a Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 22:44:07 +0900 Subject: [PATCH 11/27] =?UTF-8?q?fix(#48):=20=EC=BA=90=EB=A6=AD=ED=84=B0?= =?UTF-8?q?=20=EC=A0=80=EC=9E=A5=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manual/controller/MyManualController.java | 10 ++--- .../dto/response/UserTypeUpdateResponse.java | 9 +++++ .../com/najasin/domain/user/entity/User.java | 32 --------------- .../user/entity/userType/UserUserType.java | 37 ++++++++++++++++- .../repository/UserUserTypeRepository.java | 2 + .../domain/user/service/UserService.java | 17 -------- .../user/service/UserUserTypeService.java | 40 ++++++++++++++++--- 7 files changed, 85 insertions(+), 62 deletions(-) create mode 100644 src/main/java/com/najasin/domain/user/dto/response/UserTypeUpdateResponse.java diff --git a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java index c01cf01..08714ca 100644 --- a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java +++ b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java @@ -29,7 +29,7 @@ import com.najasin.domain.manual.question.service.QuestionService; import com.najasin.domain.manual.userKeyword.service.UserKeywordService; import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.service.UserService; +import com.najasin.domain.user.entity.userType.UserUserType; import com.najasin.domain.user.service.UserUserTypeService; import com.najasin.global.annotation.AuthorizeUser; import com.najasin.global.response.ApiResponse; @@ -45,7 +45,6 @@ public class MyManualController { private final KeywordService keywordService; private final AnswerService answerService; private final UserKeywordService userKeywordService; - private final UserService userService; private final UserUserTypeService userUserTypeService; @Value("${base-image}") @@ -69,9 +68,8 @@ public ResponseEntity> saveMyManual( @AuthorizeUser User user, @PathVariable String userType, @RequestBody MyManualCreateRequest body) { - String saveUserType = userUserTypeService.updateUserType(user, userType); - - userService.updateCharacter(user, body.characterItems()); + UserUserType saveUserType = userUserTypeService.save(user, userType, body.nickname()); + userUserTypeService.updateCharacter(saveUserType, body.characterItems()); List questions = questionService.findAllByIdList(body.getQuestionIdList()); answerService.saveAll(body.answers(), questions, user); @@ -83,7 +81,7 @@ public ResponseEntity> saveMyManual( return new ResponseEntity<>( createSuccessWithData( CREATE_MY_MANUAL_SUCCESS.getMsg(), - JffMyManualCreateResponse.of(user.getId(), saveUserType)), + JffMyManualCreateResponse.of(user.getId(), userType)), HttpStatus.CREATED ); } diff --git a/src/main/java/com/najasin/domain/user/dto/response/UserTypeUpdateResponse.java b/src/main/java/com/najasin/domain/user/dto/response/UserTypeUpdateResponse.java new file mode 100644 index 0000000..62f65d0 --- /dev/null +++ b/src/main/java/com/najasin/domain/user/dto/response/UserTypeUpdateResponse.java @@ -0,0 +1,9 @@ +package com.najasin.domain.user.dto.response; + +public record UserTypeUpdateResponse(String userType, + Boolean existFlag) { + + public static UserTypeUpdateResponse of(String userType, Boolean existFlag) { + return new UserTypeUpdateResponse(userType, existFlag); + } +} diff --git a/src/main/java/com/najasin/domain/user/entity/User.java b/src/main/java/com/najasin/domain/user/entity/User.java index f92e502..70034ad 100644 --- a/src/main/java/com/najasin/domain/user/entity/User.java +++ b/src/main/java/com/najasin/domain/user/entity/User.java @@ -61,22 +61,6 @@ public class User { @JoinColumn(name = "last_user_type", referencedColumnName = "user_type_id") private UserType lastUserType; - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "face_id", referencedColumnName = "face_id") - private Face face; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "expression_id", referencedColumnName = "expression_id") - private Expression expression; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "body_id", referencedColumnName = "body_id") - private Body body; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "set_id", referencedColumnName = "set_id") - private CharacterSet set; - @Embedded private Oauth2Entity oauth2Entity; @@ -99,22 +83,6 @@ public void updateLastUserType(UserType lastUserType) { this.lastUserType = lastUserType; } - public void updateCharacter(CharacterSet set) { - this.set = set; - - this.face = null; - this.body = null; - this.expression = null; - } - - public void updateCharacter(Face face, Body body, Expression expression) { - this.face = face; - this.body = body; - this.expression = expression; - - this.set = null; - } - // public void updateAnswer(List answers) { // this.answers = answers; // } diff --git a/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java b/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java index 78befda..fa8cc31 100644 --- a/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java +++ b/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java @@ -1,6 +1,9 @@ package com.najasin.domain.user.entity.userType; +import com.najasin.domain.character.entity.Body; import com.najasin.domain.character.entity.CharacterSet; +import com.najasin.domain.character.entity.Expression; +import com.najasin.domain.character.entity.Face; import com.najasin.domain.user.entity.User; import jakarta.persistence.*; @@ -25,12 +28,44 @@ public class UserUserType { @JoinColumn(name = "user_type_id", referencedColumnName = "user_type_id", insertable = false, updatable = false) private UserType userType; + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "face_id", referencedColumnName = "face_id") + private Face face; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "expression_id", referencedColumnName = "expression_id") + private Expression expression; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "body_id", referencedColumnName = "body_id") + private Body body; + @ManyToOne @JoinColumn(name = "character_set_id", referencedColumnName = "set_id") private CharacterSet set; - public UserUserType(User user, UserType userType) { + @Column(name = "nickname") + private String nickname; + + public UserUserType(User user, UserType userType, String nickname) { this.user = user; this.userType = userType; + this.nickname = nickname; + } + + public void updateCharacter(CharacterSet set) { + this.set = set; + + this.face = null; + this.body = null; + this.expression = null; + } + + public void updateCharacter(Face face, Body body, Expression expression) { + this.face = face; + this.body = body; + this.expression = expression; + + this.set = null; } } diff --git a/src/main/java/com/najasin/domain/user/repository/UserUserTypeRepository.java b/src/main/java/com/najasin/domain/user/repository/UserUserTypeRepository.java index 3a13b97..9200251 100644 --- a/src/main/java/com/najasin/domain/user/repository/UserUserTypeRepository.java +++ b/src/main/java/com/najasin/domain/user/repository/UserUserTypeRepository.java @@ -6,7 +6,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; +import java.util.Optional; public interface UserUserTypeRepository extends JpaRepository { + Optional findByUserIdAndUserTypeName(String userId, String userTypeName); List findAllByUser(User user); } diff --git a/src/main/java/com/najasin/domain/user/service/UserService.java b/src/main/java/com/najasin/domain/user/service/UserService.java index ba656a3..462ca87 100644 --- a/src/main/java/com/najasin/domain/user/service/UserService.java +++ b/src/main/java/com/najasin/domain/user/service/UserService.java @@ -13,7 +13,6 @@ import org.springframework.transaction.annotation.Transactional; import com.najasin.domain.character.service.CharacterService; -import com.najasin.domain.manual.dto.param.ManualCharacterItems; import com.najasin.domain.user.entity.Oauth2Entity; import com.najasin.domain.user.entity.User; import com.najasin.domain.user.repository.UserRepository; @@ -27,10 +26,6 @@ @RequiredArgsConstructor public class UserService { private final UserRepository userRepository; - private final CharacterService characterService; - private final FaceRepository faceRepository; - private final BodyRepository bodyRepository; - private final ExpressionRepository expressionRepository; private final RedisBlackListUtil redisBlackListUtil; @Transactional @@ -55,18 +50,6 @@ public void logout(String accessToken, String refreshToken) { redisBlackListUtil.setBlackList(refreshToken, "refreshToken", 7); } - @Transactional - public void updateCharacter(User user, ManualCharacterItems items) { - if (!isNull(items.set())) { - user.updateCharacter(characterService.findCharacterSetById(items.set())); - } else { - user.updateCharacter( - characterService.findFaceById(items.face()), - characterService.findBodyById(items.body()), - characterService.findExpressionById(items.expression())); - } - } - @Transactional public User updateNickname(String id, String nickname) { User user = this.findById(id); diff --git a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java index 4ae2cc2..944fbe4 100644 --- a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java +++ b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java @@ -1,9 +1,14 @@ package com.najasin.domain.user.service; +import static java.util.Objects.*; + import com.najasin.domain.character.repository.BodyRepository; import com.najasin.domain.character.repository.CharacterSetRepository; import com.najasin.domain.character.repository.ExpressionRepository; import com.najasin.domain.character.repository.FaceRepository; +import com.najasin.domain.character.service.CharacterService; +import com.najasin.domain.manual.dto.param.ManualCharacterItems; +import com.najasin.domain.user.dto.response.UserTypeUpdateResponse; import com.najasin.domain.user.entity.User; import com.najasin.domain.user.repository.UserRepository; import com.najasin.domain.user.entity.userType.UserType; @@ -11,8 +16,10 @@ import com.najasin.domain.user.entity.userType.UserUserType; import com.najasin.domain.user.repository.UserUserTypeRepository; +import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; +import org.springframework.security.core.parameters.P; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,22 +30,43 @@ public class UserUserTypeService { private final UserUserTypeRepository userUserTypeRepository; private final UserTypeService userTypeService; + private final CharacterService characterService; @Transactional - public String updateUserType(User user, String userTypeName) { + public UserTypeUpdateResponse updateUserType(User user, String userTypeName) { UserType userType = userTypeService.findByName(userTypeName); + user.updateLastUserType(userType); if (!checkAlreadyExist(user.getUserUserTypes(), userType)) { - save(user, userType); + return UserTypeUpdateResponse.of(userTypeName, Boolean.FALSE); } - user.updateLastUserType(userType); - return userTypeName; + return UserTypeUpdateResponse.of(userTypeName, Boolean.TRUE); } @Transactional - public UserUserType save(User user, UserType userType) { - return userUserTypeRepository.save(new UserUserType(user, userType)); + public UserUserType save(User user, String userTypeName, String nickname) { + UserType userType = userTypeService.findByName(userTypeName); + + return userUserTypeRepository.save(new UserUserType(user, userType, nickname)); + } + + @Transactional + public void updateCharacter(UserUserType userUserType, ManualCharacterItems items) { + if (!isNull(items.set())) { + userUserType.updateCharacter(characterService.findCharacterSetById(items.set())); + } else { + userUserType.updateCharacter( + characterService.findFaceById(items.face()), + characterService.findBodyById(items.body()), + characterService.findExpressionById(items.expression())); + } + } + + @Transactional(readOnly = true) + public UserUserType findByUserIdAndUserTypeName(String userId, String userTypeName) { + return userUserTypeRepository.findByUserIdAndUserTypeName(userId, userTypeName) + .orElseThrow(EntityNotFoundException::new); } private boolean checkAlreadyExist(List userUserTypes, UserType userType) { From 37d9efedc9f87728c7fc8f6de00e5c3a9b7456c1 Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 22:58:48 +0900 Subject: [PATCH 12/27] =?UTF-8?q?feature(#48):=20=EC=BA=90=EB=A6=AD?= =?UTF-8?q?=ED=84=B0=20=EC=88=98=EC=A0=95=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 27 +++++++++++++++---- .../domain/user/dto/message/UserResponse.java | 5 ++-- .../dto/request/CharacterUpdateRequest.java | 13 +++++++++ .../user/dto/response/UserTypeResponse.java | 8 ------ 4 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/najasin/domain/user/dto/request/CharacterUpdateRequest.java delete mode 100644 src/main/java/com/najasin/domain/user/dto/response/UserTypeResponse.java diff --git a/src/main/java/com/najasin/domain/user/controller/UserController.java b/src/main/java/com/najasin/domain/user/controller/UserController.java index 2b7d4bf..eabae0a 100644 --- a/src/main/java/com/najasin/domain/user/controller/UserController.java +++ b/src/main/java/com/najasin/domain/user/controller/UserController.java @@ -1,5 +1,8 @@ package com.najasin.domain.user.controller; +import static com.najasin.domain.user.dto.message.UserResponse.*; +import static com.najasin.global.response.ApiResponse.*; + import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -10,10 +13,12 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.najasin.domain.user.dto.request.CharacterUpdateRequest; +import com.najasin.domain.user.dto.response.UserTypeUpdateResponse; import com.najasin.domain.user.entity.User; import com.najasin.domain.user.dto.message.UserTypeMessage; import com.najasin.domain.user.dto.request.UserTypeUpdateRequest; -import com.najasin.domain.user.dto.response.UserTypeResponse; +import com.najasin.domain.user.entity.userType.UserUserType; import com.najasin.domain.user.service.UserUserTypeService; import com.najasin.global.annotation.AuthorizeUser; import com.najasin.global.response.ApiResponse; @@ -35,12 +40,24 @@ public ResponseEntity> getMyPage( } @PutMapping("/type") - public ResponseEntity> updateUserType(@AuthorizeUser User user, + public ResponseEntity> updateUserType( + @AuthorizeUser User user, @RequestBody @Validated UserTypeUpdateRequest request) { - String updatedUserType = userUserTypeService.updateUserType(user, request.userType()); + UserTypeUpdateResponse response = userUserTypeService.updateUserType(user, request.userType()); - return ResponseEntity.ok(ApiResponse.createSuccessWithData( + return ResponseEntity.ok(createSuccessWithData( UserTypeMessage.SUCCESS_UPDATE_USER_TYPE.getMsg(), - UserTypeResponse.of(updatedUserType))); + response)); + } + + @PutMapping("/{userType}/character") + public ResponseEntity> updateCharacter( + @AuthorizeUser User user, + @PathVariable String userType, + @RequestBody CharacterUpdateRequest request) { + UserUserType userUserType = userUserTypeService.findByUserIdAndUserTypeName(user.getId(), userType); + userUserTypeService.updateCharacter(userUserType, request.toManualCharacterItems()); + + return ResponseEntity.ok(createSuccess(SUCCESS_UPDATE_CHARACTER.getMessage())); } } diff --git a/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java b/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java index b7ec70d..6449170 100644 --- a/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java +++ b/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java @@ -7,7 +7,8 @@ @RequiredArgsConstructor public enum UserResponse { SUCCESS_LOGOUT("로그아웃에 성공하셨습니다."), - SUCCESS_UPDATE("업데이트에 성공하였습니다."), - SUCCESS_GET_PAGE("페이지 로딩에 성공하였습니다."); + SUCCESS_UPDATE_CHARACTER("캐릭터 수정에 성공하였습니다."), + SUCCESS_GET_PAGE("페이지 로딩에 성공하였습니다."), + ; private final String message; } diff --git a/src/main/java/com/najasin/domain/user/dto/request/CharacterUpdateRequest.java b/src/main/java/com/najasin/domain/user/dto/request/CharacterUpdateRequest.java new file mode 100644 index 0000000..591ecbc --- /dev/null +++ b/src/main/java/com/najasin/domain/user/dto/request/CharacterUpdateRequest.java @@ -0,0 +1,13 @@ +package com.najasin.domain.user.dto.request; + +import com.najasin.domain.manual.dto.param.ManualCharacterItems; + +public record CharacterUpdateRequest(Long face, + Long body, + Long expression, + Long set) { + + public ManualCharacterItems toManualCharacterItems() { + return new ManualCharacterItems(face, body, expression, set); + } +} diff --git a/src/main/java/com/najasin/domain/user/dto/response/UserTypeResponse.java b/src/main/java/com/najasin/domain/user/dto/response/UserTypeResponse.java deleted file mode 100644 index caf697d..0000000 --- a/src/main/java/com/najasin/domain/user/dto/response/UserTypeResponse.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.najasin.domain.user.dto.response; - -public record UserTypeResponse(String userType) { - - public static UserTypeResponse of(String userType) { - return new UserTypeResponse(userType); - } -} From cc90b65aa2630221e0308dbe1be5b974984251ea Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 23:40:15 +0900 Subject: [PATCH 13/27] =?UTF-8?q?feature(#48):=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EC=88=98=EC=A0=95=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/controller/UserController.java | 13 +++++++++++++ .../domain/user/dto/message/UserResponse.java | 1 + .../user/dto/request/NicknameUpdateRequest.java | 4 ++++ .../domain/user/entity/userType/UserUserType.java | 4 ++++ .../domain/user/service/UserUserTypeService.java | 5 +++++ 5 files changed, 27 insertions(+) create mode 100644 src/main/java/com/najasin/domain/user/dto/request/NicknameUpdateRequest.java diff --git a/src/main/java/com/najasin/domain/user/controller/UserController.java b/src/main/java/com/najasin/domain/user/controller/UserController.java index eabae0a..75aad49 100644 --- a/src/main/java/com/najasin/domain/user/controller/UserController.java +++ b/src/main/java/com/najasin/domain/user/controller/UserController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController; import com.najasin.domain.user.dto.request.CharacterUpdateRequest; +import com.najasin.domain.user.dto.request.NicknameUpdateRequest; import com.najasin.domain.user.dto.response.UserTypeUpdateResponse; import com.najasin.domain.user.entity.User; import com.najasin.domain.user.dto.message.UserTypeMessage; @@ -50,6 +51,18 @@ public ResponseEntity> updateUserType( response)); } + @PutMapping("/{userType}/nickname") + public ResponseEntity> updateNickname( + @AuthorizeUser User user, + @PathVariable String userType, + @RequestBody NicknameUpdateRequest request) { + UserUserType userUserType = userUserTypeService.findByUserIdAndUserTypeName(user.getId(), userType); + userUserTypeService.updateNickname(userUserType, request.nickname()); + + return ResponseEntity.ok(createSuccess(SUCCESS_UPDATE_NICKNAME.getMessage())); + } + + @PutMapping("/{userType}/character") public ResponseEntity> updateCharacter( @AuthorizeUser User user, diff --git a/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java b/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java index 6449170..6214771 100644 --- a/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java +++ b/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java @@ -7,6 +7,7 @@ @RequiredArgsConstructor public enum UserResponse { SUCCESS_LOGOUT("로그아웃에 성공하셨습니다."), + SUCCESS_UPDATE_NICKNAME("닉네임 수정에 성공하였습니다."), SUCCESS_UPDATE_CHARACTER("캐릭터 수정에 성공하였습니다."), SUCCESS_GET_PAGE("페이지 로딩에 성공하였습니다."), ; diff --git a/src/main/java/com/najasin/domain/user/dto/request/NicknameUpdateRequest.java b/src/main/java/com/najasin/domain/user/dto/request/NicknameUpdateRequest.java new file mode 100644 index 0000000..87a66f7 --- /dev/null +++ b/src/main/java/com/najasin/domain/user/dto/request/NicknameUpdateRequest.java @@ -0,0 +1,4 @@ +package com.najasin.domain.user.dto.request; + +public record NicknameUpdateRequest(String nickname) { +} diff --git a/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java b/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java index fa8cc31..ecbce13 100644 --- a/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java +++ b/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java @@ -53,6 +53,10 @@ public UserUserType(User user, UserType userType, String nickname) { this.nickname = nickname; } + public void updateNickname(String nickname) { + this.nickname = nickname; + } + public void updateCharacter(CharacterSet set) { this.set = set; diff --git a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java index 944fbe4..2f7048b 100644 --- a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java +++ b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java @@ -51,6 +51,11 @@ public UserUserType save(User user, String userTypeName, String nickname) { return userUserTypeRepository.save(new UserUserType(user, userType, nickname)); } + @Transactional + public void updateNickname(UserUserType userUserType, String nickname) { + userUserType.updateNickname(nickname); + } + @Transactional public void updateCharacter(UserUserType userUserType, ManualCharacterItems items) { if (!isNull(items.set())) { From 740babfbbeb1f5f93a67bf0e085b26b9d613a4da Mon Sep 17 00:00:00 2001 From: lcomment Date: Mon, 21 Aug 2023 23:44:03 +0900 Subject: [PATCH 14/27] =?UTF-8?q?refactor(#48):=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EC=88=98=EC=A0=95=20validation=20check=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/najasin/domain/user/controller/UserController.java | 2 +- .../domain/user/dto/request/NicknameUpdateRequest.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/najasin/domain/user/controller/UserController.java b/src/main/java/com/najasin/domain/user/controller/UserController.java index 75aad49..9d0b165 100644 --- a/src/main/java/com/najasin/domain/user/controller/UserController.java +++ b/src/main/java/com/najasin/domain/user/controller/UserController.java @@ -55,7 +55,7 @@ public ResponseEntity> updateUserType( public ResponseEntity> updateNickname( @AuthorizeUser User user, @PathVariable String userType, - @RequestBody NicknameUpdateRequest request) { + @RequestBody @Validated NicknameUpdateRequest request) { UserUserType userUserType = userUserTypeService.findByUserIdAndUserTypeName(user.getId(), userType); userUserTypeService.updateNickname(userUserType, request.nickname()); diff --git a/src/main/java/com/najasin/domain/user/dto/request/NicknameUpdateRequest.java b/src/main/java/com/najasin/domain/user/dto/request/NicknameUpdateRequest.java index 87a66f7..0d3eadf 100644 --- a/src/main/java/com/najasin/domain/user/dto/request/NicknameUpdateRequest.java +++ b/src/main/java/com/najasin/domain/user/dto/request/NicknameUpdateRequest.java @@ -1,4 +1,6 @@ package com.najasin.domain.user.dto.request; -public record NicknameUpdateRequest(String nickname) { +import jakarta.validation.constraints.NotBlank; + +public record NicknameUpdateRequest(@NotBlank String nickname) { } From d65f8ecd3738cf8373bf34961c1da9fa9603b480 Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 00:55:43 +0900 Subject: [PATCH 15/27] =?UTF-8?q?feature(#48):=20My=20Page=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/najasin/config/SecurityConfig.java | 3 +- .../controller/CharacterController.java | 4 +- .../dto/param/CharacterItemParam.java | 6 ++ .../dto/param/CharacterItemsParam.java | 13 +++++ .../character/dto/response/CharacterItem.java | 6 -- .../dto/response/CharacterItems.java | 13 ----- .../dto/response/CharacterItemsResponse.java | 6 +- .../najasin/domain/character/entity/Body.java | 6 +- .../domain/character/entity/CharacterSet.java | 6 +- .../domain/character/entity/Expression.java | 6 +- .../najasin/domain/character/entity/Face.java | 6 +- .../character/service/CharacterService.java | 16 ++--- .../domain/manual/answer/entity/Answer.java | 26 +++++---- .../answer/repository/AnswerRepository.java | 2 +- .../manual/answer/service/AnswerService.java | 5 ++ .../manual/controller/MyManualController.java | 4 +- .../dto/response/JffMyManualResponse.java | 6 +- .../userKeyword/entity/UserKeyword.java | 58 ++++++++++--------- .../repository/UserKeywordRepository.java | 3 + .../service/UserKeywordService.java | 5 ++ .../user/controller/UserController.java | 13 +++-- .../domain/user/dto/message/UserResponse.java | 2 +- .../domain/user/dto/param/MyAnswerParam.java | 6 ++ .../user/dto/param/MyCharacterItemsParam.java | 14 +++++ .../user/dto/param/MyKeywordPercentParam.java | 6 ++ .../user/dto/response/MyPageResponse.java | 21 +++++++ .../user/entity/userType/UserUserType.java | 13 +++++ .../user/service/UserUserTypeService.java | 33 +++++++++++ 28 files changed, 217 insertions(+), 91 deletions(-) create mode 100644 src/main/java/com/najasin/domain/character/dto/param/CharacterItemParam.java create mode 100644 src/main/java/com/najasin/domain/character/dto/param/CharacterItemsParam.java delete mode 100644 src/main/java/com/najasin/domain/character/dto/response/CharacterItem.java delete mode 100644 src/main/java/com/najasin/domain/character/dto/response/CharacterItems.java create mode 100644 src/main/java/com/najasin/domain/user/dto/param/MyAnswerParam.java create mode 100644 src/main/java/com/najasin/domain/user/dto/param/MyCharacterItemsParam.java create mode 100644 src/main/java/com/najasin/domain/user/dto/param/MyKeywordPercentParam.java create mode 100644 src/main/java/com/najasin/domain/user/dto/response/MyPageResponse.java diff --git a/src/main/java/com/najasin/config/SecurityConfig.java b/src/main/java/com/najasin/config/SecurityConfig.java index 303e6e9..e95e097 100644 --- a/src/main/java/com/najasin/config/SecurityConfig.java +++ b/src/main/java/com/najasin/config/SecurityConfig.java @@ -59,7 +59,8 @@ private Customizer.AuthorizationMa new AntPathRequestMatcher("/swagger-ui/index.html"), new AntPathRequestMatcher("/auth2/**"), new AntPathRequestMatcher("/login/**"), - new AntPathRequestMatcher("/api/*/my-manual", "GET"), + new AntPathRequestMatcher("/api/user/*/mypage", "GET"), + new AntPathRequestMatcher("/api/*/others-manual/**"), new AntPathRequestMatcher("/api/characterItems") ).permitAll() .requestMatchers(new AntPathRequestMatcher("/api/**")).hasAnyRole("ADMIN", "MEMBER") diff --git a/src/main/java/com/najasin/domain/character/controller/CharacterController.java b/src/main/java/com/najasin/domain/character/controller/CharacterController.java index 5bb1824..49cdc47 100644 --- a/src/main/java/com/najasin/domain/character/controller/CharacterController.java +++ b/src/main/java/com/najasin/domain/character/controller/CharacterController.java @@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RestController; import com.najasin.domain.character.dto.message.CharacterItemResponse; -import com.najasin.domain.character.dto.response.CharacterItems; +import com.najasin.domain.character.dto.param.CharacterItemsParam; import com.najasin.domain.character.dto.response.CharacterItemsResponse; import com.najasin.domain.character.service.CharacterService; import com.najasin.global.response.ApiResponse; @@ -27,7 +27,7 @@ public class CharacterController { @GetMapping public ResponseEntity> getCharacterItems() { - CharacterItems characterItems = characterService.findAllItems(); + CharacterItemsParam characterItems = characterService.findAllItems(); return ResponseEntity.ok(createSuccessWithData( CharacterItemResponse.FIND_ALL_ITEMS_SUCCESS.getMsg(), CharacterItemsResponse.of(baseImage, characterItems))); diff --git a/src/main/java/com/najasin/domain/character/dto/param/CharacterItemParam.java b/src/main/java/com/najasin/domain/character/dto/param/CharacterItemParam.java new file mode 100644 index 0000000..b7712bb --- /dev/null +++ b/src/main/java/com/najasin/domain/character/dto/param/CharacterItemParam.java @@ -0,0 +1,6 @@ +package com.najasin.domain.character.dto.param; + +public record CharacterItemParam(Long id, + String showCase, + String layoutCase) { +} diff --git a/src/main/java/com/najasin/domain/character/dto/param/CharacterItemsParam.java b/src/main/java/com/najasin/domain/character/dto/param/CharacterItemsParam.java new file mode 100644 index 0000000..8baf593 --- /dev/null +++ b/src/main/java/com/najasin/domain/character/dto/param/CharacterItemsParam.java @@ -0,0 +1,13 @@ +package com.najasin.domain.character.dto.param; + +import java.util.List; + +import lombok.Builder; + +public record CharacterItemsParam(List face, + List body, + List expression, + List set) { + @Builder + public CharacterItemsParam {} +} diff --git a/src/main/java/com/najasin/domain/character/dto/response/CharacterItem.java b/src/main/java/com/najasin/domain/character/dto/response/CharacterItem.java deleted file mode 100644 index cffb93a..0000000 --- a/src/main/java/com/najasin/domain/character/dto/response/CharacterItem.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.najasin.domain.character.dto.response; - -public record CharacterItem(Long id, - String showCase, - String layoutCase) { -} diff --git a/src/main/java/com/najasin/domain/character/dto/response/CharacterItems.java b/src/main/java/com/najasin/domain/character/dto/response/CharacterItems.java deleted file mode 100644 index 9dd2a63..0000000 --- a/src/main/java/com/najasin/domain/character/dto/response/CharacterItems.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.najasin.domain.character.dto.response; - -import java.util.List; - -import lombok.Builder; - -public record CharacterItems(List face, - List body, - List expression, - List set) { - @Builder - public CharacterItems {} -} diff --git a/src/main/java/com/najasin/domain/character/dto/response/CharacterItemsResponse.java b/src/main/java/com/najasin/domain/character/dto/response/CharacterItemsResponse.java index 591e61b..9f6174e 100644 --- a/src/main/java/com/najasin/domain/character/dto/response/CharacterItemsResponse.java +++ b/src/main/java/com/najasin/domain/character/dto/response/CharacterItemsResponse.java @@ -1,8 +1,10 @@ package com.najasin.domain.character.dto.response; -public record CharacterItemsResponse(String baseImage, CharacterItems characterItems) { +import com.najasin.domain.character.dto.param.CharacterItemsParam; - public static CharacterItemsResponse of(String baseImage, CharacterItems characterItems) { +public record CharacterItemsResponse(String baseImage, CharacterItemsParam characterItems) { + + public static CharacterItemsResponse of(String baseImage, CharacterItemsParam characterItems) { return new CharacterItemsResponse(baseImage, characterItems); } } diff --git a/src/main/java/com/najasin/domain/character/entity/Body.java b/src/main/java/com/najasin/domain/character/entity/Body.java index fab89c5..01b6a4a 100644 --- a/src/main/java/com/najasin/domain/character/entity/Body.java +++ b/src/main/java/com/najasin/domain/character/entity/Body.java @@ -1,6 +1,6 @@ package com.najasin.domain.character.entity; -import com.najasin.domain.character.dto.response.CharacterItem; +import com.najasin.domain.character.dto.param.CharacterItemParam; import jakarta.persistence.*; import lombok.AccessLevel; @@ -27,7 +27,7 @@ public class Body { @Column(name = "body_layout_url",columnDefinition = "TEXT") private String layout_url; - public CharacterItem toCharacterItem() { - return new CharacterItem(id, show_url, layout_url); + public CharacterItemParam toCharacterItem() { + return new CharacterItemParam(id, show_url, layout_url); } } diff --git a/src/main/java/com/najasin/domain/character/entity/CharacterSet.java b/src/main/java/com/najasin/domain/character/entity/CharacterSet.java index 129cd5e..bb2ce8f 100644 --- a/src/main/java/com/najasin/domain/character/entity/CharacterSet.java +++ b/src/main/java/com/najasin/domain/character/entity/CharacterSet.java @@ -1,6 +1,6 @@ package com.najasin.domain.character.entity; -import com.najasin.domain.character.dto.response.CharacterItem; +import com.najasin.domain.character.dto.param.CharacterItemParam; import jakarta.persistence.*; import lombok.AccessLevel; @@ -27,7 +27,7 @@ public class CharacterSet { @Column(name = "set_layout_url",columnDefinition = "TEXT") private String layout_url; - public CharacterItem toCharacterItem() { - return new CharacterItem(id, show_url, layout_url); + public CharacterItemParam toCharacterItem() { + return new CharacterItemParam(id, show_url, layout_url); } } diff --git a/src/main/java/com/najasin/domain/character/entity/Expression.java b/src/main/java/com/najasin/domain/character/entity/Expression.java index a2fddff..eac9fa4 100644 --- a/src/main/java/com/najasin/domain/character/entity/Expression.java +++ b/src/main/java/com/najasin/domain/character/entity/Expression.java @@ -1,6 +1,6 @@ package com.najasin.domain.character.entity; -import com.najasin.domain.character.dto.response.CharacterItem; +import com.najasin.domain.character.dto.param.CharacterItemParam; import jakarta.persistence.*; import lombok.AccessLevel; @@ -27,7 +27,7 @@ public class Expression { @Column(name = "expression_layout_url",columnDefinition = "TEXT") private String layout_url; - public CharacterItem toCharacterItem() { - return new CharacterItem(id, show_url, layout_url); + public CharacterItemParam toCharacterItem() { + return new CharacterItemParam(id, show_url, layout_url); } } diff --git a/src/main/java/com/najasin/domain/character/entity/Face.java b/src/main/java/com/najasin/domain/character/entity/Face.java index 34477cf..0a2af45 100644 --- a/src/main/java/com/najasin/domain/character/entity/Face.java +++ b/src/main/java/com/najasin/domain/character/entity/Face.java @@ -1,6 +1,6 @@ package com.najasin.domain.character.entity; -import com.najasin.domain.character.dto.response.CharacterItem; +import com.najasin.domain.character.dto.param.CharacterItemParam; import jakarta.persistence.*; import lombok.AccessLevel; @@ -27,7 +27,7 @@ public class Face { @Column(name = "face_layout_url",columnDefinition = "TEXT") private String layout_url; - public CharacterItem toCharacterItem() { - return new CharacterItem(id, show_url, layout_url); + public CharacterItemParam toCharacterItem() { + return new CharacterItemParam(id, show_url, layout_url); } } diff --git a/src/main/java/com/najasin/domain/character/service/CharacterService.java b/src/main/java/com/najasin/domain/character/service/CharacterService.java index 44aafa8..27f6384 100644 --- a/src/main/java/com/najasin/domain/character/service/CharacterService.java +++ b/src/main/java/com/najasin/domain/character/service/CharacterService.java @@ -2,8 +2,8 @@ import java.util.List; -import com.najasin.domain.character.dto.response.CharacterItem; -import com.najasin.domain.character.dto.response.CharacterItems; +import com.najasin.domain.character.dto.param.CharacterItemParam; +import com.najasin.domain.character.dto.param.CharacterItemsParam; import com.najasin.domain.character.entity.Body; import com.najasin.domain.character.entity.CharacterSet; import com.najasin.domain.character.repository.BodyRepository; @@ -28,15 +28,15 @@ public class CharacterService { private final CharacterSetRepository characterSetRepository; @Transactional(readOnly = true) - public CharacterItems findAllItems() { - List faceList = findFaceAll().stream().map(Face::toCharacterItem).toList(); - List bodyList = findBodyAll().stream().map(Body::toCharacterItem).toList(); - List expressionList = findExpressionAll().stream().map(Expression::toCharacterItem).toList(); - List characterSetList = findCharacterSetAll().stream() + public CharacterItemsParam findAllItems() { + List faceList = findFaceAll().stream().map(Face::toCharacterItem).toList(); + List bodyList = findBodyAll().stream().map(Body::toCharacterItem).toList(); + List expressionList = findExpressionAll().stream().map(Expression::toCharacterItem).toList(); + List characterSetList = findCharacterSetAll().stream() .map(CharacterSet::toCharacterItem) .toList(); - return CharacterItems.builder() + return CharacterItemsParam.builder() .face(faceList) .body(bodyList) .expression(expressionList) diff --git a/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java b/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java index c2a3912..97c4a3a 100644 --- a/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java +++ b/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java @@ -1,7 +1,9 @@ package com.najasin.domain.manual.answer.entity; import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.user.dto.param.MyAnswerParam; import com.najasin.domain.user.entity.User; + import jakarta.persistence.*; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -14,16 +16,20 @@ @AllArgsConstructor @IdClass(AnswerId.class) public class Answer { - @Id - @ManyToOne - @JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) - private User user; + @Id + @ManyToOne + @JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) + private User user; + + @Id + @ManyToOne + @JoinColumn(name = "question_id", referencedColumnName = "question_id", insertable = false, updatable = false) + private Question question; - @Id - @ManyToOne - @JoinColumn(name = "question_id", referencedColumnName = "question_id", insertable = false, updatable = false) - private Question question; + @Column(name = "answer") + private String answer; - @Column(name = "answer") - private String answer; + public MyAnswerParam toMyAnswerParam() { + return new MyAnswerParam(question.getId(), question.getQuestion(), answer); + } } diff --git a/src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java b/src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java index 6e45f7e..0ab0c78 100644 --- a/src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java +++ b/src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java @@ -8,5 +8,5 @@ public interface AnswerRepository extends JpaRepository { - List findByUser_Id(String userId); + List findByUserId(String userId); } diff --git a/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java b/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java index d47f20e..668cd11 100644 --- a/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java +++ b/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java @@ -34,4 +34,9 @@ public void saveAll(List answers, List questions, User us public Answer save(Answer answer) { return answerRepository.save(answer); } + + @Transactional(readOnly = true) + public List findByUserId(String userId) { + return answerRepository.findByUserId(userId); + } } diff --git a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java index 08714ca..d2767c7 100644 --- a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java +++ b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java @@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.najasin.domain.character.dto.response.CharacterItems; +import com.najasin.domain.character.dto.param.CharacterItemsParam; import com.najasin.domain.character.service.CharacterService; import com.najasin.domain.manual.answer.service.AnswerService; import com.najasin.domain.manual.dto.param.JffMyKeyword; @@ -52,7 +52,7 @@ public class MyManualController { @GetMapping public ResponseEntity> getMyManual(@PathVariable String userType) { - CharacterItems characterItems = characterService.findAllItems(); + CharacterItemsParam characterItems = characterService.findAllItems(); // 추후에 다른 분기에 대한 처리 필요 List questionList = questionService.findAll(userType); diff --git a/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualResponse.java b/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualResponse.java index fdd3af8..ea321b3 100644 --- a/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualResponse.java +++ b/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualResponse.java @@ -2,18 +2,18 @@ import java.util.List; -import com.najasin.domain.character.dto.response.CharacterItems; +import com.najasin.domain.character.dto.param.CharacterItemsParam; import com.najasin.domain.manual.dto.param.JffMyKeyword; import com.najasin.domain.manual.dto.param.JffMyQuestion; public record JffMyManualResponse(String baseImage, - CharacterItems characterItems, + CharacterItemsParam characterItems, List questions, List exampleKeywords) { public static JffMyManualResponse of( String baseImage, - CharacterItems characterItems, + CharacterItemsParam characterItems, List questions, List exampleKeywords) { return new JffMyManualResponse(baseImage, characterItems, questions, exampleKeywords); diff --git a/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java b/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java index 3c3cd49..d09c3db 100644 --- a/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java +++ b/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java @@ -1,7 +1,9 @@ package com.najasin.domain.manual.userKeyword.entity; import com.najasin.domain.manual.keyword.entity.Keyword; +import com.najasin.domain.user.dto.param.MyKeywordPercentParam; import com.najasin.domain.user.entity.User; + import jakarta.persistence.*; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -14,30 +16,34 @@ @AllArgsConstructor @IdClass(UserKeywordId.class) public class UserKeyword { - @Id - @ManyToOne - @JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) - private User user; - - @Id - @ManyToOne - @JoinColumn(name = "keyword_id", referencedColumnName = "keyword_id", insertable = false, updatable = false) - private Keyword keyword; - - @Column - private int originPercent; - - @Column - private int othersPercent; - - @Column - private int othersCount; - - public UserKeyword(User user, Keyword keyword, int originPercent) { - this.user = user; - this.keyword = keyword; - this.originPercent = originPercent; - this.othersPercent = 0; - this.othersCount = 0; - } + @Id + @ManyToOne + @JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false) + private User user; + + @Id + @ManyToOne + @JoinColumn(name = "keyword_id", referencedColumnName = "keyword_id", insertable = false, updatable = false) + private Keyword keyword; + + @Column + private int originPercent; + + @Column + private int othersPercent; + + @Column + private int othersCount; + + public UserKeyword(User user, Keyword keyword, int originPercent) { + this.user = user; + this.keyword = keyword; + this.originPercent = originPercent; + this.othersPercent = 0; + this.othersCount = 0; + } + + public MyKeywordPercentParam toMyKeywordPercentParam() { + return new MyKeywordPercentParam(keyword.getId(), keyword.getName(), originPercent); + } } diff --git a/src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java b/src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java index 5184642..557c0ed 100644 --- a/src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java +++ b/src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java @@ -1,8 +1,11 @@ package com.najasin.domain.manual.userKeyword.repository; +import java.util.List; + import com.najasin.domain.manual.userKeyword.entity.UserKeyword; import com.najasin.domain.manual.userKeyword.entity.UserKeywordId; import org.springframework.data.jpa.repository.JpaRepository; public interface UserKeywordRepository extends JpaRepository { + List findByUserId(String userId); } diff --git a/src/main/java/com/najasin/domain/manual/userKeyword/service/UserKeywordService.java b/src/main/java/com/najasin/domain/manual/userKeyword/service/UserKeywordService.java index 3d5b80d..065c80c 100644 --- a/src/main/java/com/najasin/domain/manual/userKeyword/service/UserKeywordService.java +++ b/src/main/java/com/najasin/domain/manual/userKeyword/service/UserKeywordService.java @@ -33,4 +33,9 @@ public void saveAll(List keywordPercents, List key public UserKeyword save(UserKeyword userKeyword) { return userKeywordRepository.save(userKeyword); } + + @Transactional(readOnly = true) + public List findByUserId(String userId) { + return userKeywordRepository.findByUserId(userId); + } } diff --git a/src/main/java/com/najasin/domain/user/controller/UserController.java b/src/main/java/com/najasin/domain/user/controller/UserController.java index 9d0b165..2cf9ff5 100644 --- a/src/main/java/com/najasin/domain/user/controller/UserController.java +++ b/src/main/java/com/najasin/domain/user/controller/UserController.java @@ -3,6 +3,7 @@ import static com.najasin.domain.user.dto.message.UserResponse.*; import static com.najasin.global.response.ApiResponse.*; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -15,6 +16,7 @@ import com.najasin.domain.user.dto.request.CharacterUpdateRequest; import com.najasin.domain.user.dto.request.NicknameUpdateRequest; +import com.najasin.domain.user.dto.response.MyPageResponse; import com.najasin.domain.user.dto.response.UserTypeUpdateResponse; import com.najasin.domain.user.entity.User; import com.najasin.domain.user.dto.message.UserTypeMessage; @@ -31,13 +33,17 @@ @RequiredArgsConstructor public class UserController { private final UserUserTypeService userUserTypeService; + @Value("${base-image}") + private String baseImage; - @GetMapping("/{userType}/mypage") - public ResponseEntity> getMyPage( + @GetMapping("/user/{userType}/mypage") + public ResponseEntity> getMyPage( @AuthorizeUser User user, @PathVariable String userType, @RequestParam(name = "userId") String userId) { - return null; + MyPageResponse response = userUserTypeService.getMyPage(user, userType, userId); + + return ResponseEntity.ok(createSuccessWithData(SUCCESS_GET_MY_PAGE.getMessage(), response)); } @PutMapping("/type") @@ -62,7 +68,6 @@ public ResponseEntity> updateNickname( return ResponseEntity.ok(createSuccess(SUCCESS_UPDATE_NICKNAME.getMessage())); } - @PutMapping("/{userType}/character") public ResponseEntity> updateCharacter( @AuthorizeUser User user, diff --git a/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java b/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java index 6214771..0736f23 100644 --- a/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java +++ b/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java @@ -9,7 +9,7 @@ public enum UserResponse { SUCCESS_LOGOUT("로그아웃에 성공하셨습니다."), SUCCESS_UPDATE_NICKNAME("닉네임 수정에 성공하였습니다."), SUCCESS_UPDATE_CHARACTER("캐릭터 수정에 성공하였습니다."), - SUCCESS_GET_PAGE("페이지 로딩에 성공하였습니다."), + SUCCESS_GET_MY_PAGE("마이 페이지 조회에 성공하였습니다."), ; private final String message; } diff --git a/src/main/java/com/najasin/domain/user/dto/param/MyAnswerParam.java b/src/main/java/com/najasin/domain/user/dto/param/MyAnswerParam.java new file mode 100644 index 0000000..5e6474f --- /dev/null +++ b/src/main/java/com/najasin/domain/user/dto/param/MyAnswerParam.java @@ -0,0 +1,6 @@ +package com.najasin.domain.user.dto.param; + +public record MyAnswerParam(Long id, + String question, + String answer) { +} diff --git a/src/main/java/com/najasin/domain/user/dto/param/MyCharacterItemsParam.java b/src/main/java/com/najasin/domain/user/dto/param/MyCharacterItemsParam.java new file mode 100644 index 0000000..112c807 --- /dev/null +++ b/src/main/java/com/najasin/domain/user/dto/param/MyCharacterItemsParam.java @@ -0,0 +1,14 @@ +package com.najasin.domain.user.dto.param; + +import com.najasin.domain.character.dto.param.CharacterItemParam; + +import lombok.Builder; + +public record MyCharacterItemsParam(CharacterItemParam face, + CharacterItemParam body, + CharacterItemParam expression, + CharacterItemParam set) { + @Builder + public MyCharacterItemsParam { + } +} diff --git a/src/main/java/com/najasin/domain/user/dto/param/MyKeywordPercentParam.java b/src/main/java/com/najasin/domain/user/dto/param/MyKeywordPercentParam.java new file mode 100644 index 0000000..193f845 --- /dev/null +++ b/src/main/java/com/najasin/domain/user/dto/param/MyKeywordPercentParam.java @@ -0,0 +1,6 @@ +package com.najasin.domain.user.dto.param; + +public record MyKeywordPercentParam(Long id, + String keyword, + Integer percent) { +} diff --git a/src/main/java/com/najasin/domain/user/dto/response/MyPageResponse.java b/src/main/java/com/najasin/domain/user/dto/response/MyPageResponse.java new file mode 100644 index 0000000..c169a7d --- /dev/null +++ b/src/main/java/com/najasin/domain/user/dto/response/MyPageResponse.java @@ -0,0 +1,21 @@ +package com.najasin.domain.user.dto.response; + +import java.util.List; + +import com.najasin.domain.user.dto.param.MyAnswerParam; +import com.najasin.domain.user.dto.param.MyCharacterItemsParam; +import com.najasin.domain.user.dto.param.MyKeywordPercentParam; + +import lombok.Builder; + +public record MyPageResponse(List userTypes, + String nickname, + String baseImage, + MyCharacterItemsParam characterItems, + List myManualQAPair, + List originKeywordPercents) { + + @Builder + public MyPageResponse { + } +} diff --git a/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java b/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java index ecbce13..338db68 100644 --- a/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java +++ b/src/main/java/com/najasin/domain/user/entity/userType/UserUserType.java @@ -1,9 +1,13 @@ package com.najasin.domain.user.entity.userType; +import static java.util.Objects.*; + +import com.najasin.domain.character.dto.param.CharacterItemsParam; import com.najasin.domain.character.entity.Body; import com.najasin.domain.character.entity.CharacterSet; import com.najasin.domain.character.entity.Expression; import com.najasin.domain.character.entity.Face; +import com.najasin.domain.user.dto.param.MyCharacterItemsParam; import com.najasin.domain.user.entity.User; import jakarta.persistence.*; @@ -72,4 +76,13 @@ public void updateCharacter(Face face, Body body, Expression expression) { this.set = null; } + + public MyCharacterItemsParam toMyCharacterItemsParam() { + return MyCharacterItemsParam.builder() + .face(isNull(face) ? null : face.toCharacterItem()) + .body(isNull(body) ? null : body.toCharacterItem()) + .expression(isNull(expression) ? null : expression.toCharacterItem()) + .set(isNull(set) ? null : set.toCharacterItem()) + .build(); + } } diff --git a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java index 2f7048b..3300c2d 100644 --- a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java +++ b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java @@ -7,7 +7,14 @@ import com.najasin.domain.character.repository.ExpressionRepository; import com.najasin.domain.character.repository.FaceRepository; import com.najasin.domain.character.service.CharacterService; +import com.najasin.domain.manual.answer.entity.Answer; +import com.najasin.domain.manual.answer.service.AnswerService; import com.najasin.domain.manual.dto.param.ManualCharacterItems; +import com.najasin.domain.manual.userKeyword.entity.UserKeyword; +import com.najasin.domain.manual.userKeyword.service.UserKeywordService; +import com.najasin.domain.user.dto.param.MyAnswerParam; +import com.najasin.domain.user.dto.param.MyKeywordPercentParam; +import com.najasin.domain.user.dto.response.MyPageResponse; import com.najasin.domain.user.dto.response.UserTypeUpdateResponse; import com.najasin.domain.user.entity.User; import com.najasin.domain.user.repository.UserRepository; @@ -19,6 +26,7 @@ import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.parameters.P; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -31,6 +39,10 @@ public class UserUserTypeService { private final UserUserTypeRepository userUserTypeRepository; private final UserTypeService userTypeService; private final CharacterService characterService; + private final AnswerService answerService; + private final UserKeywordService userKeywordService; + @Value("${base-image}") + private String baseImage; @Transactional public UserTypeUpdateResponse updateUserType(User user, String userTypeName) { @@ -68,6 +80,27 @@ public void updateCharacter(UserUserType userUserType, ManualCharacterItems item } } + @Transactional(readOnly = true) + public MyPageResponse getMyPage(User user, String userType, String userId) { + List userTypes = + isNull(user) ? null : user.getUserUserTypes().stream().map(UserUserType::getUserType).toList(); + UserUserType userUserType = findByUserIdAndUserTypeName(userId, userType); + List answers = answerService.findByUserId(userId).stream().map(Answer::toMyAnswerParam).toList(); + List percents = userKeywordService.findByUserId(userId) + .stream() + .map(UserKeyword::toMyKeywordPercentParam) + .toList(); + + return MyPageResponse.builder() + .userTypes(isNull(userTypes) ? null : userTypes.stream().map(UserType::getName).toList()) + .nickname(userUserType.getNickname()) + .baseImage(baseImage) + .characterItems(userUserType.toMyCharacterItemsParam()) + .myManualQAPair(answers) + .originKeywordPercents(percents) + .build(); + } + @Transactional(readOnly = true) public UserUserType findByUserIdAndUserTypeName(String userId, String userTypeName) { return userUserTypeRepository.findByUserIdAndUserTypeName(userId, userTypeName) From 242a47959c3a074cb711bfc40c792196a3e4f63a Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 01:42:52 +0900 Subject: [PATCH 16/27] =?UTF-8?q?feature(#48):=20=EB=82=B4=EC=A0=81?= =?UTF-8?q?=EB=82=98=EC=82=AC=20=EC=88=98=EC=A0=95=20api=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 --- .../domain/manual/answer/entity/Answer.java | 8 +++++++ .../manual/answer/service/AnswerService.java | 21 +++++++++++++++++-- .../user/controller/UserController.java | 13 ++++++++++++ .../domain/user/dto/message/UserResponse.java | 4 ++-- .../user/dto/param/AnswerUpdateParam.java | 5 +++++ .../user/dto/request/AnswerUpdateRequest.java | 8 +++++++ .../domain/user/service/UserService.java | 15 ------------- .../user/service/UserUserTypeService.java | 12 ++++------- 8 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/najasin/domain/user/dto/param/AnswerUpdateParam.java create mode 100644 src/main/java/com/najasin/domain/user/dto/request/AnswerUpdateRequest.java diff --git a/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java b/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java index 97c4a3a..300f688 100644 --- a/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java +++ b/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java @@ -29,6 +29,14 @@ public class Answer { @Column(name = "answer") private String answer; + public Long getQuestionId() { + return question.getId(); + } + + public void updateAnswer(String answer) { + this.answer = answer; + } + public MyAnswerParam toMyAnswerParam() { return new MyAnswerParam(question.getId(), question.getQuestion(), answer); } diff --git a/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java b/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java index 668cd11..3f61afb 100644 --- a/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java +++ b/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java @@ -11,6 +11,7 @@ import com.najasin.domain.manual.answer.repository.AnswerRepository; import com.najasin.domain.manual.dto.param.JffMyAnswer; import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.user.dto.param.AnswerUpdateParam; import com.najasin.domain.user.entity.User; import lombok.RequiredArgsConstructor; @@ -35,8 +36,24 @@ public Answer save(Answer answer) { return answerRepository.save(answer); } + @Transactional + public void updateAnswer(List updateAnswers, String userId, String userType) { + List answers = findByUserIdAndUserType(userId, userType); + + answers.sort(Comparator.comparing(Answer::getQuestionId)); + updateAnswers.sort(Comparator.comparing(AnswerUpdateParam::id)); + + for(int i=0 ; i findByUserId(String userId) { - return answerRepository.findByUserId(userId); + public List findByUserIdAndUserType(String userId, String userType) { + List answers = answerRepository.findByUserId(userId); + + return answers.stream() + .filter((answer -> answer.getQuestion().getQuestion().equals(userType.toUpperCase()))) + .toList(); } } diff --git a/src/main/java/com/najasin/domain/user/controller/UserController.java b/src/main/java/com/najasin/domain/user/controller/UserController.java index 2cf9ff5..8ff2ff2 100644 --- a/src/main/java/com/najasin/domain/user/controller/UserController.java +++ b/src/main/java/com/najasin/domain/user/controller/UserController.java @@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.najasin.domain.manual.answer.service.AnswerService; +import com.najasin.domain.user.dto.request.AnswerUpdateRequest; import com.najasin.domain.user.dto.request.CharacterUpdateRequest; import com.najasin.domain.user.dto.request.NicknameUpdateRequest; import com.najasin.domain.user.dto.response.MyPageResponse; @@ -33,6 +35,7 @@ @RequiredArgsConstructor public class UserController { private final UserUserTypeService userUserTypeService; + private final AnswerService answerService; @Value("${base-image}") private String baseImage; @@ -78,4 +81,14 @@ public ResponseEntity> updateCharacter( return ResponseEntity.ok(createSuccess(SUCCESS_UPDATE_CHARACTER.getMessage())); } + + @PutMapping("/{userType}/answer") + public ResponseEntity> updateAnswer( + @AuthorizeUser User user, + @PathVariable String userType, + @RequestBody AnswerUpdateRequest request) { + answerService.updateAnswer(request.answer(), user.getId(), userType); + + return ResponseEntity.ok(createSuccess(SUCCESS_UPDATE_ANSWER.getMessage())); + } } diff --git a/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java b/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java index 0736f23..c33cb20 100644 --- a/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java +++ b/src/main/java/com/najasin/domain/user/dto/message/UserResponse.java @@ -9,7 +9,7 @@ public enum UserResponse { SUCCESS_LOGOUT("로그아웃에 성공하셨습니다."), SUCCESS_UPDATE_NICKNAME("닉네임 수정에 성공하였습니다."), SUCCESS_UPDATE_CHARACTER("캐릭터 수정에 성공하였습니다."), - SUCCESS_GET_MY_PAGE("마이 페이지 조회에 성공하였습니다."), - ; + SUCCESS_UPDATE_ANSWER("답변 수정에 성공하였습니다."), + SUCCESS_GET_MY_PAGE("마이 페이지 조회에 성공하였습니다."); private final String message; } diff --git a/src/main/java/com/najasin/domain/user/dto/param/AnswerUpdateParam.java b/src/main/java/com/najasin/domain/user/dto/param/AnswerUpdateParam.java new file mode 100644 index 0000000..9e3c922 --- /dev/null +++ b/src/main/java/com/najasin/domain/user/dto/param/AnswerUpdateParam.java @@ -0,0 +1,5 @@ +package com.najasin.domain.user.dto.param; + +public record AnswerUpdateParam(Long id, + String answer) { +} diff --git a/src/main/java/com/najasin/domain/user/dto/request/AnswerUpdateRequest.java b/src/main/java/com/najasin/domain/user/dto/request/AnswerUpdateRequest.java new file mode 100644 index 0000000..5813870 --- /dev/null +++ b/src/main/java/com/najasin/domain/user/dto/request/AnswerUpdateRequest.java @@ -0,0 +1,8 @@ +package com.najasin.domain.user.dto.request; + +import java.util.List; + +import com.najasin.domain.user.dto.param.AnswerUpdateParam; + +public record AnswerUpdateRequest(List answer) { +} diff --git a/src/main/java/com/najasin/domain/user/service/UserService.java b/src/main/java/com/najasin/domain/user/service/UserService.java index 462ca87..723eb8f 100644 --- a/src/main/java/com/najasin/domain/user/service/UserService.java +++ b/src/main/java/com/najasin/domain/user/service/UserService.java @@ -1,18 +1,10 @@ package com.najasin.domain.user.service; -import static java.util.Objects.*; - import java.util.UUID; -import com.najasin.domain.character.repository.BodyRepository; -import com.najasin.domain.character.repository.CharacterSetRepository; -import com.najasin.domain.character.repository.ExpressionRepository; -import com.najasin.domain.character.repository.FaceRepository; - import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.najasin.domain.character.service.CharacterService; import com.najasin.domain.user.entity.Oauth2Entity; import com.najasin.domain.user.entity.User; import com.najasin.domain.user.repository.UserRepository; @@ -50,13 +42,6 @@ public void logout(String accessToken, String refreshToken) { redisBlackListUtil.setBlackList(refreshToken, "refreshToken", 7); } - @Transactional - public User updateNickname(String id, String nickname) { - User user = this.findById(id); - user.updateNickname(nickname); - return user; - } - public String generateUUID() { String uuid = UUID.randomUUID().toString(); diff --git a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java index 3300c2d..bf173a2 100644 --- a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java +++ b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java @@ -2,10 +2,6 @@ import static java.util.Objects.*; -import com.najasin.domain.character.repository.BodyRepository; -import com.najasin.domain.character.repository.CharacterSetRepository; -import com.najasin.domain.character.repository.ExpressionRepository; -import com.najasin.domain.character.repository.FaceRepository; import com.najasin.domain.character.service.CharacterService; import com.najasin.domain.manual.answer.entity.Answer; import com.najasin.domain.manual.answer.service.AnswerService; @@ -17,9 +13,7 @@ import com.najasin.domain.user.dto.response.MyPageResponse; import com.najasin.domain.user.dto.response.UserTypeUpdateResponse; import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.repository.UserRepository; import com.najasin.domain.user.entity.userType.UserType; -import com.najasin.domain.user.repository.UserTypeRepository; import com.najasin.domain.user.entity.userType.UserUserType; import com.najasin.domain.user.repository.UserUserTypeRepository; @@ -27,7 +21,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; -import org.springframework.security.core.parameters.P; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -85,7 +78,10 @@ public MyPageResponse getMyPage(User user, String userType, String userId) { List userTypes = isNull(user) ? null : user.getUserUserTypes().stream().map(UserUserType::getUserType).toList(); UserUserType userUserType = findByUserIdAndUserTypeName(userId, userType); - List answers = answerService.findByUserId(userId).stream().map(Answer::toMyAnswerParam).toList(); + List answers = answerService.findByUserIdAndUserType(userId, userType) + .stream() + .map(Answer::toMyAnswerParam) + .toList(); List percents = userKeywordService.findByUserId(userId) .stream() .map(UserKeyword::toMyKeywordPercentParam) From bc7c2e7859201fb1cf395393b874c6c7ddf70506 Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 01:46:56 +0900 Subject: [PATCH 17/27] =?UTF-8?q?fix(#48):=20My=20Page=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=97=90=20isOwner=20flag=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/najasin/domain/user/dto/response/MyPageResponse.java | 3 ++- .../com/najasin/domain/user/service/UserUserTypeService.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/najasin/domain/user/dto/response/MyPageResponse.java b/src/main/java/com/najasin/domain/user/dto/response/MyPageResponse.java index c169a7d..d46e414 100644 --- a/src/main/java/com/najasin/domain/user/dto/response/MyPageResponse.java +++ b/src/main/java/com/najasin/domain/user/dto/response/MyPageResponse.java @@ -13,7 +13,8 @@ public record MyPageResponse(List userTypes, String baseImage, MyCharacterItemsParam characterItems, List myManualQAPair, - List originKeywordPercents) { + List originKeywordPercents, + Boolean isOwner) { @Builder public MyPageResponse { diff --git a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java index bf173a2..df40322 100644 --- a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java +++ b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java @@ -94,6 +94,7 @@ public MyPageResponse getMyPage(User user, String userType, String userId) { .characterItems(userUserType.toMyCharacterItemsParam()) .myManualQAPair(answers) .originKeywordPercents(percents) + .isOwner(!isNull(user)) .build(); } From 35877008711f4e65d0d16d74dfab1e1a448f0226 Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 02:38:35 +0900 Subject: [PATCH 18/27] =?UTF-8?q?refactor(#48):=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=A0=95=EB=A6=AC=EC=97=90=20=EC=9D=98=ED=95=9C=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manual/controller/MyManualController.java | 12 ++--- .../domain/manual/dto/param/JffMyAnswer.java | 4 +- .../manual/dto/param/JffMyKeywordPercent.java | 4 +- .../entity => entity/answer}/Answer.java | 4 +- .../entity => entity/answer}/AnswerId.java | 4 +- .../entity/comment}/Comment.java | 4 +- .../entity/comment}/CommentId.java | 4 +- .../entity => entity/keyword}/Keyword.java | 2 +- .../entity => entity/question}/Question.java | 2 +- .../question}/QuestionType.java | 2 +- .../userKeyword}/UserKeyword.java | 4 +- .../userKeyword}/UserKeywordId.java | 4 +- .../repository/AnswerRepository.java | 6 +-- .../repository/CommentRepository.java | 6 +-- .../repository/KeywordRepository.java | 4 +- .../repository/QuestionRepository.java | 6 +-- .../repository/UserKeywordRepository.java | 6 +-- .../{answer => }/service/AnswerService.java | 9 ++-- .../{keyword => }/service/KeywordService.java | 6 +-- .../service/QuestionService.java | 8 ++-- .../service/UserKeywordService.java | 8 ++-- .../user/controller/UserController.java | 2 +- .../com/najasin/domain/user/entity/User.java | 48 ------------------- .../user/service/UserUserTypeService.java | 8 ++-- 24 files changed, 59 insertions(+), 108 deletions(-) rename src/main/java/com/najasin/domain/manual/{answer/entity => entity/answer}/Answer.java (90%) rename src/main/java/com/najasin/domain/manual/{answer/entity => entity/answer}/AnswerId.java (78%) rename src/main/java/com/najasin/domain/{comment/entity => manual/entity/comment}/Comment.java (90%) rename src/main/java/com/najasin/domain/{comment/entity => manual/entity/comment}/CommentId.java (78%) rename src/main/java/com/najasin/domain/manual/{keyword/entity => entity/keyword}/Keyword.java (91%) rename src/main/java/com/najasin/domain/manual/{question/entity => entity/question}/Question.java (94%) rename src/main/java/com/najasin/domain/manual/{question/entity => entity/question}/QuestionType.java (53%) rename src/main/java/com/najasin/domain/manual/{userKeyword/entity => entity/userKeyword}/UserKeyword.java (91%) rename src/main/java/com/najasin/domain/manual/{userKeyword/entity => entity/userKeyword}/UserKeywordId.java (72%) rename src/main/java/com/najasin/domain/manual/{answer => }/repository/AnswerRepository.java (56%) rename src/main/java/com/najasin/domain/{comment => manual}/repository/CommentRepository.java (61%) rename src/main/java/com/najasin/domain/manual/{keyword => }/repository/KeywordRepository.java (62%) rename src/main/java/com/najasin/domain/manual/{question => }/repository/QuestionRepository.java (60%) rename src/main/java/com/najasin/domain/manual/{userKeyword => }/repository/UserKeywordRepository.java (55%) rename src/main/java/com/najasin/domain/manual/{answer => }/service/AnswerService.java (86%) rename src/main/java/com/najasin/domain/manual/{keyword => }/service/KeywordService.java (83%) rename src/main/java/com/najasin/domain/manual/{question => }/service/QuestionService.java (80%) rename src/main/java/com/najasin/domain/manual/{userKeyword => }/service/UserKeywordService.java (81%) diff --git a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java index d2767c7..a3e2dd7 100644 --- a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java +++ b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java @@ -17,17 +17,17 @@ import com.najasin.domain.character.dto.param.CharacterItemsParam; import com.najasin.domain.character.service.CharacterService; -import com.najasin.domain.manual.answer.service.AnswerService; +import com.najasin.domain.manual.service.AnswerService; import com.najasin.domain.manual.dto.param.JffMyKeyword; import com.najasin.domain.manual.dto.request.MyManualCreateRequest; import com.najasin.domain.manual.dto.response.JffMyManualCreateResponse; import com.najasin.domain.manual.dto.response.JffMyManualResponse; import com.najasin.domain.manual.dto.param.JffMyQuestion; -import com.najasin.domain.manual.keyword.entity.Keyword; -import com.najasin.domain.manual.keyword.service.KeywordService; -import com.najasin.domain.manual.question.entity.Question; -import com.najasin.domain.manual.question.service.QuestionService; -import com.najasin.domain.manual.userKeyword.service.UserKeywordService; +import com.najasin.domain.manual.entity.keyword.Keyword; +import com.najasin.domain.manual.service.KeywordService; +import com.najasin.domain.manual.entity.question.Question; +import com.najasin.domain.manual.service.QuestionService; +import com.najasin.domain.manual.service.UserKeywordService; import com.najasin.domain.user.entity.User; import com.najasin.domain.user.entity.userType.UserUserType; import com.najasin.domain.user.service.UserUserTypeService; diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffMyAnswer.java b/src/main/java/com/najasin/domain/manual/dto/param/JffMyAnswer.java index c90e9e1..1047926 100644 --- a/src/main/java/com/najasin/domain/manual/dto/param/JffMyAnswer.java +++ b/src/main/java/com/najasin/domain/manual/dto/param/JffMyAnswer.java @@ -1,7 +1,7 @@ package com.najasin.domain.manual.dto.param; -import com.najasin.domain.manual.answer.entity.Answer; -import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.manual.entity.answer.Answer; +import com.najasin.domain.manual.entity.question.Question; import com.najasin.domain.user.entity.User; public record JffMyAnswer(Long id, diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffMyKeywordPercent.java b/src/main/java/com/najasin/domain/manual/dto/param/JffMyKeywordPercent.java index f974238..0271bf1 100644 --- a/src/main/java/com/najasin/domain/manual/dto/param/JffMyKeywordPercent.java +++ b/src/main/java/com/najasin/domain/manual/dto/param/JffMyKeywordPercent.java @@ -1,7 +1,7 @@ package com.najasin.domain.manual.dto.param; -import com.najasin.domain.manual.keyword.entity.Keyword; -import com.najasin.domain.manual.userKeyword.entity.UserKeyword; +import com.najasin.domain.manual.entity.keyword.Keyword; +import com.najasin.domain.manual.entity.userKeyword.UserKeyword; import com.najasin.domain.user.entity.User; public record JffMyKeywordPercent(Long id, diff --git a/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java b/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java similarity index 90% rename from src/main/java/com/najasin/domain/manual/answer/entity/Answer.java rename to src/main/java/com/najasin/domain/manual/entity/answer/Answer.java index 300f688..7eefdcd 100644 --- a/src/main/java/com/najasin/domain/manual/answer/entity/Answer.java +++ b/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java @@ -1,6 +1,6 @@ -package com.najasin.domain.manual.answer.entity; +package com.najasin.domain.manual.entity.answer; -import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.manual.entity.question.Question; import com.najasin.domain.user.dto.param.MyAnswerParam; import com.najasin.domain.user.entity.User; diff --git a/src/main/java/com/najasin/domain/manual/answer/entity/AnswerId.java b/src/main/java/com/najasin/domain/manual/entity/answer/AnswerId.java similarity index 78% rename from src/main/java/com/najasin/domain/manual/answer/entity/AnswerId.java rename to src/main/java/com/najasin/domain/manual/entity/answer/AnswerId.java index 022bf25..e2e30f0 100644 --- a/src/main/java/com/najasin/domain/manual/answer/entity/AnswerId.java +++ b/src/main/java/com/najasin/domain/manual/entity/answer/AnswerId.java @@ -1,6 +1,6 @@ -package com.najasin.domain.manual.answer.entity; +package com.najasin.domain.manual.entity.answer; -import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.manual.entity.question.Question; import com.najasin.domain.user.entity.User; import jakarta.persistence.Embeddable; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/najasin/domain/comment/entity/Comment.java b/src/main/java/com/najasin/domain/manual/entity/comment/Comment.java similarity index 90% rename from src/main/java/com/najasin/domain/comment/entity/Comment.java rename to src/main/java/com/najasin/domain/manual/entity/comment/Comment.java index fe70e99..d2d4295 100644 --- a/src/main/java/com/najasin/domain/comment/entity/Comment.java +++ b/src/main/java/com/najasin/domain/manual/entity/comment/Comment.java @@ -1,6 +1,6 @@ -package com.najasin.domain.comment.entity; +package com.najasin.domain.manual.entity.comment; -import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.manual.entity.question.Question; import com.najasin.domain.user.entity.User; import com.najasin.global.audit.AuditEntity; import jakarta.persistence.*; diff --git a/src/main/java/com/najasin/domain/comment/entity/CommentId.java b/src/main/java/com/najasin/domain/manual/entity/comment/CommentId.java similarity index 78% rename from src/main/java/com/najasin/domain/comment/entity/CommentId.java rename to src/main/java/com/najasin/domain/manual/entity/comment/CommentId.java index f99b82f..b8f0787 100644 --- a/src/main/java/com/najasin/domain/comment/entity/CommentId.java +++ b/src/main/java/com/najasin/domain/manual/entity/comment/CommentId.java @@ -1,6 +1,6 @@ -package com.najasin.domain.comment.entity; +package com.najasin.domain.manual.entity.comment; -import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.manual.entity.question.Question; import com.najasin.domain.user.entity.User; import jakarta.persistence.Embeddable; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/najasin/domain/manual/keyword/entity/Keyword.java b/src/main/java/com/najasin/domain/manual/entity/keyword/Keyword.java similarity index 91% rename from src/main/java/com/najasin/domain/manual/keyword/entity/Keyword.java rename to src/main/java/com/najasin/domain/manual/entity/keyword/Keyword.java index 3cd3882..9900437 100644 --- a/src/main/java/com/najasin/domain/manual/keyword/entity/Keyword.java +++ b/src/main/java/com/najasin/domain/manual/entity/keyword/Keyword.java @@ -1,4 +1,4 @@ -package com.najasin.domain.manual.keyword.entity; +package com.najasin.domain.manual.entity.keyword; import com.najasin.domain.manual.dto.param.JffMyKeyword; diff --git a/src/main/java/com/najasin/domain/manual/question/entity/Question.java b/src/main/java/com/najasin/domain/manual/entity/question/Question.java similarity index 94% rename from src/main/java/com/najasin/domain/manual/question/entity/Question.java rename to src/main/java/com/najasin/domain/manual/entity/question/Question.java index e6f8c76..be01936 100644 --- a/src/main/java/com/najasin/domain/manual/question/entity/Question.java +++ b/src/main/java/com/najasin/domain/manual/entity/question/Question.java @@ -1,4 +1,4 @@ -package com.najasin.domain.manual.question.entity; +package com.najasin.domain.manual.entity.question; import com.najasin.domain.manual.dto.param.JffMyQuestion; import com.najasin.domain.user.entity.userType.UserType; diff --git a/src/main/java/com/najasin/domain/manual/question/entity/QuestionType.java b/src/main/java/com/najasin/domain/manual/entity/question/QuestionType.java similarity index 53% rename from src/main/java/com/najasin/domain/manual/question/entity/QuestionType.java rename to src/main/java/com/najasin/domain/manual/entity/question/QuestionType.java index 26fafc8..4a885c5 100644 --- a/src/main/java/com/najasin/domain/manual/question/entity/QuestionType.java +++ b/src/main/java/com/najasin/domain/manual/entity/question/QuestionType.java @@ -1,4 +1,4 @@ -package com.najasin.domain.manual.question.entity; +package com.najasin.domain.manual.entity.question; public enum QuestionType { FOR_USER, diff --git a/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java b/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java similarity index 91% rename from src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java rename to src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java index d09c3db..23cdb1f 100644 --- a/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeyword.java +++ b/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java @@ -1,6 +1,6 @@ -package com.najasin.domain.manual.userKeyword.entity; +package com.najasin.domain.manual.entity.userKeyword; -import com.najasin.domain.manual.keyword.entity.Keyword; +import com.najasin.domain.manual.entity.keyword.Keyword; import com.najasin.domain.user.dto.param.MyKeywordPercentParam; import com.najasin.domain.user.entity.User; diff --git a/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeywordId.java b/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeywordId.java similarity index 72% rename from src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeywordId.java rename to src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeywordId.java index 538b107..4877a4c 100644 --- a/src/main/java/com/najasin/domain/manual/userKeyword/entity/UserKeywordId.java +++ b/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeywordId.java @@ -1,6 +1,6 @@ -package com.najasin.domain.manual.userKeyword.entity; +package com.najasin.domain.manual.entity.userKeyword; -import com.najasin.domain.manual.keyword.entity.Keyword; +import com.najasin.domain.manual.entity.keyword.Keyword; import com.najasin.domain.user.entity.User; import jakarta.persistence.Embeddable; import lombok.Getter; diff --git a/src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java b/src/main/java/com/najasin/domain/manual/repository/AnswerRepository.java similarity index 56% rename from src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java rename to src/main/java/com/najasin/domain/manual/repository/AnswerRepository.java index 0ab0c78..7f41108 100644 --- a/src/main/java/com/najasin/domain/manual/answer/repository/AnswerRepository.java +++ b/src/main/java/com/najasin/domain/manual/repository/AnswerRepository.java @@ -1,7 +1,7 @@ -package com.najasin.domain.manual.answer.repository; +package com.najasin.domain.manual.repository; -import com.najasin.domain.manual.answer.entity.Answer; -import com.najasin.domain.manual.answer.entity.AnswerId; +import com.najasin.domain.manual.entity.answer.Answer; +import com.najasin.domain.manual.entity.answer.AnswerId; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; diff --git a/src/main/java/com/najasin/domain/comment/repository/CommentRepository.java b/src/main/java/com/najasin/domain/manual/repository/CommentRepository.java similarity index 61% rename from src/main/java/com/najasin/domain/comment/repository/CommentRepository.java rename to src/main/java/com/najasin/domain/manual/repository/CommentRepository.java index 3196f95..62f4963 100644 --- a/src/main/java/com/najasin/domain/comment/repository/CommentRepository.java +++ b/src/main/java/com/najasin/domain/manual/repository/CommentRepository.java @@ -1,7 +1,7 @@ -package com.najasin.domain.comment.repository; +package com.najasin.domain.manual.repository; -import com.najasin.domain.comment.entity.Comment; -import com.najasin.domain.comment.entity.CommentId; +import com.najasin.domain.manual.entity.comment.Comment; +import com.najasin.domain.manual.entity.comment.CommentId; import com.najasin.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/najasin/domain/manual/keyword/repository/KeywordRepository.java b/src/main/java/com/najasin/domain/manual/repository/KeywordRepository.java similarity index 62% rename from src/main/java/com/najasin/domain/manual/keyword/repository/KeywordRepository.java rename to src/main/java/com/najasin/domain/manual/repository/KeywordRepository.java index 2d36093..b74d824 100644 --- a/src/main/java/com/najasin/domain/manual/keyword/repository/KeywordRepository.java +++ b/src/main/java/com/najasin/domain/manual/repository/KeywordRepository.java @@ -1,6 +1,6 @@ -package com.najasin.domain.manual.keyword.repository; +package com.najasin.domain.manual.repository; -import com.najasin.domain.manual.keyword.entity.Keyword; +import com.najasin.domain.manual.entity.keyword.Keyword; import org.springframework.data.jpa.repository.JpaRepository; public interface KeywordRepository extends JpaRepository { diff --git a/src/main/java/com/najasin/domain/manual/question/repository/QuestionRepository.java b/src/main/java/com/najasin/domain/manual/repository/QuestionRepository.java similarity index 60% rename from src/main/java/com/najasin/domain/manual/question/repository/QuestionRepository.java rename to src/main/java/com/najasin/domain/manual/repository/QuestionRepository.java index 6204241..5a396d6 100644 --- a/src/main/java/com/najasin/domain/manual/question/repository/QuestionRepository.java +++ b/src/main/java/com/najasin/domain/manual/repository/QuestionRepository.java @@ -1,7 +1,7 @@ -package com.najasin.domain.manual.question.repository; +package com.najasin.domain.manual.repository; -import com.najasin.domain.manual.question.entity.Question; -import com.najasin.domain.manual.question.entity.QuestionType; +import com.najasin.domain.manual.entity.question.Question; +import com.najasin.domain.manual.entity.question.QuestionType; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; diff --git a/src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java b/src/main/java/com/najasin/domain/manual/repository/UserKeywordRepository.java similarity index 55% rename from src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java rename to src/main/java/com/najasin/domain/manual/repository/UserKeywordRepository.java index 557c0ed..b7c8980 100644 --- a/src/main/java/com/najasin/domain/manual/userKeyword/repository/UserKeywordRepository.java +++ b/src/main/java/com/najasin/domain/manual/repository/UserKeywordRepository.java @@ -1,9 +1,9 @@ -package com.najasin.domain.manual.userKeyword.repository; +package com.najasin.domain.manual.repository; import java.util.List; -import com.najasin.domain.manual.userKeyword.entity.UserKeyword; -import com.najasin.domain.manual.userKeyword.entity.UserKeywordId; +import com.najasin.domain.manual.entity.userKeyword.UserKeyword; +import com.najasin.domain.manual.entity.userKeyword.UserKeywordId; import org.springframework.data.jpa.repository.JpaRepository; public interface UserKeywordRepository extends JpaRepository { diff --git a/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java b/src/main/java/com/najasin/domain/manual/service/AnswerService.java similarity index 86% rename from src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java rename to src/main/java/com/najasin/domain/manual/service/AnswerService.java index 3f61afb..f50a62e 100644 --- a/src/main/java/com/najasin/domain/manual/answer/service/AnswerService.java +++ b/src/main/java/com/najasin/domain/manual/service/AnswerService.java @@ -1,16 +1,15 @@ -package com.najasin.domain.manual.answer.service; +package com.najasin.domain.manual.service; -import java.util.Collections; import java.util.Comparator; import java.util.List; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.najasin.domain.manual.answer.entity.Answer; -import com.najasin.domain.manual.answer.repository.AnswerRepository; +import com.najasin.domain.manual.entity.answer.Answer; +import com.najasin.domain.manual.repository.AnswerRepository; import com.najasin.domain.manual.dto.param.JffMyAnswer; -import com.najasin.domain.manual.question.entity.Question; +import com.najasin.domain.manual.entity.question.Question; import com.najasin.domain.user.dto.param.AnswerUpdateParam; import com.najasin.domain.user.entity.User; diff --git a/src/main/java/com/najasin/domain/manual/keyword/service/KeywordService.java b/src/main/java/com/najasin/domain/manual/service/KeywordService.java similarity index 83% rename from src/main/java/com/najasin/domain/manual/keyword/service/KeywordService.java rename to src/main/java/com/najasin/domain/manual/service/KeywordService.java index 1298631..e177ba5 100644 --- a/src/main/java/com/najasin/domain/manual/keyword/service/KeywordService.java +++ b/src/main/java/com/najasin/domain/manual/service/KeywordService.java @@ -1,4 +1,4 @@ -package com.najasin.domain.manual.keyword.service; +package com.najasin.domain.manual.service; import java.util.List; @@ -6,8 +6,8 @@ import org.springframework.transaction.annotation.Transactional; import com.najasin.domain.manual.dto.param.JffMyKeyword; -import com.najasin.domain.manual.keyword.entity.Keyword; -import com.najasin.domain.manual.keyword.repository.KeywordRepository; +import com.najasin.domain.manual.entity.keyword.Keyword; +import com.najasin.domain.manual.repository.KeywordRepository; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/najasin/domain/manual/question/service/QuestionService.java b/src/main/java/com/najasin/domain/manual/service/QuestionService.java similarity index 80% rename from src/main/java/com/najasin/domain/manual/question/service/QuestionService.java rename to src/main/java/com/najasin/domain/manual/service/QuestionService.java index 346ba84..918a39a 100644 --- a/src/main/java/com/najasin/domain/manual/question/service/QuestionService.java +++ b/src/main/java/com/najasin/domain/manual/service/QuestionService.java @@ -1,6 +1,6 @@ -package com.najasin.domain.manual.question.service; +package com.najasin.domain.manual.service; -import static com.najasin.domain.manual.question.entity.QuestionType.*; +import static com.najasin.domain.manual.entity.question.QuestionType.*; import java.util.List; @@ -8,8 +8,8 @@ import org.springframework.transaction.annotation.Transactional; import com.najasin.domain.manual.dto.param.JffMyQuestion; -import com.najasin.domain.manual.question.entity.Question; -import com.najasin.domain.manual.question.repository.QuestionRepository; +import com.najasin.domain.manual.entity.question.Question; +import com.najasin.domain.manual.repository.QuestionRepository; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/najasin/domain/manual/userKeyword/service/UserKeywordService.java b/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java similarity index 81% rename from src/main/java/com/najasin/domain/manual/userKeyword/service/UserKeywordService.java rename to src/main/java/com/najasin/domain/manual/service/UserKeywordService.java index 065c80c..bcd9a3e 100644 --- a/src/main/java/com/najasin/domain/manual/userKeyword/service/UserKeywordService.java +++ b/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java @@ -1,4 +1,4 @@ -package com.najasin.domain.manual.userKeyword.service; +package com.najasin.domain.manual.service; import java.util.Comparator; import java.util.List; @@ -7,9 +7,9 @@ import org.springframework.transaction.annotation.Transactional; import com.najasin.domain.manual.dto.param.JffMyKeywordPercent; -import com.najasin.domain.manual.keyword.entity.Keyword; -import com.najasin.domain.manual.userKeyword.entity.UserKeyword; -import com.najasin.domain.manual.userKeyword.repository.UserKeywordRepository; +import com.najasin.domain.manual.entity.keyword.Keyword; +import com.najasin.domain.manual.entity.userKeyword.UserKeyword; +import com.najasin.domain.manual.repository.UserKeywordRepository; import com.najasin.domain.user.entity.User; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/najasin/domain/user/controller/UserController.java b/src/main/java/com/najasin/domain/user/controller/UserController.java index 8ff2ff2..14a3c65 100644 --- a/src/main/java/com/najasin/domain/user/controller/UserController.java +++ b/src/main/java/com/najasin/domain/user/controller/UserController.java @@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.najasin.domain.manual.answer.service.AnswerService; +import com.najasin.domain.manual.service.AnswerService; import com.najasin.domain.user.dto.request.AnswerUpdateRequest; import com.najasin.domain.user.dto.request.CharacterUpdateRequest; import com.najasin.domain.user.dto.request.NicknameUpdateRequest; diff --git a/src/main/java/com/najasin/domain/user/entity/User.java b/src/main/java/com/najasin/domain/user/entity/User.java index 70034ad..88999f9 100644 --- a/src/main/java/com/najasin/domain/user/entity/User.java +++ b/src/main/java/com/najasin/domain/user/entity/User.java @@ -3,14 +3,7 @@ import java.util.ArrayList; import java.util.List; -import com.najasin.domain.character.entity.Body; -import com.najasin.domain.character.entity.CharacterSet; -import com.najasin.domain.character.entity.Expression; -import com.najasin.domain.character.entity.Face; -import com.najasin.domain.manual.answer.entity.Answer; -import com.najasin.domain.comment.entity.Comment; import com.najasin.domain.user.entity.userType.UserType; -import com.najasin.domain.manual.userKeyword.entity.UserKeyword; import com.najasin.domain.user.entity.userType.UserUserType; import jakarta.persistence.*; import lombok.*; @@ -35,25 +28,12 @@ public class User { @Column(name = "user_id") private String id; - @Column(name = "nickname") - private String nickname; - @ElementCollection(fetch = FetchType.EAGER) @Enumerated(EnumType.STRING) @CollectionTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id")) @Column(name = "role") private List role; - - // @OneToMany(mappedBy = "user") - // private List userKeywords; - // - // @OneToMany(mappedBy = "user") - // private List answers; - // - // @OneToMany(mappedBy = "user") - // private List comments; - @OneToMany(mappedBy = "user") private List userUserTypes; @@ -73,9 +53,6 @@ public User(String id, Oauth2Entity oauth2Entity) { this.role = new ArrayList<>(List.of(Role.ROLE_MEMBER)); this.auditEntity = new AuditEntity(); - // userKeywords = new ArrayList<>(); - // answers = new ArrayList<>(); - // comments = new ArrayList<>(); userUserTypes = new ArrayList<>(); } @@ -83,31 +60,6 @@ public void updateLastUserType(UserType lastUserType) { this.lastUserType = lastUserType; } - // public void updateAnswer(List answers) { - // this.answers = answers; - // } - - public void updateNickname(String nickname) { - this.nickname = nickname; - } - - // public void updateUserUserType(UserUserType userUserType) { - // for (UserUserType uut : this.userUserTypes) { - // if (uut.getUserType() == userUserType.getUserType()) { - // this.userUserTypes.remove(uut); - // break; - // } - // } - // this.userUserTypes.add(userUserType); - // } - // - // public void deleteKeywords(){ - // this.userKeywords = new ArrayList<>();} - // - // public void updateKeyword(UserKeyword userKeyword) { - // this.userKeywords.add(userKeyword); - // } - public List getRole() { return role.stream() .map(Role::name) diff --git a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java index df40322..6eeb9bf 100644 --- a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java +++ b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java @@ -3,11 +3,11 @@ import static java.util.Objects.*; import com.najasin.domain.character.service.CharacterService; -import com.najasin.domain.manual.answer.entity.Answer; -import com.najasin.domain.manual.answer.service.AnswerService; +import com.najasin.domain.manual.entity.answer.Answer; +import com.najasin.domain.manual.service.AnswerService; import com.najasin.domain.manual.dto.param.ManualCharacterItems; -import com.najasin.domain.manual.userKeyword.entity.UserKeyword; -import com.najasin.domain.manual.userKeyword.service.UserKeywordService; +import com.najasin.domain.manual.entity.userKeyword.UserKeyword; +import com.najasin.domain.manual.service.UserKeywordService; import com.najasin.domain.user.dto.param.MyAnswerParam; import com.najasin.domain.user.dto.param.MyKeywordPercentParam; import com.najasin.domain.user.dto.response.MyPageResponse; From db2d6c4da3c2d6c96d7fefe0d79b623fe571997a Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 04:29:59 +0900 Subject: [PATCH 19/27] =?UTF-8?q?refactor(#48):=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EB=B6=84=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{JffMyAnswer.java => JffAnswerParam.java} | 0 ...JffMyKeyword.java => JffKeywordParam.java} | 0 ...rcent.java => JffKeywordPercentParam.java} | 0 ...fMyQuestion.java => JffQuestionParam.java} | 0 .../dto/request/MyAnswerCreateRequest.java | 5 - .../dto/request/MyKeywordCreateRequest.java | 4 - .../{MyAnswerParam.java => AnswerParam.java} | 0 ...entParam.java => KeywordPercentParam.java} | 0 .../najasin/service/AnswerServiceTest.java | 143 ----------- .../najasin/service/CharacterServiceTest.java | 83 ------ .../najasin/service/CommentServiceTest.java | 124 --------- .../najasin/service/KeywordServiceTest.java | 49 ---- .../najasin/service/QuestionServiceTest.java | 62 ----- .../service/UserKeywordServiceTest.java | 169 ------------ .../com/najasin/service/UserServiceTest.java | 221 ---------------- .../najasin/service/UserTypeServiceTest.java | 71 ------ .../service/UserUserTypeServiceTest.java | 241 ------------------ 17 files changed, 1172 deletions(-) rename src/main/java/com/najasin/domain/manual/dto/param/{JffMyAnswer.java => JffAnswerParam.java} (100%) rename src/main/java/com/najasin/domain/manual/dto/param/{JffMyKeyword.java => JffKeywordParam.java} (100%) rename src/main/java/com/najasin/domain/manual/dto/param/{JffMyKeywordPercent.java => JffKeywordPercentParam.java} (100%) rename src/main/java/com/najasin/domain/manual/dto/param/{JffMyQuestion.java => JffQuestionParam.java} (100%) delete mode 100644 src/main/java/com/najasin/domain/manual/dto/request/MyAnswerCreateRequest.java delete mode 100644 src/main/java/com/najasin/domain/manual/dto/request/MyKeywordCreateRequest.java rename src/main/java/com/najasin/domain/user/dto/param/{MyAnswerParam.java => AnswerParam.java} (100%) rename src/main/java/com/najasin/domain/user/dto/param/{MyKeywordPercentParam.java => KeywordPercentParam.java} (100%) delete mode 100644 src/test/java/com/najasin/service/AnswerServiceTest.java delete mode 100644 src/test/java/com/najasin/service/CharacterServiceTest.java delete mode 100644 src/test/java/com/najasin/service/CommentServiceTest.java delete mode 100644 src/test/java/com/najasin/service/KeywordServiceTest.java delete mode 100644 src/test/java/com/najasin/service/QuestionServiceTest.java delete mode 100644 src/test/java/com/najasin/service/UserKeywordServiceTest.java delete mode 100644 src/test/java/com/najasin/service/UserServiceTest.java delete mode 100644 src/test/java/com/najasin/service/UserTypeServiceTest.java delete mode 100644 src/test/java/com/najasin/service/UserUserTypeServiceTest.java diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffMyAnswer.java b/src/main/java/com/najasin/domain/manual/dto/param/JffAnswerParam.java similarity index 100% rename from src/main/java/com/najasin/domain/manual/dto/param/JffMyAnswer.java rename to src/main/java/com/najasin/domain/manual/dto/param/JffAnswerParam.java diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffMyKeyword.java b/src/main/java/com/najasin/domain/manual/dto/param/JffKeywordParam.java similarity index 100% rename from src/main/java/com/najasin/domain/manual/dto/param/JffMyKeyword.java rename to src/main/java/com/najasin/domain/manual/dto/param/JffKeywordParam.java diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffMyKeywordPercent.java b/src/main/java/com/najasin/domain/manual/dto/param/JffKeywordPercentParam.java similarity index 100% rename from src/main/java/com/najasin/domain/manual/dto/param/JffMyKeywordPercent.java rename to src/main/java/com/najasin/domain/manual/dto/param/JffKeywordPercentParam.java diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffMyQuestion.java b/src/main/java/com/najasin/domain/manual/dto/param/JffQuestionParam.java similarity index 100% rename from src/main/java/com/najasin/domain/manual/dto/param/JffMyQuestion.java rename to src/main/java/com/najasin/domain/manual/dto/param/JffQuestionParam.java diff --git a/src/main/java/com/najasin/domain/manual/dto/request/MyAnswerCreateRequest.java b/src/main/java/com/najasin/domain/manual/dto/request/MyAnswerCreateRequest.java deleted file mode 100644 index 6b15927..0000000 --- a/src/main/java/com/najasin/domain/manual/dto/request/MyAnswerCreateRequest.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.najasin.domain.manual.dto.request; - -public record MyAnswerCreateRequest(Long id, - String answer) { -} diff --git a/src/main/java/com/najasin/domain/manual/dto/request/MyKeywordCreateRequest.java b/src/main/java/com/najasin/domain/manual/dto/request/MyKeywordCreateRequest.java deleted file mode 100644 index 5479d3a..0000000 --- a/src/main/java/com/najasin/domain/manual/dto/request/MyKeywordCreateRequest.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.najasin.domain.manual.dto.request; - -public record MyKeywordCreateRequest() { -} diff --git a/src/main/java/com/najasin/domain/user/dto/param/MyAnswerParam.java b/src/main/java/com/najasin/domain/user/dto/param/AnswerParam.java similarity index 100% rename from src/main/java/com/najasin/domain/user/dto/param/MyAnswerParam.java rename to src/main/java/com/najasin/domain/user/dto/param/AnswerParam.java diff --git a/src/main/java/com/najasin/domain/user/dto/param/MyKeywordPercentParam.java b/src/main/java/com/najasin/domain/user/dto/param/KeywordPercentParam.java similarity index 100% rename from src/main/java/com/najasin/domain/user/dto/param/MyKeywordPercentParam.java rename to src/main/java/com/najasin/domain/user/dto/param/KeywordPercentParam.java diff --git a/src/test/java/com/najasin/service/AnswerServiceTest.java b/src/test/java/com/najasin/service/AnswerServiceTest.java deleted file mode 100644 index 5133e76..0000000 --- a/src/test/java/com/najasin/service/AnswerServiceTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.najasin.service; - -import com.najasin.domain.answer.entity.Answer; -import com.najasin.domain.answer.repository.AnswerRepository; -import com.najasin.domain.answer.service.AnswerService; -import com.najasin.domain.question.entity.Question; -import com.najasin.domain.question.entity.QuestionType; -import com.najasin.domain.question.repository.QuestionRepository; -import com.najasin.domain.user.dto.PageUpdateRequestDTO; -import com.najasin.domain.user.entity.Oauth2Entity; -import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.entity.enums.Provider; -import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.user.entity.userType.UserType; -import com.najasin.domain.user.repository.UserTypeRepository; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import static org.mockito.Mockito.*; - -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import static junit.framework.TestCase.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; - -@ExtendWith(MockitoExtension.class) -public class AnswerServiceTest { - @InjectMocks - private AnswerService answerService; - - @Mock - private AnswerRepository answerRepository; - @Mock - private UserRepository userRepository; - @Mock - private QuestionRepository questionRepository; - @Mock - private UserTypeRepository userTypeRepository; - - - private String mockUserId; - private Oauth2Entity mockOauth2Entity; - private User mockUser; - - private Long mockQuestionId; - private Question mockQuestion; - private Answer mockAnswer; - private String mockAns; - - - - @BeforeEach - public void setup(){ - mockUserId = "test-uuid"; - mockOauth2Entity = Oauth2Entity.builder() - .provider(Provider.KAKAO) - .providerId("test-provider-id") - .providerUsername("test-provider-nickname") - .email("test@kakao.com") - .build(); - mockUser = new User(mockUserId, mockOauth2Entity); - mockQuestionId = 123456789L; - mockQuestion = new Question(mockQuestionId, "테스트 질문", QuestionType.FOR_USER, new ArrayList<>(), new UserType(1L, "JFF", new ArrayList<>())); - mockAns = "테스트 응답"; - mockAnswer = new Answer(mockUser, mockQuestion, mockAns); - } - - @AfterEach - public void cleanup(){ - userRepository.deleteAll(); - questionRepository.deleteAll(); - answerRepository.deleteAll(); - } - - @Test - @DisplayName("유저가 질문에 답을 한다") - public void save(){ - given(answerRepository.save(any())) - .willReturn(mockAnswer); - given(userRepository.findById(any())) - .willReturn(Optional.of(mockUser)); - given(questionRepository.findById(any())) - .willReturn(Optional.of(mockQuestion)); - Answer saveAnswer = answerService.save(mockUserId, mockQuestionId, mockAns); - assertEquals(saveAnswer, mockAnswer); - } - - - @Test - @DisplayName("해당 유저의 응답 정보를 지운다") - public void deleteAnswers() { - // Given - UserType userTypeToDelete = new UserType(1L, "JFF", null); - - List answersToDelete = new ArrayList<>(); - - for (int i = 1; i <= 3; i++) { - UserType questionUserType = userTypeToDelete; - Question question = new Question(null, null, null, null, questionUserType); - Answer answer = new Answer(mockUser, question, null); - if (questionUserType != userTypeToDelete) { - answersToDelete.add(answer); - } - } - - given(userRepository.findById(anyString())).willReturn(Optional.of(mockUser)); - given(answerRepository.findByUser_Id(anyString())).willReturn(answersToDelete); - given(userTypeRepository.findByName(anyString())).willReturn(Optional.of(userTypeToDelete)); - // When - answerService.deleteAnswers(mockUserId, "JFF"); - - // Then - List remainingAnswers = answersToDelete.stream() - .filter(answer -> answer.getQuestion().getUserType() != userTypeToDelete) - .collect(Collectors.toList()); - assertEquals(remainingAnswers.size(), mockUser.getAnswers().size()); - } - - @Test - @DisplayName("유저의 응답 정보를 업데이트한다") - public void updateAnswers() { - //given - given(userRepository.findById(any())).willReturn(Optional.ofNullable(mockUser)); - given(questionRepository.findById(any())).willReturn(Optional.ofNullable(mockQuestion)); - List dto = new ArrayList<>(); - dto.add(new PageUpdateRequestDTO.AnswerDTO(1L, "응답 1")); - dto.add(new PageUpdateRequestDTO.AnswerDTO(2L, "응답 2")); - //when - answerService.updateAnswers(mockUserId, dto); - //then - assertEquals(mockUser.getAnswers().size(), dto.size()); - } -} diff --git a/src/test/java/com/najasin/service/CharacterServiceTest.java b/src/test/java/com/najasin/service/CharacterServiceTest.java deleted file mode 100644 index 4c27be2..0000000 --- a/src/test/java/com/najasin/service/CharacterServiceTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.najasin.service; - -import com.najasin.domain.character.service.CharacterService; -import com.najasin.domain.character.entity.Body; -import com.najasin.domain.character.repository.BodyRepository; -import com.najasin.domain.character.entity.CharacterSet; -import com.najasin.domain.character.repository.CharacterSetRepository; -import com.najasin.domain.character.dto.AllCharacterItems; -import com.najasin.domain.character.entity.Expression; -import com.najasin.domain.character.repository.ExpressionRepository; -import com.najasin.domain.character.entity.Face; -import com.najasin.domain.character.repository.FaceRepository; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import static org.mockito.Mockito.*; - - -import java.util.ArrayList; -import java.util.List; - -import static junit.framework.TestCase.assertEquals; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -public class CharacterServiceTest { - @InjectMocks - private CharacterService characterService; - @Mock - private FaceRepository faceRepository; - - @Mock - private BodyRepository bodyRepository; - - @Mock - private ExpressionRepository expressionRepository; - - @Mock - private CharacterSetRepository characterSetRepository; - - @Test - public void testGetAllCharacterItems() { - //given - List mockFaces = new ArrayList<>(); - mockFaces.add(new Face(1L, "Face 1 Show URL", "Face 1 Layout URL", "URL")); - mockFaces.add(new Face(2L, "Face 2 Show URL", "Face 2 Layout URL","URL")); - - List mockBodies = new ArrayList<>(); - mockBodies.add(new Body(1L, "Body 1 Show URL", "Body 1 Layout URL","URL")); - mockBodies.add(new Body(2L, "Body 2 Show URL", "Body 2 Layout URL","URL")); - - List mockExpressions = new ArrayList<>(); - mockExpressions.add(new Expression(1L, "Expression 1 Show URL", "Expression 1 Layout URL","URL")); - mockExpressions.add(new Expression(2L, "Expression 2 Show URL", "Expression 2 Layout URL","URL")); - - List mockCharacterSets = new ArrayList<>(); - mockCharacterSets.add(new CharacterSet(1L, "Character Set 1 URL","URL")); - - when(faceRepository.findAll()).thenReturn(mockFaces); - when(bodyRepository.findAll()).thenReturn(mockBodies); - when(expressionRepository.findAll()).thenReturn(mockExpressions); - when(characterSetRepository.findAll()).thenReturn(mockCharacterSets); - - // Call the service method - AllCharacterItems allCharacterItems = characterService.getAllCharacterItems(); - - // Assertions - assertEquals("기본 이미지 url", allCharacterItems.getBaseImage()); - - assertEquals(2, allCharacterItems.getCharacterItems().getFace().size()); - assertEquals(2, allCharacterItems.getCharacterItems().getBody().size()); - assertEquals(2, allCharacterItems.getCharacterItems().getExpression().size()); - assertEquals(1, allCharacterItems.getCharacterItems().getSet().size()); - - // Verify that the methods were called as expected - verify(faceRepository, times(1)).findAll(); - verify(bodyRepository, times(1)).findAll(); - verify(expressionRepository, times(1)).findAll(); - verify(characterSetRepository, times(1)).findAll(); - } -} diff --git a/src/test/java/com/najasin/service/CommentServiceTest.java b/src/test/java/com/najasin/service/CommentServiceTest.java deleted file mode 100644 index d71ff27..0000000 --- a/src/test/java/com/najasin/service/CommentServiceTest.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.najasin.service; - -import com.najasin.domain.comment.entity.Comment; -import com.najasin.domain.comment.repository.CommentRepository; -import com.najasin.domain.comment.service.CommentService; -import com.najasin.domain.question.entity.Question; -import com.najasin.domain.question.entity.QuestionType; -import com.najasin.domain.question.repository.QuestionRepository; -import com.najasin.domain.user.entity.Oauth2Entity; -import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.entity.enums.Provider; -import com.najasin.domain.user.entity.enums.Role; -import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.user.entity.userType.UserType; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import static junit.framework.TestCase.assertEquals; -import static org.hibernate.validator.internal.util.Contracts.assertTrue; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.*; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -@ExtendWith(MockitoExtension.class) -public class CommentServiceTest { - @InjectMocks - private CommentService commentService; - @Mock - private CommentRepository commentRepository; - @Mock - private UserRepository userRepository; - @Mock - private QuestionRepository questionRepository; - private String mockUserId; - private Oauth2Entity mockOauth2Entity; - private User mockUser; - private Question mockQuestion; - private Long mockQuestionId; - private Comment mockComment; - private String mockCommentContent; - private String mockCommentNickname; - - @BeforeEach - public void setup() { - mockUserId = "test-uuid"; - mockOauth2Entity = Oauth2Entity.builder() - .provider(Provider.KAKAO) - .providerId("test-provider-id") - .providerUsername("test-provider-nickname") - .email("test@kakao.com") - .build(); - mockUser = User.builder() - .id(mockUserId) - .role( new ArrayList<>(List.of(Role.ROLE_MEMBER))) - .comments(new ArrayList<>()) - .oauth2Entity(mockOauth2Entity) - .build(); - mockQuestionId = 123456789L; - mockQuestion = new Question(mockQuestionId, "질문", QuestionType.FOR_OTHERS, new ArrayList<>(), new UserType(1L, "JFF", null)); - mockCommentContent = "테스트 코멘트"; - mockCommentNickname = "테스트 닉네임"; - mockComment = Comment.builder() - .user(mockUser) - .question(mockQuestion) - .comment(mockCommentContent) - .nickname(mockCommentNickname) - .build(); - } - - @AfterEach - public void cleanup() { - userRepository.deleteAll(); - questionRepository.deleteAll(); - commentRepository.deleteAll(); - } - - @Test - @DisplayName("타적나사를 저장한다") - public void save() { - //given - given(userRepository.findById(any())) - .willReturn(Optional.of(mockUser)); - given(questionRepository.findById(any())) - .willReturn(Optional.of(mockQuestion)); - given(commentRepository.save(any())) - .willReturn(mockComment); - //when - Comment comment = commentService.save(mockUserId, mockQuestionId, mockCommentNickname, mockCommentContent); - //then - assertEquals(mockComment.getComment(), comment.getComment()); - - verify(userRepository, times(1)).findById(mockUserId); - verify(questionRepository, times(1)).findById(mockQuestionId); - verify(commentRepository, times(1)).save(any(Comment.class)); - } - - @Test - @DisplayName("타적나사를 삭제한다") - public void delete(){ - //given - given(userRepository.findById(any())) - .willReturn(Optional.of(mockUser)); - given(questionRepository.findById(any())) - .willReturn(Optional.of(mockQuestion)); - given(commentRepository.findById(any())) - .willReturn(Optional.of(mockComment)); - mockUser.getComments().add(mockComment); - mockQuestion.getComments().add(mockComment); - //then - assertDoesNotThrow(() -> commentService.delete(mockUserId, mockQuestionId)); - assertEquals(true, mockUser.getComments().isEmpty()); - assertEquals(true, mockQuestion.getComments().isEmpty()); - } -} diff --git a/src/test/java/com/najasin/service/KeywordServiceTest.java b/src/test/java/com/najasin/service/KeywordServiceTest.java deleted file mode 100644 index a2902e9..0000000 --- a/src/test/java/com/najasin/service/KeywordServiceTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.najasin.service; - -import com.najasin.domain.keyword.entity.Keyword; -import com.najasin.domain.keyword.repository.KeywordRepository; -import com.najasin.domain.keyword.service.KeywordService; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; - -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.ArrayList; -import java.util.List; - -import static junit.framework.TestCase.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; - -@ExtendWith(MockitoExtension.class) -public class KeywordServiceTest { - @InjectMocks - private KeywordService keywordService; - - @Mock - private KeywordRepository keywordRepository; - - - @Test - @DisplayName("모든 키워드를 가져온다") - public void getAllKeywords() { - //given - List keywords = new ArrayList<>(); - keywords.add("키워드1"); - keywords.add("키워드2"); - keywords.add("키워드3"); - List keywordList = new ArrayList<>(); - keywordList.add(new Keyword(1L, "키워드1")); - keywordList.add(new Keyword(2L, "키워드2")); - keywordList.add(new Keyword(3L, "키워드3")); - given(keywordRepository.findAll()).willReturn(keywordList); - //when - List getAllKeywords = keywordService.getAllKeywords(); - //then - assertEquals(getAllKeywords, keywords); - } -} diff --git a/src/test/java/com/najasin/service/QuestionServiceTest.java b/src/test/java/com/najasin/service/QuestionServiceTest.java deleted file mode 100644 index 78e3566..0000000 --- a/src/test/java/com/najasin/service/QuestionServiceTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.najasin.service; - -import com.najasin.domain.question.entity.Question; -import com.najasin.domain.question.entity.QuestionType; -import com.najasin.domain.question.repository.QuestionRepository; -import com.najasin.domain.question.service.QuestionService; -import com.najasin.domain.user.dto.Page; -import com.najasin.domain.user.entity.userType.UserType; -import com.najasin.domain.user.repository.UserTypeRepository; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import static org.mockito.Mockito.*; -import static junit.framework.TestCase.*; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -@ExtendWith(MockitoExtension.class) - -public class QuestionServiceTest { - @InjectMocks - private QuestionService questionService; - - @Mock - private QuestionRepository questionRepository; - @Mock - private UserTypeRepository userTypeRepository; - - @Test - @DisplayName("질문 타입과 유저 타입별로 질문을 받아온다") - public void getQuestionByQuestionTypeAndUserType() { - - //given - QuestionType questionType = QuestionType.FOR_USER; - String userTypeName = "JFF"; - UserType userType = new UserType(1L, userTypeName, new ArrayList<>()); - - List mockQuestions = new ArrayList<>(); - mockQuestions.add(new Question(1L, "Question 1", QuestionType.FOR_USER,null, userType)); - mockQuestions.add(new Question(2L, "Question 2", QuestionType.FOR_USER, null, userType)); - - when(userTypeRepository.findByName(userTypeName)).thenReturn(Optional.of(userType)); - when(questionRepository.getQuestionsByQuestionTypeAndUserType(questionType, userType)).thenReturn(mockQuestions); - - //when - List ret = questionService.getQuestionByQuestionTypeAndUserType(questionType, userTypeName); - - //then - assertNotNull(ret); - assertEquals(2, ret.size()); - assertEquals("Question 1", ret.get(0).getQuestion()); - assertEquals("Question 2", ret.get(1).getQuestion()); - - verify(userTypeRepository, times(1)).findByName(userTypeName); - verify(questionRepository, times(1)).getQuestionsByQuestionTypeAndUserType(questionType, userType); - } -} diff --git a/src/test/java/com/najasin/service/UserKeywordServiceTest.java b/src/test/java/com/najasin/service/UserKeywordServiceTest.java deleted file mode 100644 index 99b5556..0000000 --- a/src/test/java/com/najasin/service/UserKeywordServiceTest.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.najasin.service; - -import com.najasin.domain.keyword.entity.Keyword; -import com.najasin.domain.keyword.repository.KeywordRepository; -import com.najasin.domain.user.entity.Oauth2Entity; -import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.entity.enums.Provider; -import com.najasin.domain.user.entity.enums.Role; -import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.userKeyword.entity.UserKeyword; -import com.najasin.domain.userKeyword.repository.UserKeywordRepository; -import com.najasin.domain.userKeyword.service.UserKeywordService; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import static junit.framework.TestCase.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.*; - - -import java.util.*; - -@ExtendWith(MockitoExtension.class) -public class UserKeywordServiceTest { - @InjectMocks - private UserKeywordService userKeywordService; - - @Mock - private UserKeywordRepository userKeywordRepository; - @Mock - private KeywordRepository keywordRepository; - @Mock - private UserRepository userRepository; - - private String mockUserId; - private Oauth2Entity mockOauth2Entity; - private User mockUser; - - private Long mockKeywordId; - private Keyword mockKeyword; - - private UserKeyword prevUserKeyword; - private UserKeyword mockUK; - private int mockPercent; - - @BeforeEach - public void setup() { - mockUserId = "test-uuid"; - mockOauth2Entity = Oauth2Entity.builder() - .provider(Provider.KAKAO) - .providerId("test-provider-id") - .providerUsername("test-provider-nickname") - .email("test@kakao.com") - .build(); - mockKeywordId = 123456789L; - mockKeyword = new Keyword(mockKeywordId, "키워드"); - mockPercent = 50; - mockUK = new UserKeyword(mockUser, mockKeyword, mockPercent); - prevUserKeyword = new UserKeyword(mockUser, mockKeyword, 50, 30, 5); - List list = new ArrayList<>(); - list.add(prevUserKeyword); - mockUser = User.builder() - .id(mockUserId) - .role( new ArrayList<>(List.of(Role.ROLE_MEMBER))) - .userKeywords(list) - .oauth2Entity(mockOauth2Entity) - .build(); - } - - @AfterEach - public void cleanup() { - userRepository.deleteAll(); - userKeywordRepository.deleteAll(); - } - - @Test - @DisplayName("유저가 키워드의 퍼센트를 설정한다") - public void save() { - given(userKeywordRepository.save(any())) - .willReturn(mockUK); - given(userRepository.findById(any())) - .willReturn(Optional.of(mockUser)); - given(keywordRepository.findById(any())) - .willReturn(Optional.of(mockKeyword)); - UserKeyword saveUserKeyword = userKeywordService.save(mockUserId, mockKeywordId, mockPercent); - assertEquals(saveUserKeyword, mockUK); - } - - @Test - @DisplayName("유저의 원래 키워드 퍼센트를 가져온다") - public void getOriginKeywordPercents() { - //given - given(userRepository.findById(any())).willReturn(Optional.of(mockUser)); - //when - Map getPercents = userKeywordService.getOriginKeywordPercents(mockUserId); - //then - for (UserKeyword userKeyword : mockUser.getUserKeywords()) { - String keyword = userKeyword.getKeyword().getName(); - assertEquals(Optional.ofNullable(getPercents.get(keyword)), Optional.ofNullable(userKeyword.getOriginPercent())); - } - } - - @Test - @DisplayName("유저의 합산 키워드 퍼센트를 가져온다") - public void getOtherKeywordPercents() { - //given - given(userRepository.findById(any())).willReturn(Optional.of(mockUser)); - //when - Map othersPercent = userKeywordService.getOtherKeywordPercents(mockUserId); - //then - for (UserKeyword userKeyword : mockUser.getUserKeywords()) { - String keyword = userKeyword.getKeyword().getName(); - assertEquals(Optional.ofNullable(othersPercent.get(keyword)), Optional.ofNullable(Long.valueOf(userKeyword.getOriginPercent()+userKeyword.getOthersPercent())/(userKeyword.getOthersCount()+1))); - } - } - - - @Test - @DisplayName("타인이 유저 키워드 퍼센트 설정에 기여한다") - public void updateByOthers() { - - // Given - String userId = mockUserId; - Long keywordId = mockKeywordId; - int percentToAdd = 10; - - User user = mockUser; - Keyword keyword = mockKeyword; - - - when(userRepository.findById(userId)).thenReturn(Optional.of(user)); - when(userKeywordRepository.save(any(UserKeyword.class))).thenReturn(prevUserKeyword); - - // When - UserKeyword updatedUserKeyword = userKeywordService.updateByOthers(userId, keyword.getName(), percentToAdd); - - // Then -// assertEquals(prevUserKeyword.getOthersPercent() + percentToAdd, updatedUserKeyword.getOthersPercent()); -// assertEquals(prevUserKeyword.getOthersCount() + 1, updatedUserKeyword.getOthersCount()); - - verify(userRepository, times(1)).findById(userId); - verify(userKeywordRepository, times(1)).save(any(UserKeyword.class)); - } - - @Test - @DisplayName("유저가 원래 퍼센트를 수정한다") - public void updateByUser() { - //given - Map dto = new HashMap<>(); - dto.put("키워드", 10); - given(userRepository.findById(mockUserId)).willReturn(Optional.of(mockUser)); - given(keywordRepository.findKeywordByName("키워드")).willReturn(new Keyword(1L, "키워드")); - //when - userKeywordService.updateByUser(mockUserId, dto); - //then - for (UserKeyword userKeyword : mockUser.getUserKeywords()) { - assertEquals(Optional.ofNullable(userKeyword.getOriginPercent()), Optional.ofNullable(dto.get(userKeyword.getKeyword().getName()))); - } - - } -} diff --git a/src/test/java/com/najasin/service/UserServiceTest.java b/src/test/java/com/najasin/service/UserServiceTest.java deleted file mode 100644 index 35c9fb7..0000000 --- a/src/test/java/com/najasin/service/UserServiceTest.java +++ /dev/null @@ -1,221 +0,0 @@ -package com.najasin.service; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.*; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import com.najasin.domain.character.entity.Body; -import com.najasin.domain.character.repository.BodyRepository; -import com.najasin.domain.character.entity.CharacterSet; -import com.najasin.domain.character.repository.CharacterSetRepository; -import com.najasin.domain.keyword.dto.KeywordDTO; -import com.najasin.domain.character.entity.Expression; -import com.najasin.domain.character.repository.ExpressionRepository; -import com.najasin.domain.character.entity.Face; -import com.najasin.domain.character.repository.FaceRepository; -import com.najasin.domain.keyword.entity.Keyword; -import com.najasin.domain.userKeyword.entity.UserKeyword; -import com.najasin.domain.userKeyword.service.UserKeywordService; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.test.util.ReflectionTestUtils; - -import com.najasin.domain.user.entity.Oauth2Entity; -import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.entity.enums.Provider; -import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.user.service.UserService; -import com.najasin.global.util.RedisBlackListUtil; -import com.najasin.security.model.OAuth2Request; - -import jakarta.persistence.EntityNotFoundException; - -@ExtendWith(MockitoExtension.class) -public class UserServiceTest { - - @InjectMocks - private UserService userService; - - @Mock - private UserRepository userRepository; - @Mock - private CharacterSetRepository characterSetRepository; - @Mock - private FaceRepository faceRepository; - @Mock - private BodyRepository bodyRepository; - @Mock - private ExpressionRepository expressionRepository; - @Mock - private UserKeywordService userKeywordService; - - @Mock - private RedisBlackListUtil redisBlackListUtil; - - private String mockId; - private Oauth2Entity mockOauth2Entity; - private User mockUser; - private OAuth2Request request; - private Face mockFace; - private Body mockBody; - private Expression mockExpression; - private CharacterSet mockCS; - private Long mockKeywordId; - private Keyword mockKeyword; - - private UserKeyword prevUserKeyword; - private UserKeyword mockUK; - private int mockPercent; - - private List keywordDTOs = new ArrayList<>(); - - @BeforeEach - public void setup() { - mockId = "test-uuid"; - mockOauth2Entity = Oauth2Entity.builder() - .provider(Provider.KAKAO) - .providerId("test-provider-id") - .providerUsername("test-provider-nickname") - .email("test@kakao.com") - .build(); - mockUser = new User(mockId, mockOauth2Entity); - request = OAuth2Request.builder() - .provider(Provider.KAKAO) - .providerId("test-provider-id") - .name("test-provider-nickname") - .email("test@kakao.com") - .build(); - mockKeywordId = 123456789L; - mockKeyword = new Keyword(mockKeywordId, "키워드"); - mockPercent = 50; - mockUK = new UserKeyword(mockUser, mockKeyword, mockPercent); - mockFace = new Face(123456789L, "mockFace", "show_url", "layout_url"); - mockBody = new Body(123456789L, "mockBody", "show_url", "layout_url"); - mockExpression = new Expression(123456789L, "mockBody", "show_url", "layout_url"); - mockCS = new CharacterSet(123456789L, "mockBody", "show_url"); - keywordDTOs.add(new KeywordDTO(123456789L, 30)); - } - - @AfterEach - public void cleanup() { - userRepository.deleteAll(); - } - - @Test - @DisplayName("새로운 유저를 저장한다.") - void save() { - // given - given(userRepository.save(any())) - .willReturn(mockUser); - // when - User saveUser = userService.save(mockOauth2Entity); - // then - assertEquals(saveUser, mockUser); - } - - @Test - @DisplayName("해당 id의 유저를 조회한다") - void findById() { - // given - ReflectionTestUtils.setField(mockUser, "id", mockId); - given(userRepository.findById(anyString())) - .willReturn(Optional.of(mockUser)); - - // when - User findUser = userService.findById(mockId); - - //then - assertEquals(mockUser, findUser); - } - - @Test - @DisplayName("로그아웃을 수행한다.") - void logout() { - // given - String accessToken = ""; - String refreshToken = ""; - doNothing().when(redisBlackListUtil).setBlackList(anyString(), anyString(), anyInt()); - - // then - assertDoesNotThrow(() -> userService.logout(accessToken, refreshToken)); - } - - @Test - @DisplayName("유저 조회를 실패한다") - void findByIdFail() { - // given - given(userRepository.findById(anyString())) - .willReturn(Optional.empty()); - - //then - assertThrows(EntityNotFoundException.class, () -> userService.findById(mockId)); - } - - @Test - @DisplayName("새로운 유저일 경우 저장한다.") - void saveIfNewUserSuccess() { - // given - given(userRepository.findUserByOauth2EntityProviderId(anyString())) - .willReturn(Optional.empty()); - given(userRepository.save(any())) - .willReturn(mockUser); - - // when - User saveUser = userService.saveIfNewUser(request); - - // then - assertEquals(mockUser, saveUser); - } - - @Test - @DisplayName("유저 닉네임을 수정한다") - void updateNickname() { - //given - given(userRepository.findById(any())).willReturn(Optional.of(mockUser)); - //when - userService.updateNickname(mockUser.getId(), "새로운 닉네임"); - //then - assertEquals(mockUser.getNickname(), "새로운 닉네임"); - } - - - - @Test - @DisplayName("만약 유저가 존재하는 경우 기존 데이터를 리턴한다.") - void saveIfNewUserFail() { - - // given - given(userRepository.findUserByOauth2EntityProviderId(anyString())) - .willReturn(Optional.of(mockUser)); - - // when - User existUser = userService.saveIfNewUser(request); - - // then - assertEquals(mockUser, existUser); - } - - @Test - @DisplayName("UUID를 생성한다.") - void generateUUID() { - // given - given(userRepository.findById(anyString())) - .willReturn(Optional.empty()); - - // when - String uuid = userService.generateUUID(); - - // then - assertNotEquals(uuid, mockId); - } -} diff --git a/src/test/java/com/najasin/service/UserTypeServiceTest.java b/src/test/java/com/najasin/service/UserTypeServiceTest.java deleted file mode 100644 index c164f12..0000000 --- a/src/test/java/com/najasin/service/UserTypeServiceTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.najasin.service; - -import static org.junit.Assert.*; -import static org.mockito.BDDMockito.*; - -import java.util.Optional; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.najasin.domain.user.entity.userType.UserType; -import com.najasin.domain.user.repository.UserTypeRepository; -import com.najasin.domain.user.service.UserTypeService; - -import jakarta.persistence.EntityNotFoundException; - -@ExtendWith(MockitoExtension.class) -public class UserTypeServiceTest { - @InjectMocks - private UserTypeService userTypeService; - - @Mock - private UserTypeRepository userTypeRepository; - - private UserType mockUserType; - private String userTypeName; - - @BeforeEach - void setup() { - userTypeName = "test"; - mockUserType = new UserType(userTypeName); - } - - @AfterEach - void cleanup() { - userTypeRepository.deleteAll();; - } - - @Test - @DisplayName("타입 이름으로 UserType을 찾는다.") - void findByNameSuccess() { - // given - given(userTypeRepository.findByName(userTypeName)) - .willReturn(Optional.of(mockUserType)); - - // when - UserType userType = userTypeService.findByName(userTypeName); - - // then - assertEquals(mockUserType, userType); - } - - @Test - @DisplayName("타입 이름으로 UserType을 찾는 데 실패한다") - void findByNameFail() { - // given - given(userTypeRepository.findByName(userTypeName)) - .willReturn(Optional.empty()); - - // then - assertThrows(EntityNotFoundException.class, () -> { - userTypeService.findByName(userTypeName); - }); - } -} diff --git a/src/test/java/com/najasin/service/UserUserTypeServiceTest.java b/src/test/java/com/najasin/service/UserUserTypeServiceTest.java deleted file mode 100644 index eba0aa6..0000000 --- a/src/test/java/com/najasin/service/UserUserTypeServiceTest.java +++ /dev/null @@ -1,241 +0,0 @@ -package com.najasin.service; - -import static org.junit.Assert.*; -import static org.mockito.BDDMockito.*; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import com.najasin.domain.answer.entity.Answer; -import com.najasin.domain.character.entity.Body; -import com.najasin.domain.character.repository.BodyRepository; -import com.najasin.domain.character.entity.CharacterSet; -import com.najasin.domain.character.repository.CharacterSetRepository; -import com.najasin.domain.character.dto.CharacterItem; -import com.najasin.domain.character.entity.Expression; -import com.najasin.domain.character.repository.ExpressionRepository; -import com.najasin.domain.character.entity.Face; -import com.najasin.domain.character.repository.FaceRepository; -import com.najasin.domain.comment.entity.Comment; -import com.najasin.domain.question.entity.Question; -import com.najasin.domain.question.entity.QuestionType; -import com.najasin.domain.character.dto.CharacterItems; -import com.najasin.domain.user.dto.Page; -import com.najasin.domain.user.repository.UserRepository; -import com.najasin.domain.user.repository.UserTypeRepository; -import com.najasin.global.audit.AuditEntity; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.najasin.domain.user.entity.Oauth2Entity; -import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.entity.userType.UserType; -import com.najasin.domain.user.service.UserTypeService; -import com.najasin.domain.user.entity.userType.UserUserType; -import com.najasin.domain.user.repository.UserUserTypeRepository; -import com.najasin.domain.user.service.UserUserTypeService; - -@ExtendWith(MockitoExtension.class) -public class UserUserTypeServiceTest { - @InjectMocks - private UserUserTypeService userUserTypeService; - - @Mock - private UserTypeService userTypeService; - - @Mock - private UserUserTypeRepository userUserTypeRepository; - @Mock - private UserRepository userRepository; - @Mock - private FaceRepository faceRepository; - @Mock - private BodyRepository bodyRepository; - @Mock - private ExpressionRepository expressionRepository; - @Mock - private CharacterSetRepository characterSetRepository; - @Mock - private UserTypeRepository userTypeRepository; - - private User mockUser; - private UserType mockUserType; - private String userTypeName; - private UserUserType mockUserUserType; - private List mockAnswers; - private Question question; - private Face mockFace; - private Body mockBody; - private Expression mockExpression; - private CharacterSet mockCharacterSet; - - - private CharacterItems dto; - - @BeforeEach - void setup() { - Oauth2Entity oauth2Entity = Oauth2Entity.builder().build(); - userTypeName = "test"; - mockAnswers = new ArrayList<>(); - question = new Question(1L, "test question", QuestionType.FOR_USER, null, null); - mockAnswers.add(new Answer(mockUser, question, "answer")); - mockUser = User.builder() - .answers(mockAnswers) - .userUserTypes(new ArrayList<>()) - .comments(new ArrayList<>()) - .auditEntity(new AuditEntity()) - .build(); - mockUserType = new UserType(userTypeName); - mockUserUserType = new UserUserType(mockUser, mockUserType); - dto = new CharacterItems(); - dto.setBody(CharacterItem.builder() - .id(2L) - .build()); - dto.setFace(CharacterItem.builder() - .id(1L) - .build()); - dto.setExpression(null); - dto.setSet(null); - - } - - @AfterEach - void cleanup() { - userUserTypeRepository.deleteAll(); - } - - @Test - @DisplayName("유저와 유저 타입의 연관관계를 저장한다") - void save() { - // given - given(userUserTypeRepository.save(any())) - .willReturn(mockUserUserType); - - // when - UserUserType userUserType = userUserTypeService.save(mockUser, mockUserType); - - // then - assertEquals(userUserType, mockUserUserType); - } - - @Test - @DisplayName("유저의 유저 타입을 변경한다.") - void updateUserType() { - // given - given(userTypeService.findByName(userTypeName)) - .willReturn(mockUserType); - - //when - String updatedTypeName = userUserTypeService.updateUserType(mockUser, userTypeName); - - // then - assertEquals(updatedTypeName, userTypeName); - } - - @Test - @DisplayName("유저와 유저타입 관계를 받아온다.") - public void getUserUserTypeById() { - //given - given(userRepository.findById(any())).willReturn(Optional.of(mockUser)); - given(userTypeRepository.findByName(any())).willReturn(Optional.of(mockUserType)); - given(userUserTypeRepository.findById(any())).willReturn(Optional.ofNullable(mockUserUserType)); - //when - UserUserType getUserUserType = userUserTypeService.getUserUserTypeById(mockUser.getId(), mockUserType.getName()); - //then - assertEquals(mockUserUserType, getUserUserType); - } - - @Test - @DisplayName("유저아이디로 유저타입관계들을 가져온다") - public void getUserUserTypesById() { - //given - List list = new ArrayList<>(); - list.add(mockUserUserType); - given(userRepository.findById(any())).willReturn(Optional.of(mockUser)); - given(userUserTypeRepository.findAllByUser(any())).willReturn(list); - //when - List getList = userUserTypeService.getUserUserTypesByUserId(mockUser.getId()); - //then - assertEquals(getList, list); - } - - @Test - @DisplayName("유저 아이디와 타입과 질문 유형 별 질문 응답을 가져온다") - public void getQAByUserIdAndUserTypeAndQuestionType(){ - //given - given(userRepository.findById(any())).willReturn(Optional.of(mockUser)); - given(userTypeRepository.findByName(any())).willReturn(Optional.of(mockUserType)); - given(userUserTypeRepository.findById(any())).willReturn(Optional.ofNullable(mockUserUserType)); - List myQaParis = new ArrayList<>(); - myQaParis.add(new Page.QAPair(1L, "test question", "answer")); - //when - List getQaPair = userUserTypeService.getQAByUserIdAndUserTypeForUser(mockUser.getId(), "JFF", QuestionType.FOR_USER); - //then - assertEquals(getQaPair.get(0).getQuestion(), myQaParis.get(0).getQuestion()); - assertEquals(getQaPair.get(0).getAnswer(), myQaParis.get(0).getAnswer()); - assertEquals(getQaPair.get(0).getId(), myQaParis.get(0).getId()); - } - - @Test - @DisplayName("유저의 타적나사를 가져온다") - public void getOtherManualByUserIdAndUserType() { - //given - mockUserUserType.getUser().getComments().add(new Comment(1L, mockUser, new Question(1L, "질문", null, null, null), null, "mockNickname", new AuditEntity())); - given(userRepository.findById(any())).willReturn(Optional.of(mockUser)); - given(userTypeRepository.findByName(any())).willReturn(Optional.of(mockUserType)); - given(userUserTypeRepository.findById(any())).willReturn(Optional.ofNullable(mockUserUserType)); - //when - List getList = userUserTypeService.getOtherManualByUserIdAndUserType(mockUser.getId(), mockUserType.getName(), QuestionType.FOR_OTHERS); - //then -// assertEquals(getList.get(0).getNickname(), "mockNickname"); - - } - - - @Test - @DisplayName("유저의 캐릭터를 업데이트한다") - public void updateCharacter() { - //given - - given(userRepository.findById(any())).willReturn(Optional.of(mockUser)); - given(userRepository.findById(any())).willReturn(Optional.of(mockUser)); - given(userTypeRepository.findByName(any())).willReturn(Optional.of(mockUserType)); - given(userUserTypeRepository.findById(any())).willReturn(Optional.ofNullable(mockUserUserType)); - given(userUserTypeRepository.save(any())).willReturn(mockUserUserType); - //when - UserUserType userUserType = userUserTypeService.updateCharacter(mockUser.getId(), "JFF", dto); - //then - assertEquals(mockUserUserType, userUserType); - } - - @Test - @DisplayName("유저의 캐릭터 정보들을 가져온다") - public void getCharacter() { - //given - mockFace = new Face(1L, "얼굴1", null, null); - mockBody = new Body(2L, "몸2", null, null); - mockExpression = null; - mockCharacterSet = null; - mockUserUserType.updateCharacter(mockFace, mockBody, mockExpression, mockCharacterSet); - given(userRepository.findById(any())).willReturn(Optional.of(mockUser)); - given(userTypeRepository.findByName(any())).willReturn(Optional.of(mockUserType)); - given(userUserTypeRepository.findById(any())).willReturn(Optional.ofNullable(mockUserUserType)); - given(userUserTypeRepository.findById(any())).willReturn(Optional.ofNullable(mockUserUserType)); - //when - CharacterItems characterInfoDTO = userUserTypeService.getCharacter(mockUser.getId(), "JFF"); - assertEquals(characterInfoDTO.getFace().getId(), mockFace.getId()); - assertEquals(characterInfoDTO.getFace().getShowCase(), mockFace.getShow_url()); - assertEquals(characterInfoDTO.getFace().getLayoutCase(), mockFace.getLayout_url()); - assertEquals(characterInfoDTO.getBody().getId(), mockBody.getId()); - assertEquals(characterInfoDTO.getBody().getShowCase(), mockBody.getShow_url()); - assertEquals(characterInfoDTO.getBody().getLayoutCase(), mockBody.getLayout_url()); - } - -} From 3b9384ca9db508983e78abd761119aa79dfb1b4c Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 04:30:41 +0900 Subject: [PATCH 20/27] =?UTF-8?q?refactor(#48):=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manual/controller/MyManualController.java | 8 ++-- .../manual/dto/param/JffAnswerParam.java | 4 +- .../manual/dto/param/JffKeywordParam.java | 4 +- .../dto/param/JffKeywordPercentParam.java | 4 +- .../manual/dto/param/JffQuestionParam.java | 4 +- .../dto/request/MyManualCreateRequest.java | 12 +++--- .../dto/response/JffMyManualResponse.java | 12 +++--- .../dto/response/JffOtherManualResponse.java | 16 +++++++ .../domain/manual/entity/answer/Answer.java | 14 +++---- .../domain/manual/entity/comment/Comment.java | 10 +++-- .../domain/manual/entity/keyword/Keyword.java | 6 +-- .../manual/entity/question/Question.java | 6 +-- .../entity/userKeyword/UserKeyword.java | 10 +++-- .../manual/repository/CommentRepository.java | 2 +- .../domain/manual/service/AnswerService.java | 6 +-- .../domain/manual/service/CommentService.java | 42 +++++++++++++++++++ .../domain/manual/service/KeywordService.java | 4 +- .../manual/service/QuestionService.java | 4 +- .../manual/service/UserKeywordService.java | 6 +-- .../domain/user/dto/param/AnswerParam.java | 6 +-- .../domain/user/dto/param/CommentParam.java | 12 ++++++ .../user/dto/param/KeywordPercentParam.java | 6 +-- .../user/dto/response/MyPageResponse.java | 11 +++-- .../domain/user/service/UserService.java | 1 - .../user/service/UserUserTypeService.java | 18 ++++---- 25 files changed, 155 insertions(+), 73 deletions(-) create mode 100644 src/main/java/com/najasin/domain/manual/dto/response/JffOtherManualResponse.java create mode 100644 src/main/java/com/najasin/domain/manual/service/CommentService.java create mode 100644 src/main/java/com/najasin/domain/user/dto/param/CommentParam.java diff --git a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java index a3e2dd7..4bcc3ad 100644 --- a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java +++ b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java @@ -18,11 +18,11 @@ import com.najasin.domain.character.dto.param.CharacterItemsParam; import com.najasin.domain.character.service.CharacterService; import com.najasin.domain.manual.service.AnswerService; -import com.najasin.domain.manual.dto.param.JffMyKeyword; +import com.najasin.domain.manual.dto.param.JffKeywordParam; import com.najasin.domain.manual.dto.request.MyManualCreateRequest; import com.najasin.domain.manual.dto.response.JffMyManualCreateResponse; import com.najasin.domain.manual.dto.response.JffMyManualResponse; -import com.najasin.domain.manual.dto.param.JffMyQuestion; +import com.najasin.domain.manual.dto.param.JffQuestionParam; import com.najasin.domain.manual.entity.keyword.Keyword; import com.najasin.domain.manual.service.KeywordService; import com.najasin.domain.manual.entity.question.Question; @@ -55,8 +55,8 @@ public ResponseEntity> getMyManual(@PathVariabl CharacterItemsParam characterItems = characterService.findAllItems(); // 추후에 다른 분기에 대한 처리 필요 - List questionList = questionService.findAll(userType); - List keywordList = keywordService.findAll(); + List questionList = questionService.findAll(userType); + List keywordList = keywordService.findAll(); return ResponseEntity.ok(createSuccessWithData( FIND_MY_MANUAL_SUCCESS.getMsg(), diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffAnswerParam.java b/src/main/java/com/najasin/domain/manual/dto/param/JffAnswerParam.java index 1047926..1bb7dd6 100644 --- a/src/main/java/com/najasin/domain/manual/dto/param/JffAnswerParam.java +++ b/src/main/java/com/najasin/domain/manual/dto/param/JffAnswerParam.java @@ -4,8 +4,8 @@ import com.najasin.domain.manual.entity.question.Question; import com.najasin.domain.user.entity.User; -public record JffMyAnswer(Long id, - String answer) { +public record JffAnswerParam(Long id, + String answer) { public Answer toAnswerEntity(User user, Question question) { return new Answer(user, question, answer); diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffKeywordParam.java b/src/main/java/com/najasin/domain/manual/dto/param/JffKeywordParam.java index 18ade18..9031364 100644 --- a/src/main/java/com/najasin/domain/manual/dto/param/JffKeywordParam.java +++ b/src/main/java/com/najasin/domain/manual/dto/param/JffKeywordParam.java @@ -1,5 +1,5 @@ package com.najasin.domain.manual.dto.param; -public record JffMyKeyword(Long id, - String keyword) { +public record JffKeywordParam(Long id, + String keyword) { } diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffKeywordPercentParam.java b/src/main/java/com/najasin/domain/manual/dto/param/JffKeywordPercentParam.java index 0271bf1..ee1a33c 100644 --- a/src/main/java/com/najasin/domain/manual/dto/param/JffKeywordPercentParam.java +++ b/src/main/java/com/najasin/domain/manual/dto/param/JffKeywordPercentParam.java @@ -4,8 +4,8 @@ import com.najasin.domain.manual.entity.userKeyword.UserKeyword; import com.najasin.domain.user.entity.User; -public record JffMyKeywordPercent(Long id, - Integer percent) { +public record JffKeywordPercentParam(Long id, + Integer percent) { public UserKeyword toUserKeywordEntity(User user, Keyword keyword) { return new UserKeyword(user, keyword, percent); diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffQuestionParam.java b/src/main/java/com/najasin/domain/manual/dto/param/JffQuestionParam.java index 0a9f78e..c32cfc2 100644 --- a/src/main/java/com/najasin/domain/manual/dto/param/JffQuestionParam.java +++ b/src/main/java/com/najasin/domain/manual/dto/param/JffQuestionParam.java @@ -1,5 +1,5 @@ package com.najasin.domain.manual.dto.param; -public record JffMyQuestion(Long id, - String question) { +public record JffQuestionParam(Long id, + String question) { } diff --git a/src/main/java/com/najasin/domain/manual/dto/request/MyManualCreateRequest.java b/src/main/java/com/najasin/domain/manual/dto/request/MyManualCreateRequest.java index 97b7ddb..cda137c 100644 --- a/src/main/java/com/najasin/domain/manual/dto/request/MyManualCreateRequest.java +++ b/src/main/java/com/najasin/domain/manual/dto/request/MyManualCreateRequest.java @@ -2,20 +2,20 @@ import java.util.List; -import com.najasin.domain.manual.dto.param.JffMyAnswer; -import com.najasin.domain.manual.dto.param.JffMyKeywordPercent; +import com.najasin.domain.manual.dto.param.JffAnswerParam; +import com.najasin.domain.manual.dto.param.JffKeywordPercentParam; import com.najasin.domain.manual.dto.param.ManualCharacterItems; public record MyManualCreateRequest(String nickname, ManualCharacterItems characterItems, - List answers, - List keywordPercents) { + List answers, + List keywordPercents) { public List getQuestionIdList() { - return answers.stream().map(JffMyAnswer::id).toList(); + return answers.stream().map(JffAnswerParam::id).toList(); } public List getKeywordIdList() { - return keywordPercents.stream().map(JffMyKeywordPercent::id).toList(); + return keywordPercents.stream().map(JffKeywordPercentParam::id).toList(); } } diff --git a/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualResponse.java b/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualResponse.java index ea321b3..fea6ec1 100644 --- a/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualResponse.java +++ b/src/main/java/com/najasin/domain/manual/dto/response/JffMyManualResponse.java @@ -3,19 +3,19 @@ import java.util.List; import com.najasin.domain.character.dto.param.CharacterItemsParam; -import com.najasin.domain.manual.dto.param.JffMyKeyword; -import com.najasin.domain.manual.dto.param.JffMyQuestion; +import com.najasin.domain.manual.dto.param.JffKeywordParam; +import com.najasin.domain.manual.dto.param.JffQuestionParam; public record JffMyManualResponse(String baseImage, CharacterItemsParam characterItems, - List questions, - List exampleKeywords) { + List questions, + List exampleKeywords) { public static JffMyManualResponse of( String baseImage, CharacterItemsParam characterItems, - List questions, - List exampleKeywords) { + List questions, + List exampleKeywords) { return new JffMyManualResponse(baseImage, characterItems, questions, exampleKeywords); } } diff --git a/src/main/java/com/najasin/domain/manual/dto/response/JffOtherManualResponse.java b/src/main/java/com/najasin/domain/manual/dto/response/JffOtherManualResponse.java new file mode 100644 index 0000000..68e0e91 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/response/JffOtherManualResponse.java @@ -0,0 +1,16 @@ +package com.najasin.domain.manual.dto.response; + +import java.util.List; + +import com.najasin.domain.manual.dto.param.JffQuestionParam; +import com.najasin.domain.user.dto.param.AnswerParam; +import com.najasin.domain.user.dto.param.MyCharacterItemsParam; +import com.najasin.domain.user.dto.param.KeywordPercentParam; + +public record JffOtherManualResponse(String nickname, + String baseImage, + MyCharacterItemsParam characterItems, + List questions, + List myManualQAPair, + List originKeywordPercents) { +} diff --git a/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java b/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java index 7eefdcd..374e0fc 100644 --- a/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java +++ b/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java @@ -1,7 +1,7 @@ package com.najasin.domain.manual.entity.answer; import com.najasin.domain.manual.entity.question.Question; -import com.najasin.domain.user.dto.param.MyAnswerParam; +import com.najasin.domain.user.dto.param.AnswerParam; import com.najasin.domain.user.entity.User; import jakarta.persistence.*; @@ -26,18 +26,18 @@ public class Answer { @JoinColumn(name = "question_id", referencedColumnName = "question_id", insertable = false, updatable = false) private Question question; - @Column(name = "answer") - private String answer; + @Column(name = "content") + private String content; public Long getQuestionId() { return question.getId(); } - public void updateAnswer(String answer) { - this.answer = answer; + public void updateAnswer(String content) { + this.content = content; } - public MyAnswerParam toMyAnswerParam() { - return new MyAnswerParam(question.getId(), question.getQuestion(), answer); + public AnswerParam toMyAnswerParam() { + return new AnswerParam(question.getId(), question.getQuestion(), content); } } diff --git a/src/main/java/com/najasin/domain/manual/entity/comment/Comment.java b/src/main/java/com/najasin/domain/manual/entity/comment/Comment.java index d2d4295..60b8654 100644 --- a/src/main/java/com/najasin/domain/manual/entity/comment/Comment.java +++ b/src/main/java/com/najasin/domain/manual/entity/comment/Comment.java @@ -1,6 +1,7 @@ package com.najasin.domain.manual.entity.comment; import com.najasin.domain.manual.entity.question.Question; +import com.najasin.domain.user.dto.param.AnswerParam; import com.najasin.domain.user.entity.User; import com.najasin.global.audit.AuditEntity; import jakarta.persistence.*; @@ -12,7 +13,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Getter -@Entity +@Entity(name = "comments") @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @Builder @@ -30,8 +31,8 @@ public class Comment { @JoinColumn(name = "question_id", referencedColumnName = "question_id") private Question question; - @Column(name = "comment") - private String comment; + @Column(name = "content") + private String content; @Column(name = "nickname") private String nickname; @@ -39,4 +40,7 @@ public class Comment { @Embedded private AuditEntity auditEntity; + public AnswerParam toAnswerParam() { + return new AnswerParam(question.getId(), question.getQuestion(), content); + } } diff --git a/src/main/java/com/najasin/domain/manual/entity/keyword/Keyword.java b/src/main/java/com/najasin/domain/manual/entity/keyword/Keyword.java index 9900437..2957216 100644 --- a/src/main/java/com/najasin/domain/manual/entity/keyword/Keyword.java +++ b/src/main/java/com/najasin/domain/manual/entity/keyword/Keyword.java @@ -1,6 +1,6 @@ package com.najasin.domain.manual.entity.keyword; -import com.najasin.domain.manual.dto.param.JffMyKeyword; +import com.najasin.domain.manual.dto.param.JffKeywordParam; import jakarta.persistence.*; import lombok.AccessLevel; @@ -21,7 +21,7 @@ public class Keyword { @Column(name = "keyword_name") private String name; - public JffMyKeyword toJffMyKeyword() { - return new JffMyKeyword(id, name); + public JffKeywordParam toJffMyKeyword() { + return new JffKeywordParam(id, name); } } diff --git a/src/main/java/com/najasin/domain/manual/entity/question/Question.java b/src/main/java/com/najasin/domain/manual/entity/question/Question.java index be01936..cdc2584 100644 --- a/src/main/java/com/najasin/domain/manual/entity/question/Question.java +++ b/src/main/java/com/najasin/domain/manual/entity/question/Question.java @@ -1,6 +1,6 @@ package com.najasin.domain.manual.entity.question; -import com.najasin.domain.manual.dto.param.JffMyQuestion; +import com.najasin.domain.manual.dto.param.JffQuestionParam; import com.najasin.domain.user.entity.userType.UserType; import jakarta.persistence.*; import lombok.AccessLevel; @@ -29,7 +29,7 @@ public class Question { @JoinColumn(name = "user_type_id", referencedColumnName = "user_type_id") private UserType userType; - public JffMyQuestion toJffMyQuestion() { - return new JffMyQuestion(id, question); + public JffQuestionParam toJffMyQuestion() { + return new JffQuestionParam(id, question); } } diff --git a/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java b/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java index 23cdb1f..13b0718 100644 --- a/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java +++ b/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java @@ -1,7 +1,7 @@ package com.najasin.domain.manual.entity.userKeyword; import com.najasin.domain.manual.entity.keyword.Keyword; -import com.najasin.domain.user.dto.param.MyKeywordPercentParam; +import com.najasin.domain.user.dto.param.KeywordPercentParam; import com.najasin.domain.user.entity.User; import jakarta.persistence.*; @@ -43,7 +43,11 @@ public UserKeyword(User user, Keyword keyword, int originPercent) { this.othersCount = 0; } - public MyKeywordPercentParam toMyKeywordPercentParam() { - return new MyKeywordPercentParam(keyword.getId(), keyword.getName(), originPercent); + public KeywordPercentParam toMyKeywordPercentParam() { + return new KeywordPercentParam(keyword.getId(), keyword.getName(), originPercent); + } + + public KeywordPercentParam toOthersKeywordPercentParam() { + return new KeywordPercentParam(keyword.getId(), keyword.getName(), othersCount); } } diff --git a/src/main/java/com/najasin/domain/manual/repository/CommentRepository.java b/src/main/java/com/najasin/domain/manual/repository/CommentRepository.java index 62f4963..bf8869d 100644 --- a/src/main/java/com/najasin/domain/manual/repository/CommentRepository.java +++ b/src/main/java/com/najasin/domain/manual/repository/CommentRepository.java @@ -8,5 +8,5 @@ import java.util.List; public interface CommentRepository extends JpaRepository { - List findAllByUser(User user); + List findAllByUserId(String userId); } diff --git a/src/main/java/com/najasin/domain/manual/service/AnswerService.java b/src/main/java/com/najasin/domain/manual/service/AnswerService.java index f50a62e..5afbfa5 100644 --- a/src/main/java/com/najasin/domain/manual/service/AnswerService.java +++ b/src/main/java/com/najasin/domain/manual/service/AnswerService.java @@ -8,7 +8,7 @@ import com.najasin.domain.manual.entity.answer.Answer; import com.najasin.domain.manual.repository.AnswerRepository; -import com.najasin.domain.manual.dto.param.JffMyAnswer; +import com.najasin.domain.manual.dto.param.JffAnswerParam; import com.najasin.domain.manual.entity.question.Question; import com.najasin.domain.user.dto.param.AnswerUpdateParam; import com.najasin.domain.user.entity.User; @@ -21,8 +21,8 @@ public class AnswerService { private final AnswerRepository answerRepository; @Transactional - public void saveAll(List answers, List questions, User user) { - answers.sort(Comparator.comparing(JffMyAnswer::id)); + public void saveAll(List answers, List questions, User user) { + answers.sort(Comparator.comparing(JffAnswerParam::id)); questions.sort(Comparator.comparing(Question::getId)); for (int i = 0; i < answers.size(); i++) { diff --git a/src/main/java/com/najasin/domain/manual/service/CommentService.java b/src/main/java/com/najasin/domain/manual/service/CommentService.java new file mode 100644 index 0000000..91c9807 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/service/CommentService.java @@ -0,0 +1,42 @@ +package com.najasin.domain.manual.service; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.najasin.domain.manual.entity.comment.Comment; +import com.najasin.domain.manual.repository.CommentRepository; +import com.najasin.domain.user.dto.param.AnswerParam; +import com.najasin.domain.user.dto.param.CommentParam; +import com.najasin.domain.user.entity.User; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Service +public class CommentService { + private final CommentRepository commentRepository; + + public List mapToCommentParam(List comments) { + Map> map = new LinkedHashMap<>(); + + for(Comment comment : comments) { + String key = comment.getNickname(); + if(!map.containsKey(comment.getNickname())) { + map.put(key, new ArrayList<>()); + } + map.get(key).add(comment.toAnswerParam()); + } + + return CommentParam.ofList(map); + } + + @Transactional(readOnly = true) + public List findAllByUserId(String userId) { + return commentRepository.findAllByUserId(userId); + } +} diff --git a/src/main/java/com/najasin/domain/manual/service/KeywordService.java b/src/main/java/com/najasin/domain/manual/service/KeywordService.java index e177ba5..9c98fc3 100644 --- a/src/main/java/com/najasin/domain/manual/service/KeywordService.java +++ b/src/main/java/com/najasin/domain/manual/service/KeywordService.java @@ -5,7 +5,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.najasin.domain.manual.dto.param.JffMyKeyword; +import com.najasin.domain.manual.dto.param.JffKeywordParam; import com.najasin.domain.manual.entity.keyword.Keyword; import com.najasin.domain.manual.repository.KeywordRepository; @@ -28,7 +28,7 @@ public Keyword findById(Long id) { } @Transactional(readOnly = true) - public List findAll() { + public List findAll() { return keywordRepository.findAll().stream().map(Keyword::toJffMyKeyword).toList(); } } diff --git a/src/main/java/com/najasin/domain/manual/service/QuestionService.java b/src/main/java/com/najasin/domain/manual/service/QuestionService.java index 918a39a..e1f7769 100644 --- a/src/main/java/com/najasin/domain/manual/service/QuestionService.java +++ b/src/main/java/com/najasin/domain/manual/service/QuestionService.java @@ -7,7 +7,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.najasin.domain.manual.dto.param.JffMyQuestion; +import com.najasin.domain.manual.dto.param.JffQuestionParam; import com.najasin.domain.manual.entity.question.Question; import com.najasin.domain.manual.repository.QuestionRepository; @@ -21,7 +21,7 @@ public class QuestionService { private final QuestionRepository questionRepository; @Transactional(readOnly = true) - public List findAll(String userTypeName) { + public List findAll(String userTypeName) { List questionList = questionRepository.findAllByQuestionTypeAndUserTypeName(FOR_USER, userTypeName); return questionList.stream().map(Question::toJffMyQuestion).toList(); diff --git a/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java b/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java index bcd9a3e..91cee32 100644 --- a/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java +++ b/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java @@ -6,7 +6,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.najasin.domain.manual.dto.param.JffMyKeywordPercent; +import com.najasin.domain.manual.dto.param.JffKeywordPercentParam; import com.najasin.domain.manual.entity.keyword.Keyword; import com.najasin.domain.manual.entity.userKeyword.UserKeyword; import com.najasin.domain.manual.repository.UserKeywordRepository; @@ -20,8 +20,8 @@ public class UserKeywordService { private final UserKeywordRepository userKeywordRepository; @Transactional - public void saveAll(List keywordPercents, List keywords, User user) { - keywordPercents.sort(Comparator.comparing(JffMyKeywordPercent::id)); + public void saveAll(List keywordPercents, List keywords, User user) { + keywordPercents.sort(Comparator.comparing(JffKeywordPercentParam::id)); keywords.sort(Comparator.comparing(Keyword::getId)); for (int i = 0; i < keywordPercents.size(); i++) { diff --git a/src/main/java/com/najasin/domain/user/dto/param/AnswerParam.java b/src/main/java/com/najasin/domain/user/dto/param/AnswerParam.java index 5e6474f..c150832 100644 --- a/src/main/java/com/najasin/domain/user/dto/param/AnswerParam.java +++ b/src/main/java/com/najasin/domain/user/dto/param/AnswerParam.java @@ -1,6 +1,6 @@ package com.najasin.domain.user.dto.param; -public record MyAnswerParam(Long id, - String question, - String answer) { +public record AnswerParam(Long id, + String question, + String answer) { } diff --git a/src/main/java/com/najasin/domain/user/dto/param/CommentParam.java b/src/main/java/com/najasin/domain/user/dto/param/CommentParam.java new file mode 100644 index 0000000..1912b7a --- /dev/null +++ b/src/main/java/com/najasin/domain/user/dto/param/CommentParam.java @@ -0,0 +1,12 @@ +package com.najasin.domain.user.dto.param; + +import java.util.List; +import java.util.Map; + +public record CommentParam(String nickname, + List qas) { + + public static List ofList(Map> map) { + return map.keySet().stream().map((key) -> new CommentParam(key, map.get(key))).toList(); + } +} diff --git a/src/main/java/com/najasin/domain/user/dto/param/KeywordPercentParam.java b/src/main/java/com/najasin/domain/user/dto/param/KeywordPercentParam.java index 193f845..62c96e2 100644 --- a/src/main/java/com/najasin/domain/user/dto/param/KeywordPercentParam.java +++ b/src/main/java/com/najasin/domain/user/dto/param/KeywordPercentParam.java @@ -1,6 +1,6 @@ package com.najasin.domain.user.dto.param; -public record MyKeywordPercentParam(Long id, - String keyword, - Integer percent) { +public record KeywordPercentParam(Long id, + String keyword, + Integer percent) { } diff --git a/src/main/java/com/najasin/domain/user/dto/response/MyPageResponse.java b/src/main/java/com/najasin/domain/user/dto/response/MyPageResponse.java index d46e414..622dcf2 100644 --- a/src/main/java/com/najasin/domain/user/dto/response/MyPageResponse.java +++ b/src/main/java/com/najasin/domain/user/dto/response/MyPageResponse.java @@ -2,9 +2,10 @@ import java.util.List; -import com.najasin.domain.user.dto.param.MyAnswerParam; +import com.najasin.domain.user.dto.param.AnswerParam; +import com.najasin.domain.user.dto.param.CommentParam; import com.najasin.domain.user.dto.param.MyCharacterItemsParam; -import com.najasin.domain.user.dto.param.MyKeywordPercentParam; +import com.najasin.domain.user.dto.param.KeywordPercentParam; import lombok.Builder; @@ -12,8 +13,10 @@ public record MyPageResponse(List userTypes, String nickname, String baseImage, MyCharacterItemsParam characterItems, - List myManualQAPair, - List originKeywordPercents, + List myManualQAPair, + List othersManualQAPairs, + List originKeywordPercents, + List otherKeywordPercents, Boolean isOwner) { @Builder diff --git a/src/main/java/com/najasin/domain/user/service/UserService.java b/src/main/java/com/najasin/domain/user/service/UserService.java index 723eb8f..fbb5a1d 100644 --- a/src/main/java/com/najasin/domain/user/service/UserService.java +++ b/src/main/java/com/najasin/domain/user/service/UserService.java @@ -33,7 +33,6 @@ public User save(Oauth2Entity oauth2Entity) { @Transactional(readOnly = true) public User findById(String id) { - System.out.println(id); return userRepository.findById(id).orElseThrow(EntityNotFoundException::new); } diff --git a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java index 6eeb9bf..1df7dc4 100644 --- a/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java +++ b/src/main/java/com/najasin/domain/user/service/UserUserTypeService.java @@ -7,9 +7,10 @@ import com.najasin.domain.manual.service.AnswerService; import com.najasin.domain.manual.dto.param.ManualCharacterItems; import com.najasin.domain.manual.entity.userKeyword.UserKeyword; +import com.najasin.domain.manual.service.CommentService; import com.najasin.domain.manual.service.UserKeywordService; -import com.najasin.domain.user.dto.param.MyAnswerParam; -import com.najasin.domain.user.dto.param.MyKeywordPercentParam; +import com.najasin.domain.user.dto.param.AnswerParam; +import com.najasin.domain.user.dto.param.CommentParam; import com.najasin.domain.user.dto.response.MyPageResponse; import com.najasin.domain.user.dto.response.UserTypeUpdateResponse; import com.najasin.domain.user.entity.User; @@ -34,6 +35,7 @@ public class UserUserTypeService { private final CharacterService characterService; private final AnswerService answerService; private final UserKeywordService userKeywordService; + private final CommentService commentService; @Value("${base-image}") private String baseImage; @@ -78,14 +80,12 @@ public MyPageResponse getMyPage(User user, String userType, String userId) { List userTypes = isNull(user) ? null : user.getUserUserTypes().stream().map(UserUserType::getUserType).toList(); UserUserType userUserType = findByUserIdAndUserTypeName(userId, userType); - List answers = answerService.findByUserIdAndUserType(userId, userType) + List answers = answerService.findByUserIdAndUserType(userId, userType) .stream() .map(Answer::toMyAnswerParam) .toList(); - List percents = userKeywordService.findByUserId(userId) - .stream() - .map(UserKeyword::toMyKeywordPercentParam) - .toList(); + List percents = userKeywordService.findByUserId(userId); + List comments = commentService.mapToCommentParam(commentService.findAllByUserId(userId)); return MyPageResponse.builder() .userTypes(isNull(userTypes) ? null : userTypes.stream().map(UserType::getName).toList()) @@ -93,7 +93,9 @@ public MyPageResponse getMyPage(User user, String userType, String userId) { .baseImage(baseImage) .characterItems(userUserType.toMyCharacterItemsParam()) .myManualQAPair(answers) - .originKeywordPercents(percents) + .othersManualQAPairs(comments) + .originKeywordPercents(percents.stream().map(UserKeyword::toMyKeywordPercentParam).toList()) + .otherKeywordPercents(percents.stream().map(UserKeyword::toOthersKeywordPercentParam).toList()) .isOwner(!isNull(user)) .build(); } From 25224f859c97518109aaf8c0d4ef4281db9c7b42 Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 04:52:22 +0900 Subject: [PATCH 21/27] =?UTF-8?q?feature(#48):=20Others=20Manual=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../controller/OthersManualController.java | 39 +++++++++++++ .../manual/dto/message/ManualMessage.java | 3 +- .../dto/response/JffOtherManualResponse.java | 11 +++- .../manual/service/OthersManualService.java | 58 +++++++++++++++++++ .../manual/service/QuestionService.java | 1 - src/test/resources/application.yml | 4 +- 7 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/najasin/domain/manual/controller/OthersManualController.java create mode 100644 src/main/java/com/najasin/domain/manual/service/OthersManualService.java diff --git a/build.gradle b/build.gradle index 3c1ddde..6d1ee89 100644 --- a/build.gradle +++ b/build.gradle @@ -108,6 +108,7 @@ jacocoTestCoverageVerification { 'com.najasin.domain.dto.**', 'com.najasin.domain.**.dto.**', 'com.najasin.domain.**.entity.**', + 'com.najasin.domain.**.service.**', 'com.najasin.domain.**.controller.**', 'com.najasin.global.**', 'com.najasin.security.**', diff --git a/src/main/java/com/najasin/domain/manual/controller/OthersManualController.java b/src/main/java/com/najasin/domain/manual/controller/OthersManualController.java new file mode 100644 index 0000000..02dc3c8 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/controller/OthersManualController.java @@ -0,0 +1,39 @@ +package com.najasin.domain.manual.controller; + +import static com.najasin.domain.manual.dto.message.ManualMessage.*; +import static com.najasin.global.response.ApiResponse.*; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.najasin.domain.manual.dto.response.JffOtherManualResponse; +import com.najasin.domain.manual.service.OthersManualService; +import com.najasin.global.response.ApiResponse; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/{userType}/others-manual") +public class OthersManualController { + private final OthersManualService othersManualService; + + @GetMapping + public ResponseEntity> getOthersManual( + @PathVariable String userType, + @RequestParam(required = true, value = "userId") String userId) { + return ResponseEntity.ok(createSuccessWithData( + FIND_OTHERS_MANUAL_SUCCESS.getMsg(), + othersManualService.getJffOtherManual(userType, userId))); + } + + @PostMapping + public ResponseEntity> saveOthersManual(@PathVariable String userType) { + return null; + } +} diff --git a/src/main/java/com/najasin/domain/manual/dto/message/ManualMessage.java b/src/main/java/com/najasin/domain/manual/dto/message/ManualMessage.java index e15c8ba..728ae3e 100644 --- a/src/main/java/com/najasin/domain/manual/dto/message/ManualMessage.java +++ b/src/main/java/com/najasin/domain/manual/dto/message/ManualMessage.java @@ -7,6 +7,7 @@ @RequiredArgsConstructor public enum ManualMessage { FIND_MY_MANUAL_SUCCESS("my manual 조회에 성공했습니다."), - CREATE_MY_MANUAL_SUCCESS("my manual 생성에 성공했습니다."); + CREATE_MY_MANUAL_SUCCESS("my manual 생성에 성공했습니다."), + FIND_OTHERS_MANUAL_SUCCESS("others manual 조회에 성공했습니다."); private final String msg; } diff --git a/src/main/java/com/najasin/domain/manual/dto/response/JffOtherManualResponse.java b/src/main/java/com/najasin/domain/manual/dto/response/JffOtherManualResponse.java index 68e0e91..93a9f4c 100644 --- a/src/main/java/com/najasin/domain/manual/dto/response/JffOtherManualResponse.java +++ b/src/main/java/com/najasin/domain/manual/dto/response/JffOtherManualResponse.java @@ -4,13 +4,22 @@ import com.najasin.domain.manual.dto.param.JffQuestionParam; import com.najasin.domain.user.dto.param.AnswerParam; +import com.najasin.domain.user.dto.param.CommentParam; import com.najasin.domain.user.dto.param.MyCharacterItemsParam; import com.najasin.domain.user.dto.param.KeywordPercentParam; +import lombok.Builder; + public record JffOtherManualResponse(String nickname, String baseImage, MyCharacterItemsParam characterItems, List questions, List myManualQAPair, - List originKeywordPercents) { + List othersManualQAPairs, + List originKeywordPercents, + List otherKeywordPercents) { + + @Builder + public JffOtherManualResponse { + } } diff --git a/src/main/java/com/najasin/domain/manual/service/OthersManualService.java b/src/main/java/com/najasin/domain/manual/service/OthersManualService.java new file mode 100644 index 0000000..39d3253 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/service/OthersManualService.java @@ -0,0 +1,58 @@ +package com.najasin.domain.manual.service; + +import static java.util.Objects.*; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.najasin.domain.manual.dto.param.JffQuestionParam; +import com.najasin.domain.manual.dto.response.JffOtherManualResponse; +import com.najasin.domain.manual.entity.answer.Answer; +import com.najasin.domain.manual.entity.userKeyword.UserKeyword; +import com.najasin.domain.user.dto.param.AnswerParam; +import com.najasin.domain.user.dto.param.CommentParam; +import com.najasin.domain.user.dto.response.MyPageResponse; +import com.najasin.domain.user.entity.User; +import com.najasin.domain.user.entity.userType.UserType; +import com.najasin.domain.user.entity.userType.UserUserType; +import com.najasin.domain.user.service.UserUserTypeService; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class OthersManualService { + private final UserUserTypeService userUserTypeService; + private final QuestionService questionService; + private final AnswerService answerService; + private final UserKeywordService userKeywordService; + private final CommentService commentService; + @Value("${base-image}") + private String baseImage; + + @Transactional(readOnly = true) + public JffOtherManualResponse getJffOtherManual(String userType, String userId) { + UserUserType userUserType = userUserTypeService.findByUserIdAndUserTypeName(userId, userType); + List answers = answerService.findByUserIdAndUserType(userId, userType) + .stream() + .map(Answer::toMyAnswerParam) + .toList(); + List percents = userKeywordService.findByUserId(userId); + List comments = commentService.mapToCommentParam(commentService.findAllByUserId(userId)); + List questions = questionService.findAll(userType); + + return JffOtherManualResponse.builder() + .nickname(userUserType.getNickname()) + .baseImage(baseImage) + .characterItems(userUserType.toMyCharacterItemsParam()) + .questions(questions) + .myManualQAPair(answers) + .othersManualQAPairs(comments) + .originKeywordPercents(percents.stream().map(UserKeyword::toMyKeywordPercentParam).toList()) + .otherKeywordPercents(percents.stream().map(UserKeyword::toOthersKeywordPercentParam).toList()) + .build(); + } +} diff --git a/src/main/java/com/najasin/domain/manual/service/QuestionService.java b/src/main/java/com/najasin/domain/manual/service/QuestionService.java index e1f7769..075c2c4 100644 --- a/src/main/java/com/najasin/domain/manual/service/QuestionService.java +++ b/src/main/java/com/najasin/domain/manual/service/QuestionService.java @@ -27,7 +27,6 @@ public List findAll(String userTypeName) { return questionList.stream().map(Question::toJffMyQuestion).toList(); } - @Transactional(readOnly = true) public List findAllByIdList(List questionIds) { return questionIds.stream().map(this::findById).toList(); } diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 01b9424..573e335 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -58,4 +58,6 @@ jwt: client: host: localhost url: http://localhost:3000 - endpoint: success \ No newline at end of file + endpoint: success + +base-image: test \ No newline at end of file From 9164f9e488e733c06000be610672ddc489591d2b Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 05:31:28 +0900 Subject: [PATCH 22/27] =?UTF-8?q?feature(#48):=20Q=20Class=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/character/entity/QBody.java | 43 ++++++++++++ .../character/entity/QCharacterSet.java | 43 ++++++++++++ .../domain/character/entity/QExpression.java | 43 ++++++++++++ .../domain/character/entity/QFace.java | 43 ++++++++++++ .../domain/manual/entity/answer/QAnswer.java | 54 +++++++++++++++ .../manual/entity/answer/QAnswerId.java | 52 +++++++++++++++ .../manual/entity/comment/QComment.java | 61 +++++++++++++++++ .../manual/entity/comment/QCommentId.java | 52 +++++++++++++++ .../manual/entity/keyword/QKeyword.java | 39 +++++++++++ .../manual/entity/question/QQuestion.java | 55 ++++++++++++++++ .../entity/userKeyword/QUserKeyword.java | 58 ++++++++++++++++ .../entity/userKeyword/QUserKeywordId.java | 52 +++++++++++++++ .../domain/user/entity/QOauth2Entity.java | 43 ++++++++++++ .../com/najasin/domain/user/entity/QUser.java | 61 +++++++++++++++++ .../user/entity/userType/QUserType.java | 42 ++++++++++++ .../user/entity/userType/QUserUserType.java | 66 +++++++++++++++++++ .../user/entity/userType/QUserUserTypeId.java | 52 +++++++++++++++ .../najasin/global/audit/QAuditEntity.java | 39 +++++++++++ 18 files changed, 898 insertions(+) create mode 100644 src/main/generated/com/najasin/domain/character/entity/QBody.java create mode 100644 src/main/generated/com/najasin/domain/character/entity/QCharacterSet.java create mode 100644 src/main/generated/com/najasin/domain/character/entity/QExpression.java create mode 100644 src/main/generated/com/najasin/domain/character/entity/QFace.java create mode 100644 src/main/generated/com/najasin/domain/manual/entity/answer/QAnswer.java create mode 100644 src/main/generated/com/najasin/domain/manual/entity/answer/QAnswerId.java create mode 100644 src/main/generated/com/najasin/domain/manual/entity/comment/QComment.java create mode 100644 src/main/generated/com/najasin/domain/manual/entity/comment/QCommentId.java create mode 100644 src/main/generated/com/najasin/domain/manual/entity/keyword/QKeyword.java create mode 100644 src/main/generated/com/najasin/domain/manual/entity/question/QQuestion.java create mode 100644 src/main/generated/com/najasin/domain/manual/entity/userKeyword/QUserKeyword.java create mode 100644 src/main/generated/com/najasin/domain/manual/entity/userKeyword/QUserKeywordId.java create mode 100644 src/main/generated/com/najasin/domain/user/entity/QOauth2Entity.java create mode 100644 src/main/generated/com/najasin/domain/user/entity/QUser.java create mode 100644 src/main/generated/com/najasin/domain/user/entity/userType/QUserType.java create mode 100644 src/main/generated/com/najasin/domain/user/entity/userType/QUserUserType.java create mode 100644 src/main/generated/com/najasin/domain/user/entity/userType/QUserUserTypeId.java create mode 100644 src/main/generated/com/najasin/global/audit/QAuditEntity.java diff --git a/src/main/generated/com/najasin/domain/character/entity/QBody.java b/src/main/generated/com/najasin/domain/character/entity/QBody.java new file mode 100644 index 0000000..c21511a --- /dev/null +++ b/src/main/generated/com/najasin/domain/character/entity/QBody.java @@ -0,0 +1,43 @@ +package com.najasin.domain.character.entity; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; + + +/** + * QBody is a Querydsl query type for Body + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QBody extends EntityPathBase { + + private static final long serialVersionUID = 1473554379L; + + public static final QBody body = new QBody("body"); + + public final NumberPath id = createNumber("id", Long.class); + + public final StringPath layout_url = createString("layout_url"); + + public final StringPath name = createString("name"); + + public final StringPath show_url = createString("show_url"); + + public QBody(String variable) { + super(Body.class, forVariable(variable)); + } + + public QBody(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QBody(PathMetadata metadata) { + super(Body.class, metadata); + } + +} + diff --git a/src/main/generated/com/najasin/domain/character/entity/QCharacterSet.java b/src/main/generated/com/najasin/domain/character/entity/QCharacterSet.java new file mode 100644 index 0000000..c3a30e0 --- /dev/null +++ b/src/main/generated/com/najasin/domain/character/entity/QCharacterSet.java @@ -0,0 +1,43 @@ +package com.najasin.domain.character.entity; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; + + +/** + * QCharacterSet is a Querydsl query type for CharacterSet + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QCharacterSet extends EntityPathBase { + + private static final long serialVersionUID = 575177122L; + + public static final QCharacterSet characterSet = new QCharacterSet("characterSet"); + + public final NumberPath id = createNumber("id", Long.class); + + public final StringPath layout_url = createString("layout_url"); + + public final StringPath name = createString("name"); + + public final StringPath show_url = createString("show_url"); + + public QCharacterSet(String variable) { + super(CharacterSet.class, forVariable(variable)); + } + + public QCharacterSet(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QCharacterSet(PathMetadata metadata) { + super(CharacterSet.class, metadata); + } + +} + diff --git a/src/main/generated/com/najasin/domain/character/entity/QExpression.java b/src/main/generated/com/najasin/domain/character/entity/QExpression.java new file mode 100644 index 0000000..cd8f9df --- /dev/null +++ b/src/main/generated/com/najasin/domain/character/entity/QExpression.java @@ -0,0 +1,43 @@ +package com.najasin.domain.character.entity; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; + + +/** + * QExpression is a Querydsl query type for Expression + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QExpression extends EntityPathBase { + + private static final long serialVersionUID = 2121727489L; + + public static final QExpression expression = new QExpression("expression"); + + public final NumberPath id = createNumber("id", Long.class); + + public final StringPath layout_url = createString("layout_url"); + + public final StringPath name = createString("name"); + + public final StringPath show_url = createString("show_url"); + + public QExpression(String variable) { + super(Expression.class, forVariable(variable)); + } + + public QExpression(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QExpression(PathMetadata metadata) { + super(Expression.class, metadata); + } + +} + diff --git a/src/main/generated/com/najasin/domain/character/entity/QFace.java b/src/main/generated/com/najasin/domain/character/entity/QFace.java new file mode 100644 index 0000000..8a9aca0 --- /dev/null +++ b/src/main/generated/com/najasin/domain/character/entity/QFace.java @@ -0,0 +1,43 @@ +package com.najasin.domain.character.entity; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; + + +/** + * QFace is a Querydsl query type for Face + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QFace extends EntityPathBase { + + private static final long serialVersionUID = 1473660038L; + + public static final QFace face = new QFace("face"); + + public final NumberPath id = createNumber("id", Long.class); + + public final StringPath layout_url = createString("layout_url"); + + public final StringPath name = createString("name"); + + public final StringPath show_url = createString("show_url"); + + public QFace(String variable) { + super(Face.class, forVariable(variable)); + } + + public QFace(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QFace(PathMetadata metadata) { + super(Face.class, metadata); + } + +} + diff --git a/src/main/generated/com/najasin/domain/manual/entity/answer/QAnswer.java b/src/main/generated/com/najasin/domain/manual/entity/answer/QAnswer.java new file mode 100644 index 0000000..a1de074 --- /dev/null +++ b/src/main/generated/com/najasin/domain/manual/entity/answer/QAnswer.java @@ -0,0 +1,54 @@ +package com.najasin.domain.manual.entity.answer; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QAnswer is a Querydsl query type for Answer + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QAnswer extends EntityPathBase { + + private static final long serialVersionUID = -1108062642L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QAnswer answer = new QAnswer("answer"); + + public final StringPath content = createString("content"); + + public final com.najasin.domain.manual.entity.question.QQuestion question; + + public final com.najasin.domain.user.entity.QUser user; + + public QAnswer(String variable) { + this(Answer.class, forVariable(variable), INITS); + } + + public QAnswer(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QAnswer(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QAnswer(PathMetadata metadata, PathInits inits) { + this(Answer.class, metadata, inits); + } + + public QAnswer(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.question = inits.isInitialized("question") ? new com.najasin.domain.manual.entity.question.QQuestion(forProperty("question"), inits.get("question")) : null; + this.user = inits.isInitialized("user") ? new com.najasin.domain.user.entity.QUser(forProperty("user"), inits.get("user")) : null; + } + +} + diff --git a/src/main/generated/com/najasin/domain/manual/entity/answer/QAnswerId.java b/src/main/generated/com/najasin/domain/manual/entity/answer/QAnswerId.java new file mode 100644 index 0000000..6398464 --- /dev/null +++ b/src/main/generated/com/najasin/domain/manual/entity/answer/QAnswerId.java @@ -0,0 +1,52 @@ +package com.najasin.domain.manual.entity.answer; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QAnswerId is a Querydsl query type for AnswerId + */ +@Generated("com.querydsl.codegen.DefaultEmbeddableSerializer") +public class QAnswerId extends BeanPath { + + private static final long serialVersionUID = 303692809L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QAnswerId answerId = new QAnswerId("answerId"); + + public final com.najasin.domain.manual.entity.question.QQuestion question; + + public final com.najasin.domain.user.entity.QUser user; + + public QAnswerId(String variable) { + this(AnswerId.class, forVariable(variable), INITS); + } + + public QAnswerId(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QAnswerId(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QAnswerId(PathMetadata metadata, PathInits inits) { + this(AnswerId.class, metadata, inits); + } + + public QAnswerId(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.question = inits.isInitialized("question") ? new com.najasin.domain.manual.entity.question.QQuestion(forProperty("question"), inits.get("question")) : null; + this.user = inits.isInitialized("user") ? new com.najasin.domain.user.entity.QUser(forProperty("user"), inits.get("user")) : null; + } + +} + diff --git a/src/main/generated/com/najasin/domain/manual/entity/comment/QComment.java b/src/main/generated/com/najasin/domain/manual/entity/comment/QComment.java new file mode 100644 index 0000000..0874691 --- /dev/null +++ b/src/main/generated/com/najasin/domain/manual/entity/comment/QComment.java @@ -0,0 +1,61 @@ +package com.najasin.domain.manual.entity.comment; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QComment is a Querydsl query type for Comment + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QComment extends EntityPathBase { + + private static final long serialVersionUID = -578980880L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QComment comment = new QComment("comment"); + + public final com.najasin.global.audit.QAuditEntity auditEntity; + + public final StringPath content = createString("content"); + + public final NumberPath id = createNumber("id", Long.class); + + public final StringPath nickname = createString("nickname"); + + public final com.najasin.domain.manual.entity.question.QQuestion question; + + public final com.najasin.domain.user.entity.QUser user; + + public QComment(String variable) { + this(Comment.class, forVariable(variable), INITS); + } + + public QComment(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QComment(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QComment(PathMetadata metadata, PathInits inits) { + this(Comment.class, metadata, inits); + } + + public QComment(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.auditEntity = inits.isInitialized("auditEntity") ? new com.najasin.global.audit.QAuditEntity(forProperty("auditEntity")) : null; + this.question = inits.isInitialized("question") ? new com.najasin.domain.manual.entity.question.QQuestion(forProperty("question"), inits.get("question")) : null; + this.user = inits.isInitialized("user") ? new com.najasin.domain.user.entity.QUser(forProperty("user"), inits.get("user")) : null; + } + +} + diff --git a/src/main/generated/com/najasin/domain/manual/entity/comment/QCommentId.java b/src/main/generated/com/najasin/domain/manual/entity/comment/QCommentId.java new file mode 100644 index 0000000..2cb0df7 --- /dev/null +++ b/src/main/generated/com/najasin/domain/manual/entity/comment/QCommentId.java @@ -0,0 +1,52 @@ +package com.najasin.domain.manual.entity.comment; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QCommentId is a Querydsl query type for CommentId + */ +@Generated("com.querydsl.codegen.DefaultEmbeddableSerializer") +public class QCommentId extends BeanPath { + + private static final long serialVersionUID = 1945125163L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QCommentId commentId = new QCommentId("commentId"); + + public final com.najasin.domain.manual.entity.question.QQuestion question; + + public final com.najasin.domain.user.entity.QUser user; + + public QCommentId(String variable) { + this(CommentId.class, forVariable(variable), INITS); + } + + public QCommentId(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QCommentId(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QCommentId(PathMetadata metadata, PathInits inits) { + this(CommentId.class, metadata, inits); + } + + public QCommentId(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.question = inits.isInitialized("question") ? new com.najasin.domain.manual.entity.question.QQuestion(forProperty("question"), inits.get("question")) : null; + this.user = inits.isInitialized("user") ? new com.najasin.domain.user.entity.QUser(forProperty("user"), inits.get("user")) : null; + } + +} + diff --git a/src/main/generated/com/najasin/domain/manual/entity/keyword/QKeyword.java b/src/main/generated/com/najasin/domain/manual/entity/keyword/QKeyword.java new file mode 100644 index 0000000..71af0f2 --- /dev/null +++ b/src/main/generated/com/najasin/domain/manual/entity/keyword/QKeyword.java @@ -0,0 +1,39 @@ +package com.najasin.domain.manual.entity.keyword; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; + + +/** + * QKeyword is a Querydsl query type for Keyword + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QKeyword extends EntityPathBase { + + private static final long serialVersionUID = 1231071492L; + + public static final QKeyword keyword = new QKeyword("keyword"); + + public final NumberPath id = createNumber("id", Long.class); + + public final StringPath name = createString("name"); + + public QKeyword(String variable) { + super(Keyword.class, forVariable(variable)); + } + + public QKeyword(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QKeyword(PathMetadata metadata) { + super(Keyword.class, metadata); + } + +} + diff --git a/src/main/generated/com/najasin/domain/manual/entity/question/QQuestion.java b/src/main/generated/com/najasin/domain/manual/entity/question/QQuestion.java new file mode 100644 index 0000000..4bba2ed --- /dev/null +++ b/src/main/generated/com/najasin/domain/manual/entity/question/QQuestion.java @@ -0,0 +1,55 @@ +package com.najasin.domain.manual.entity.question; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QQuestion is a Querydsl query type for Question + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QQuestion extends EntityPathBase { + + private static final long serialVersionUID = -462846130L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QQuestion question1 = new QQuestion("question1"); + + public final NumberPath id = createNumber("id", Long.class); + + public final StringPath question = createString("question"); + + public final EnumPath questionType = createEnum("questionType", QuestionType.class); + + public final com.najasin.domain.user.entity.userType.QUserType userType; + + public QQuestion(String variable) { + this(Question.class, forVariable(variable), INITS); + } + + public QQuestion(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QQuestion(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QQuestion(PathMetadata metadata, PathInits inits) { + this(Question.class, metadata, inits); + } + + public QQuestion(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.userType = inits.isInitialized("userType") ? new com.najasin.domain.user.entity.userType.QUserType(forProperty("userType")) : null; + } + +} + diff --git a/src/main/generated/com/najasin/domain/manual/entity/userKeyword/QUserKeyword.java b/src/main/generated/com/najasin/domain/manual/entity/userKeyword/QUserKeyword.java new file mode 100644 index 0000000..9d404b5 --- /dev/null +++ b/src/main/generated/com/najasin/domain/manual/entity/userKeyword/QUserKeyword.java @@ -0,0 +1,58 @@ +package com.najasin.domain.manual.entity.userKeyword; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QUserKeyword is a Querydsl query type for UserKeyword + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QUserKeyword extends EntityPathBase { + + private static final long serialVersionUID = 1728339822L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QUserKeyword userKeyword = new QUserKeyword("userKeyword"); + + public final com.najasin.domain.manual.entity.keyword.QKeyword keyword; + + public final NumberPath originPercent = createNumber("originPercent", Integer.class); + + public final NumberPath othersCount = createNumber("othersCount", Integer.class); + + public final NumberPath othersPercent = createNumber("othersPercent", Integer.class); + + public final com.najasin.domain.user.entity.QUser user; + + public QUserKeyword(String variable) { + this(UserKeyword.class, forVariable(variable), INITS); + } + + public QUserKeyword(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QUserKeyword(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QUserKeyword(PathMetadata metadata, PathInits inits) { + this(UserKeyword.class, metadata, inits); + } + + public QUserKeyword(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.keyword = inits.isInitialized("keyword") ? new com.najasin.domain.manual.entity.keyword.QKeyword(forProperty("keyword")) : null; + this.user = inits.isInitialized("user") ? new com.najasin.domain.user.entity.QUser(forProperty("user"), inits.get("user")) : null; + } + +} + diff --git a/src/main/generated/com/najasin/domain/manual/entity/userKeyword/QUserKeywordId.java b/src/main/generated/com/najasin/domain/manual/entity/userKeyword/QUserKeywordId.java new file mode 100644 index 0000000..9f99b01 --- /dev/null +++ b/src/main/generated/com/najasin/domain/manual/entity/userKeyword/QUserKeywordId.java @@ -0,0 +1,52 @@ +package com.najasin.domain.manual.entity.userKeyword; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QUserKeywordId is a Querydsl query type for UserKeywordId + */ +@Generated("com.querydsl.codegen.DefaultEmbeddableSerializer") +public class QUserKeywordId extends BeanPath { + + private static final long serialVersionUID = -1217772247L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QUserKeywordId userKeywordId = new QUserKeywordId("userKeywordId"); + + public final com.najasin.domain.manual.entity.keyword.QKeyword keyword; + + public final com.najasin.domain.user.entity.QUser user; + + public QUserKeywordId(String variable) { + this(UserKeywordId.class, forVariable(variable), INITS); + } + + public QUserKeywordId(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QUserKeywordId(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QUserKeywordId(PathMetadata metadata, PathInits inits) { + this(UserKeywordId.class, metadata, inits); + } + + public QUserKeywordId(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.keyword = inits.isInitialized("keyword") ? new com.najasin.domain.manual.entity.keyword.QKeyword(forProperty("keyword")) : null; + this.user = inits.isInitialized("user") ? new com.najasin.domain.user.entity.QUser(forProperty("user"), inits.get("user")) : null; + } + +} + diff --git a/src/main/generated/com/najasin/domain/user/entity/QOauth2Entity.java b/src/main/generated/com/najasin/domain/user/entity/QOauth2Entity.java new file mode 100644 index 0000000..e9cb9dd --- /dev/null +++ b/src/main/generated/com/najasin/domain/user/entity/QOauth2Entity.java @@ -0,0 +1,43 @@ +package com.najasin.domain.user.entity; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; + + +/** + * QOauth2Entity is a Querydsl query type for Oauth2Entity + */ +@Generated("com.querydsl.codegen.DefaultEmbeddableSerializer") +public class QOauth2Entity extends BeanPath { + + private static final long serialVersionUID = 1912136931L; + + public static final QOauth2Entity oauth2Entity = new QOauth2Entity("oauth2Entity"); + + public final StringPath email = createString("email"); + + public final EnumPath provider = createEnum("provider", com.najasin.domain.user.entity.enums.Provider.class); + + public final StringPath providerId = createString("providerId"); + + public final StringPath providerUsername = createString("providerUsername"); + + public QOauth2Entity(String variable) { + super(Oauth2Entity.class, forVariable(variable)); + } + + public QOauth2Entity(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QOauth2Entity(PathMetadata metadata) { + super(Oauth2Entity.class, metadata); + } + +} + diff --git a/src/main/generated/com/najasin/domain/user/entity/QUser.java b/src/main/generated/com/najasin/domain/user/entity/QUser.java new file mode 100644 index 0000000..d7ec8b7 --- /dev/null +++ b/src/main/generated/com/najasin/domain/user/entity/QUser.java @@ -0,0 +1,61 @@ +package com.najasin.domain.user.entity; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QUser is a Querydsl query type for User + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QUser extends EntityPathBase { + + private static final long serialVersionUID = -1225049744L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QUser user = new QUser("user"); + + public final com.najasin.global.audit.QAuditEntity auditEntity; + + public final StringPath id = createString("id"); + + public final com.najasin.domain.user.entity.userType.QUserType lastUserType; + + public final QOauth2Entity oauth2Entity; + + public final ListPath> role = this.>createList("role", com.najasin.domain.user.entity.enums.Role.class, EnumPath.class, PathInits.DIRECT2); + + public final ListPath userUserTypes = this.createList("userUserTypes", com.najasin.domain.user.entity.userType.UserUserType.class, com.najasin.domain.user.entity.userType.QUserUserType.class, PathInits.DIRECT2); + + public QUser(String variable) { + this(User.class, forVariable(variable), INITS); + } + + public QUser(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QUser(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QUser(PathMetadata metadata, PathInits inits) { + this(User.class, metadata, inits); + } + + public QUser(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.auditEntity = inits.isInitialized("auditEntity") ? new com.najasin.global.audit.QAuditEntity(forProperty("auditEntity")) : null; + this.lastUserType = inits.isInitialized("lastUserType") ? new com.najasin.domain.user.entity.userType.QUserType(forProperty("lastUserType")) : null; + this.oauth2Entity = inits.isInitialized("oauth2Entity") ? new QOauth2Entity(forProperty("oauth2Entity")) : null; + } + +} + diff --git a/src/main/generated/com/najasin/domain/user/entity/userType/QUserType.java b/src/main/generated/com/najasin/domain/user/entity/userType/QUserType.java new file mode 100644 index 0000000..5a0061d --- /dev/null +++ b/src/main/generated/com/najasin/domain/user/entity/userType/QUserType.java @@ -0,0 +1,42 @@ +package com.najasin.domain.user.entity.userType; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QUserType is a Querydsl query type for UserType + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QUserType extends EntityPathBase { + + private static final long serialVersionUID = 72279689L; + + public static final QUserType userType = new QUserType("userType"); + + public final NumberPath id = createNumber("id", Long.class); + + public final StringPath name = createString("name"); + + public final ListPath userUserTypes = this.createList("userUserTypes", UserUserType.class, QUserUserType.class, PathInits.DIRECT2); + + public QUserType(String variable) { + super(UserType.class, forVariable(variable)); + } + + public QUserType(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QUserType(PathMetadata metadata) { + super(UserType.class, metadata); + } + +} + diff --git a/src/main/generated/com/najasin/domain/user/entity/userType/QUserUserType.java b/src/main/generated/com/najasin/domain/user/entity/userType/QUserUserType.java new file mode 100644 index 0000000..f7cefc2 --- /dev/null +++ b/src/main/generated/com/najasin/domain/user/entity/userType/QUserUserType.java @@ -0,0 +1,66 @@ +package com.najasin.domain.user.entity.userType; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QUserUserType is a Querydsl query type for UserUserType + */ +@Generated("com.querydsl.codegen.DefaultEntitySerializer") +public class QUserUserType extends EntityPathBase { + + private static final long serialVersionUID = -158586508L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QUserUserType userUserType = new QUserUserType("userUserType"); + + public final com.najasin.domain.character.entity.QBody body; + + public final com.najasin.domain.character.entity.QExpression expression; + + public final com.najasin.domain.character.entity.QFace face; + + public final StringPath nickname = createString("nickname"); + + public final com.najasin.domain.character.entity.QCharacterSet set; + + public final com.najasin.domain.user.entity.QUser user; + + public final QUserType userType; + + public QUserUserType(String variable) { + this(UserUserType.class, forVariable(variable), INITS); + } + + public QUserUserType(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QUserUserType(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QUserUserType(PathMetadata metadata, PathInits inits) { + this(UserUserType.class, metadata, inits); + } + + public QUserUserType(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.body = inits.isInitialized("body") ? new com.najasin.domain.character.entity.QBody(forProperty("body")) : null; + this.expression = inits.isInitialized("expression") ? new com.najasin.domain.character.entity.QExpression(forProperty("expression")) : null; + this.face = inits.isInitialized("face") ? new com.najasin.domain.character.entity.QFace(forProperty("face")) : null; + this.set = inits.isInitialized("set") ? new com.najasin.domain.character.entity.QCharacterSet(forProperty("set")) : null; + this.user = inits.isInitialized("user") ? new com.najasin.domain.user.entity.QUser(forProperty("user"), inits.get("user")) : null; + this.userType = inits.isInitialized("userType") ? new QUserType(forProperty("userType")) : null; + } + +} + diff --git a/src/main/generated/com/najasin/domain/user/entity/userType/QUserUserTypeId.java b/src/main/generated/com/najasin/domain/user/entity/userType/QUserUserTypeId.java new file mode 100644 index 0000000..838f79c --- /dev/null +++ b/src/main/generated/com/najasin/domain/user/entity/userType/QUserUserTypeId.java @@ -0,0 +1,52 @@ +package com.najasin.domain.user.entity.userType; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.PathInits; + + +/** + * QUserUserTypeId is a Querydsl query type for UserUserTypeId + */ +@Generated("com.querydsl.codegen.DefaultEmbeddableSerializer") +public class QUserUserTypeId extends BeanPath { + + private static final long serialVersionUID = -2077776465L; + + private static final PathInits INITS = PathInits.DIRECT2; + + public static final QUserUserTypeId userUserTypeId = new QUserUserTypeId("userUserTypeId"); + + public final com.najasin.domain.user.entity.QUser user; + + public final QUserType userType; + + public QUserUserTypeId(String variable) { + this(UserUserTypeId.class, forVariable(variable), INITS); + } + + public QUserUserTypeId(Path path) { + this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); + } + + public QUserUserTypeId(PathMetadata metadata) { + this(metadata, PathInits.getFor(metadata, INITS)); + } + + public QUserUserTypeId(PathMetadata metadata, PathInits inits) { + this(UserUserTypeId.class, metadata, inits); + } + + public QUserUserTypeId(Class type, PathMetadata metadata, PathInits inits) { + super(type, metadata, inits); + this.user = inits.isInitialized("user") ? new com.najasin.domain.user.entity.QUser(forProperty("user"), inits.get("user")) : null; + this.userType = inits.isInitialized("userType") ? new QUserType(forProperty("userType")) : null; + } + +} + diff --git a/src/main/generated/com/najasin/global/audit/QAuditEntity.java b/src/main/generated/com/najasin/global/audit/QAuditEntity.java new file mode 100644 index 0000000..dd0e930 --- /dev/null +++ b/src/main/generated/com/najasin/global/audit/QAuditEntity.java @@ -0,0 +1,39 @@ +package com.najasin.global.audit; + +import static com.querydsl.core.types.PathMetadataFactory.*; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.PathMetadata; +import javax.annotation.processing.Generated; +import com.querydsl.core.types.Path; + + +/** + * QAuditEntity is a Querydsl query type for AuditEntity + */ +@Generated("com.querydsl.codegen.DefaultEmbeddableSerializer") +public class QAuditEntity extends BeanPath { + + private static final long serialVersionUID = -953092435L; + + public static final QAuditEntity auditEntity = new QAuditEntity("auditEntity"); + + public final DateTimePath createdAt = createDateTime("createdAt", java.time.LocalDateTime.class); + + public final DateTimePath updatedAt = createDateTime("updatedAt", java.time.LocalDateTime.class); + + public QAuditEntity(String variable) { + super(AuditEntity.class, forVariable(variable)); + } + + public QAuditEntity(Path path) { + super(path.getType(), path.getMetadata()); + } + + public QAuditEntity(PathMetadata metadata) { + super(AuditEntity.class, metadata); + } + +} + From 6cad0a0f8759980310ce6855cd599ce23d9dd3dd Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 05:31:52 +0900 Subject: [PATCH 23/27] =?UTF-8?q?feature(#48):=20Others=20Manual=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manual/controller/MyManualController.java | 2 +- .../controller/OthersManualController.java | 15 ++++++++++++++- .../manual/dto/param/JffCommentParam.java | 17 +++++++++++++++++ .../request/OthersManualCreateRequest.java | 11 +++++++++++ .../domain/manual/entity/answer/Answer.java | 9 ++++++++- .../domain/manual/entity/comment/Comment.java | 8 ++++++++ .../domain/manual/service/CommentService.java | 19 +++++++++++++++++++ .../manual/service/OthersManualService.java | 16 +++++++++++++++- .../manual/service/QuestionService.java | 6 ++++-- 9 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/najasin/domain/manual/dto/param/JffCommentParam.java create mode 100644 src/main/java/com/najasin/domain/manual/dto/request/OthersManualCreateRequest.java diff --git a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java index 4bcc3ad..6b43fa8 100644 --- a/src/main/java/com/najasin/domain/manual/controller/MyManualController.java +++ b/src/main/java/com/najasin/domain/manual/controller/MyManualController.java @@ -55,7 +55,7 @@ public ResponseEntity> getMyManual(@PathVariabl CharacterItemsParam characterItems = characterService.findAllItems(); // 추후에 다른 분기에 대한 처리 필요 - List questionList = questionService.findAll(userType); + List questionList = questionService.mapToJffQuestions(questionService.findAll(userType)); List keywordList = keywordService.findAll(); return ResponseEntity.ok(createSuccessWithData( diff --git a/src/main/java/com/najasin/domain/manual/controller/OthersManualController.java b/src/main/java/com/najasin/domain/manual/controller/OthersManualController.java index 02dc3c8..1efca49 100644 --- a/src/main/java/com/najasin/domain/manual/controller/OthersManualController.java +++ b/src/main/java/com/najasin/domain/manual/controller/OthersManualController.java @@ -7,12 +7,17 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.najasin.domain.manual.dto.request.OthersManualCreateRequest; import com.najasin.domain.manual.dto.response.JffOtherManualResponse; +import com.najasin.domain.manual.service.CommentService; import com.najasin.domain.manual.service.OthersManualService; +import com.najasin.domain.user.entity.User; +import com.najasin.domain.user.service.UserService; import com.najasin.global.response.ApiResponse; import lombok.RequiredArgsConstructor; @@ -22,6 +27,8 @@ @RequestMapping("/api/{userType}/others-manual") public class OthersManualController { private final OthersManualService othersManualService; + private final UserService userService; + private final CommentService commentService; @GetMapping public ResponseEntity> getOthersManual( @@ -33,7 +40,13 @@ public ResponseEntity> getOthersManual( } @PostMapping - public ResponseEntity> saveOthersManual(@PathVariable String userType) { + public ResponseEntity> saveOthersManual( + @PathVariable String userType, + @RequestParam(required = true, value = "userId") String userId, + @RequestBody OthersManualCreateRequest request) { + User user = userService.findById(userId); + + othersManualService.saveOthersManual(request, userType, user); return null; } } diff --git a/src/main/java/com/najasin/domain/manual/dto/param/JffCommentParam.java b/src/main/java/com/najasin/domain/manual/dto/param/JffCommentParam.java new file mode 100644 index 0000000..df3d8be --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/param/JffCommentParam.java @@ -0,0 +1,17 @@ +package com.najasin.domain.manual.dto.param; + +import com.najasin.domain.manual.entity.comment.Comment; +import com.najasin.domain.manual.entity.question.Question; +import com.najasin.domain.user.entity.User; + +public record JffCommentParam(Long id, + String answer) { + public Comment toCommentEntity(User user, Question question, String nickname) { + return Comment.builder() + .user(user) + .question(question) + .content(answer) + .nickname(nickname) + .build(); + } +} diff --git a/src/main/java/com/najasin/domain/manual/dto/request/OthersManualCreateRequest.java b/src/main/java/com/najasin/domain/manual/dto/request/OthersManualCreateRequest.java new file mode 100644 index 0000000..6055e12 --- /dev/null +++ b/src/main/java/com/najasin/domain/manual/dto/request/OthersManualCreateRequest.java @@ -0,0 +1,11 @@ +package com.najasin.domain.manual.dto.request; + +import java.util.List; + +import com.najasin.domain.manual.dto.param.JffCommentParam; +import com.najasin.domain.manual.dto.param.JffKeywordParam; + +public record OthersManualCreateRequest(String nickname, + List answers, + List otherKeywordPercents) { +} diff --git a/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java b/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java index 374e0fc..35635da 100644 --- a/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java +++ b/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java @@ -7,13 +7,13 @@ import jakarta.persistence.*; import lombok.AccessLevel; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor @IdClass(AnswerId.class) public class Answer { @Id @@ -29,6 +29,13 @@ public class Answer { @Column(name = "content") private String content; + @Builder + public Answer(User user, Question question, String content) { + this.user = user; + this.question = question; + this.content = content; + } + public Long getQuestionId() { return question.getId(); } diff --git a/src/main/java/com/najasin/domain/manual/entity/comment/Comment.java b/src/main/java/com/najasin/domain/manual/entity/comment/Comment.java index 60b8654..77ec604 100644 --- a/src/main/java/com/najasin/domain/manual/entity/comment/Comment.java +++ b/src/main/java/com/najasin/domain/manual/entity/comment/Comment.java @@ -40,6 +40,14 @@ public class Comment { @Embedded private AuditEntity auditEntity; + @Builder + public Comment(User user, Question question, String content, String nickname) { + this.user = user; + this.question = question; + this.content = content; + this.nickname = nickname; + } + public AnswerParam toAnswerParam() { return new AnswerParam(question.getId(), question.getQuestion(), content); } diff --git a/src/main/java/com/najasin/domain/manual/service/CommentService.java b/src/main/java/com/najasin/domain/manual/service/CommentService.java index 91c9807..f1851c5 100644 --- a/src/main/java/com/najasin/domain/manual/service/CommentService.java +++ b/src/main/java/com/najasin/domain/manual/service/CommentService.java @@ -1,6 +1,7 @@ package com.najasin.domain.manual.service; import java.util.ArrayList; +import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -8,7 +9,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.najasin.domain.manual.dto.param.JffAnswerParam; +import com.najasin.domain.manual.dto.param.JffCommentParam; import com.najasin.domain.manual.entity.comment.Comment; +import com.najasin.domain.manual.entity.question.Question; import com.najasin.domain.manual.repository.CommentRepository; import com.najasin.domain.user.dto.param.AnswerParam; import com.najasin.domain.user.dto.param.CommentParam; @@ -21,6 +25,21 @@ public class CommentService { private final CommentRepository commentRepository; + @Transactional + public void saveAll(List comments, List questions, User user, String nickname) { + comments.sort(Comparator.comparing(JffCommentParam::id)); + questions.sort(Comparator.comparing(Question::getId)); + + for (int i = 0; i < comments.size(); i++) { + save(comments.get(i).toCommentEntity(user, questions.get(i), nickname)); + } + } + + @Transactional + public Comment save(Comment comment) { + return commentRepository.save(comment); + } + public List mapToCommentParam(List comments) { Map> map = new LinkedHashMap<>(); diff --git a/src/main/java/com/najasin/domain/manual/service/OthersManualService.java b/src/main/java/com/najasin/domain/manual/service/OthersManualService.java index 39d3253..e91b7b6 100644 --- a/src/main/java/com/najasin/domain/manual/service/OthersManualService.java +++ b/src/main/java/com/najasin/domain/manual/service/OthersManualService.java @@ -2,15 +2,19 @@ import static java.util.Objects.*; +import java.util.Comparator; import java.util.List; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.najasin.domain.manual.dto.param.JffCommentParam; import com.najasin.domain.manual.dto.param.JffQuestionParam; +import com.najasin.domain.manual.dto.request.OthersManualCreateRequest; import com.najasin.domain.manual.dto.response.JffOtherManualResponse; import com.najasin.domain.manual.entity.answer.Answer; +import com.najasin.domain.manual.entity.question.Question; import com.najasin.domain.manual.entity.userKeyword.UserKeyword; import com.najasin.domain.user.dto.param.AnswerParam; import com.najasin.domain.user.dto.param.CommentParam; @@ -42,7 +46,7 @@ public JffOtherManualResponse getJffOtherManual(String userType, String userId) .toList(); List percents = userKeywordService.findByUserId(userId); List comments = commentService.mapToCommentParam(commentService.findAllByUserId(userId)); - List questions = questionService.findAll(userType); + List questions = questionService.mapToJffQuestions(questionService.findAll(userType)); return JffOtherManualResponse.builder() .nickname(userUserType.getNickname()) @@ -55,4 +59,14 @@ public JffOtherManualResponse getJffOtherManual(String userType, String userId) .otherKeywordPercents(percents.stream().map(UserKeyword::toOthersKeywordPercentParam).toList()) .build(); } + + @Transactional + public void saveOthersManual(OthersManualCreateRequest request, String userType, User user) { + List questions = questionService.findAll(userType); + + questions.sort(Comparator.comparing(Question::getId)); + request.answers().sort(Comparator.comparing(JffCommentParam::id)); + + commentService.saveAll(request.answers(), questions, user, request.nickname()); + } } diff --git a/src/main/java/com/najasin/domain/manual/service/QuestionService.java b/src/main/java/com/najasin/domain/manual/service/QuestionService.java index 075c2c4..3fd802b 100644 --- a/src/main/java/com/najasin/domain/manual/service/QuestionService.java +++ b/src/main/java/com/najasin/domain/manual/service/QuestionService.java @@ -21,9 +21,11 @@ public class QuestionService { private final QuestionRepository questionRepository; @Transactional(readOnly = true) - public List findAll(String userTypeName) { - List questionList = questionRepository.findAllByQuestionTypeAndUserTypeName(FOR_USER, userTypeName); + public List findAll(String userTypeName) { + return questionRepository.findAllByQuestionTypeAndUserTypeName(FOR_USER, userTypeName); + } + public List mapToJffQuestions(List questionList) { return questionList.stream().map(Question::toJffMyQuestion).toList(); } From 52643007143439540d53743d3acd812e4c1a6df9 Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 05:55:22 +0900 Subject: [PATCH 24/27] =?UTF-8?q?feature(#48):=20Others=20Manual=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OthersManualController.java | 7 ++++-- .../manual/dto/message/ManualMessage.java | 3 ++- .../request/OthersManualCreateRequest.java | 4 ++-- .../entity/userKeyword/UserKeyword.java | 22 +++++++++++++++---- .../manual/service/OthersManualService.java | 7 +++++- .../manual/service/UserKeywordService.java | 14 ++++++++++++ 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/najasin/domain/manual/controller/OthersManualController.java b/src/main/java/com/najasin/domain/manual/controller/OthersManualController.java index 1efca49..1055908 100644 --- a/src/main/java/com/najasin/domain/manual/controller/OthersManualController.java +++ b/src/main/java/com/najasin/domain/manual/controller/OthersManualController.java @@ -3,6 +3,7 @@ import static com.najasin.domain.manual.dto.message.ManualMessage.*; import static com.najasin.global.response.ApiResponse.*; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -45,8 +46,10 @@ public ResponseEntity> saveOthersManual( @RequestParam(required = true, value = "userId") String userId, @RequestBody OthersManualCreateRequest request) { User user = userService.findById(userId); - othersManualService.saveOthersManual(request, userType, user); - return null; + return new ResponseEntity<>( + createSuccess(CREATE_OTHERS_MANUAL_SUCCESS.getMsg()), + HttpStatus.CREATED + ); } } diff --git a/src/main/java/com/najasin/domain/manual/dto/message/ManualMessage.java b/src/main/java/com/najasin/domain/manual/dto/message/ManualMessage.java index 728ae3e..a4d769c 100644 --- a/src/main/java/com/najasin/domain/manual/dto/message/ManualMessage.java +++ b/src/main/java/com/najasin/domain/manual/dto/message/ManualMessage.java @@ -8,6 +8,7 @@ public enum ManualMessage { FIND_MY_MANUAL_SUCCESS("my manual 조회에 성공했습니다."), CREATE_MY_MANUAL_SUCCESS("my manual 생성에 성공했습니다."), - FIND_OTHERS_MANUAL_SUCCESS("others manual 조회에 성공했습니다."); + FIND_OTHERS_MANUAL_SUCCESS("others manual 조회에 성공했습니다."), + CREATE_OTHERS_MANUAL_SUCCESS("others manual 생성에 성공했습니다."); private final String msg; } diff --git a/src/main/java/com/najasin/domain/manual/dto/request/OthersManualCreateRequest.java b/src/main/java/com/najasin/domain/manual/dto/request/OthersManualCreateRequest.java index 6055e12..0e93559 100644 --- a/src/main/java/com/najasin/domain/manual/dto/request/OthersManualCreateRequest.java +++ b/src/main/java/com/najasin/domain/manual/dto/request/OthersManualCreateRequest.java @@ -3,9 +3,9 @@ import java.util.List; import com.najasin.domain.manual.dto.param.JffCommentParam; -import com.najasin.domain.manual.dto.param.JffKeywordParam; +import com.najasin.domain.manual.dto.param.JffKeywordPercentParam; public record OthersManualCreateRequest(String nickname, List answers, - List otherKeywordPercents) { + List otherKeywordPercents) { } diff --git a/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java b/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java index 13b0718..c2b9c9e 100644 --- a/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java +++ b/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java @@ -27,20 +27,34 @@ public class UserKeyword { private Keyword keyword; @Column - private int originPercent; + private Integer originPercent; @Column - private int othersPercent; + private Integer othersPercent; @Column - private int othersCount; + private Integer othersCount; public UserKeyword(User user, Keyword keyword, int originPercent) { this.user = user; this.keyword = keyword; this.originPercent = originPercent; this.othersPercent = 0; - this.othersCount = 0; + this.othersCount = 1; + } + + public void updateOthersPercent(int othersPercent) { + this.othersCount++; + + if(this.othersCount == 2) { + this.othersPercent += this.originPercent; + } + + this.othersPercent = (this.othersPercent +othersPercent) / this.othersCount; + } + + public Long getKeyWordId() { + return keyword.getId(); } public KeywordPercentParam toMyKeywordPercentParam() { diff --git a/src/main/java/com/najasin/domain/manual/service/OthersManualService.java b/src/main/java/com/najasin/domain/manual/service/OthersManualService.java index e91b7b6..9e88cb5 100644 --- a/src/main/java/com/najasin/domain/manual/service/OthersManualService.java +++ b/src/main/java/com/najasin/domain/manual/service/OthersManualService.java @@ -10,6 +10,7 @@ import org.springframework.transaction.annotation.Transactional; import com.najasin.domain.manual.dto.param.JffCommentParam; +import com.najasin.domain.manual.dto.param.JffKeywordPercentParam; import com.najasin.domain.manual.dto.param.JffQuestionParam; import com.najasin.domain.manual.dto.request.OthersManualCreateRequest; import com.najasin.domain.manual.dto.response.JffOtherManualResponse; @@ -66,7 +67,11 @@ public void saveOthersManual(OthersManualCreateRequest request, String userType, questions.sort(Comparator.comparing(Question::getId)); request.answers().sort(Comparator.comparing(JffCommentParam::id)); - commentService.saveAll(request.answers(), questions, user, request.nickname()); + + List userKeywords = userKeywordService.findByUserId(user.getId()); + userKeywords.sort(Comparator.comparing(UserKeyword::getKeyWordId)); + request.otherKeywordPercents().sort(Comparator.comparing(JffKeywordPercentParam::id)); + userKeywordService.updateAllOthersPercent(request.otherKeywordPercents(), userKeywords); } } diff --git a/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java b/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java index 91cee32..f066f7d 100644 --- a/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java +++ b/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java @@ -34,6 +34,20 @@ public UserKeyword save(UserKeyword userKeyword) { return userKeywordRepository.save(userKeyword); } + @Transactional + public void updateAllOthersPercent( + List otherKeywordPercents, + List userKeywords) { + for(int i=0 ; i findByUserId(String userId) { return userKeywordRepository.findByUserId(userId); From 4fb674cfca73fd0718aea7c8d273909547e9c6fa Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 06:10:03 +0900 Subject: [PATCH 25/27] =?UTF-8?q?fix(#48):=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=A0=95=EB=A0=AC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/najasin/domain/manual/service/AnswerService.java | 1 - .../com/najasin/domain/manual/service/UserKeywordService.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/com/najasin/domain/manual/service/AnswerService.java b/src/main/java/com/najasin/domain/manual/service/AnswerService.java index 5afbfa5..5e2f218 100644 --- a/src/main/java/com/najasin/domain/manual/service/AnswerService.java +++ b/src/main/java/com/najasin/domain/manual/service/AnswerService.java @@ -23,7 +23,6 @@ public class AnswerService { @Transactional public void saveAll(List answers, List questions, User user) { answers.sort(Comparator.comparing(JffAnswerParam::id)); - questions.sort(Comparator.comparing(Question::getId)); for (int i = 0; i < answers.size(); i++) { save(answers.get(i).toAnswerEntity(user, questions.get(i))); diff --git a/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java b/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java index f066f7d..581db54 100644 --- a/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java +++ b/src/main/java/com/najasin/domain/manual/service/UserKeywordService.java @@ -22,7 +22,6 @@ public class UserKeywordService { @Transactional public void saveAll(List keywordPercents, List keywords, User user) { keywordPercents.sort(Comparator.comparing(JffKeywordPercentParam::id)); - keywords.sort(Comparator.comparing(Keyword::getId)); for (int i = 0; i < keywordPercents.size(); i++) { save(keywordPercents.get(i).toUserKeywordEntity(user, keywords.get(i))); From 2140ae823139735ac0d08bc028048ce31a169e17 Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 06:56:37 +0900 Subject: [PATCH 26/27] =?UTF-8?q?fix(#48):=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EB=8F=84=EC=A4=91=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/najasin/domain/manual/entity/answer/Answer.java | 4 ---- .../domain/manual/entity/userKeyword/UserKeyword.java | 2 +- .../com/najasin/domain/manual/service/AnswerService.java | 5 ++--- .../com/najasin/domain/manual/service/CommentService.java | 1 - .../najasin/domain/manual/service/OthersManualService.java | 2 -- .../com/najasin/domain/user/controller/UserController.java | 4 ++-- .../najasin/domain/user/dto/request/AnswerUpdateRequest.java | 2 +- src/main/java/com/najasin/security/jwt/util/JwtProvider.java | 4 ++-- src/main/resources/application-local.yml | 2 +- src/main/resources/application-prod.yml | 2 +- 10 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java b/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java index 35635da..fb55961 100644 --- a/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java +++ b/src/main/java/com/najasin/domain/manual/entity/answer/Answer.java @@ -36,10 +36,6 @@ public Answer(User user, Question question, String content) { this.content = content; } - public Long getQuestionId() { - return question.getId(); - } - public void updateAnswer(String content) { this.content = content; } diff --git a/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java b/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java index c2b9c9e..9769ed3 100644 --- a/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java +++ b/src/main/java/com/najasin/domain/manual/entity/userKeyword/UserKeyword.java @@ -62,6 +62,6 @@ public KeywordPercentParam toMyKeywordPercentParam() { } public KeywordPercentParam toOthersKeywordPercentParam() { - return new KeywordPercentParam(keyword.getId(), keyword.getName(), othersCount); + return new KeywordPercentParam(keyword.getId(), keyword.getName(), othersPercent); } } diff --git a/src/main/java/com/najasin/domain/manual/service/AnswerService.java b/src/main/java/com/najasin/domain/manual/service/AnswerService.java index 5e2f218..4c6ae08 100644 --- a/src/main/java/com/najasin/domain/manual/service/AnswerService.java +++ b/src/main/java/com/najasin/domain/manual/service/AnswerService.java @@ -37,8 +37,7 @@ public Answer save(Answer answer) { @Transactional public void updateAnswer(List updateAnswers, String userId, String userType) { List answers = findByUserIdAndUserType(userId, userType); - - answers.sort(Comparator.comparing(Answer::getQuestionId)); + System.out.println(answers.size()); updateAnswers.sort(Comparator.comparing(AnswerUpdateParam::id)); for(int i=0 ; i findByUserIdAndUserType(String userId, String userType) { List answers = answerRepository.findByUserId(userId); return answers.stream() - .filter((answer -> answer.getQuestion().getQuestion().equals(userType.toUpperCase()))) + .filter((answer -> answer.getQuestion().getUserType().getName().equals(userType.toUpperCase()))) .toList(); } } diff --git a/src/main/java/com/najasin/domain/manual/service/CommentService.java b/src/main/java/com/najasin/domain/manual/service/CommentService.java index f1851c5..1d3ba05 100644 --- a/src/main/java/com/najasin/domain/manual/service/CommentService.java +++ b/src/main/java/com/najasin/domain/manual/service/CommentService.java @@ -27,7 +27,6 @@ public class CommentService { @Transactional public void saveAll(List comments, List questions, User user, String nickname) { - comments.sort(Comparator.comparing(JffCommentParam::id)); questions.sort(Comparator.comparing(Question::getId)); for (int i = 0; i < comments.size(); i++) { diff --git a/src/main/java/com/najasin/domain/manual/service/OthersManualService.java b/src/main/java/com/najasin/domain/manual/service/OthersManualService.java index 9e88cb5..4f37f19 100644 --- a/src/main/java/com/najasin/domain/manual/service/OthersManualService.java +++ b/src/main/java/com/najasin/domain/manual/service/OthersManualService.java @@ -66,12 +66,10 @@ public void saveOthersManual(OthersManualCreateRequest request, String userType, List questions = questionService.findAll(userType); questions.sort(Comparator.comparing(Question::getId)); - request.answers().sort(Comparator.comparing(JffCommentParam::id)); commentService.saveAll(request.answers(), questions, user, request.nickname()); List userKeywords = userKeywordService.findByUserId(user.getId()); userKeywords.sort(Comparator.comparing(UserKeyword::getKeyWordId)); - request.otherKeywordPercents().sort(Comparator.comparing(JffKeywordPercentParam::id)); userKeywordService.updateAllOthersPercent(request.otherKeywordPercents(), userKeywords); } } diff --git a/src/main/java/com/najasin/domain/user/controller/UserController.java b/src/main/java/com/najasin/domain/user/controller/UserController.java index 14a3c65..9d416ff 100644 --- a/src/main/java/com/najasin/domain/user/controller/UserController.java +++ b/src/main/java/com/najasin/domain/user/controller/UserController.java @@ -39,7 +39,7 @@ public class UserController { @Value("${base-image}") private String baseImage; - @GetMapping("/user/{userType}/mypage") + @GetMapping("/{userType}/mypage") public ResponseEntity> getMyPage( @AuthorizeUser User user, @PathVariable String userType, @@ -87,7 +87,7 @@ public ResponseEntity> updateAnswer( @AuthorizeUser User user, @PathVariable String userType, @RequestBody AnswerUpdateRequest request) { - answerService.updateAnswer(request.answer(), user.getId(), userType); + answerService.updateAnswer(request.answers(), user.getId(), userType); return ResponseEntity.ok(createSuccess(SUCCESS_UPDATE_ANSWER.getMessage())); } diff --git a/src/main/java/com/najasin/domain/user/dto/request/AnswerUpdateRequest.java b/src/main/java/com/najasin/domain/user/dto/request/AnswerUpdateRequest.java index 5813870..e1ab625 100644 --- a/src/main/java/com/najasin/domain/user/dto/request/AnswerUpdateRequest.java +++ b/src/main/java/com/najasin/domain/user/dto/request/AnswerUpdateRequest.java @@ -4,5 +4,5 @@ import com.najasin.domain.user.dto.param.AnswerUpdateParam; -public record AnswerUpdateRequest(List answer) { +public record AnswerUpdateRequest(List answers) { } diff --git a/src/main/java/com/najasin/security/jwt/util/JwtProvider.java b/src/main/java/com/najasin/security/jwt/util/JwtProvider.java index b67e3f5..d6150e1 100644 --- a/src/main/java/com/najasin/security/jwt/util/JwtProvider.java +++ b/src/main/java/com/najasin/security/jwt/util/JwtProvider.java @@ -16,8 +16,8 @@ @Component @RequiredArgsConstructor public class JwtProvider { - private static final Long ACCESS_TOKEN_VALIDATION_SECOND = 60L * 60 * 24 * 1000; // 24hours - private static final Long REFRESH_TOKEN_VALIDATION_SECOND = 60L * 60 * 24 * 1000 * 7; // 7days + private static final Long ACCESS_TOKEN_VALIDATION_SECOND = 60L * 60 * 24 * 1000 * 90; // 24hours + private static final Long REFRESH_TOKEN_VALIDATION_SECOND = 60L * 60 * 24 * 1000 * 120; // 7days private static final String BEARER_TYPE = "bearer"; private final Key key; diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index dcd4656..b7a158c 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -15,7 +15,7 @@ spring: host: 127.0.0.1 jpa: - open-in-view: false + open-in-view: true hibernate: ddl-auto: update show-sql: true diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index be3dea1..162ebe6 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -15,7 +15,7 @@ spring: host: ${ELASTIC_CACHE_HOST} jpa: - open-in-view: false + open-in-view: true hibernate: ddl-auto: none From 8458dd191b306c3579ea0f55cad71d161c09184d Mon Sep 17 00:00:00 2001 From: lcomment Date: Tue, 22 Aug 2023 06:58:50 +0900 Subject: [PATCH 27/27] =?UTF-8?q?fix(#48):=20cicd=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/master-cicd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/master-cicd.yml b/.github/workflows/master-cicd.yml index 02105b1..47118ed 100644 --- a/.github/workflows/master-cicd.yml +++ b/.github/workflows/master-cicd.yml @@ -114,6 +114,7 @@ jobs: spring.data.redis.host: ${{ secrets.ELASTIC_CACHE_HOST }} jwt.secret: ${{ secrets.JWT_SECRET }} client.url: ${{ secrets.CLIENT_URL }} + base-image: ${{ secrets.BASE_IMAGE }} - name: Grant execute permission for gradlew run: chmod +x gradlew