From e582fe6778d84917de7a5e99acdfd3ea340f3e3c Mon Sep 17 00:00:00 2001 From: lgsok00 Date: Sat, 14 Oct 2023 17:45:22 +0900 Subject: [PATCH 1/3] =?UTF-8?q?reply=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/ArticleController.java | 6 +- .../board/controller/ReplyController.java | 44 ++++++++ .../server/board/dto/ReplyRequestDto.java | 38 +++++++ .../HookKiller/server/board/entity/Reply.java | 52 +++++++-- .../server/board/entity/ReplyContent.java | 10 +- .../board/exception/BoardException.java | 3 +- .../ReplyContentNotFoundException.java | 13 +++ .../repository/ReplyContentRepository.java | 6 ++ .../board/repository/ReplyRepository.java | 4 + .../board/service/ArticleContentService.java | 11 +- .../server/board/service/ArticleService.java | 1 - .../server/board/service/ReplyService.java | 102 ++++++++++++++++++ .../server/board/type/ReplyStatus.java | 13 +++ .../common/service/TranslateService.java | 5 +- 14 files changed, 285 insertions(+), 23 deletions(-) create mode 100644 src/main/java/HookKiller/server/board/controller/ReplyController.java create mode 100644 src/main/java/HookKiller/server/board/dto/ReplyRequestDto.java create mode 100644 src/main/java/HookKiller/server/board/exception/ReplyContentNotFoundException.java create mode 100644 src/main/java/HookKiller/server/board/service/ReplyService.java create mode 100644 src/main/java/HookKiller/server/board/type/ReplyStatus.java diff --git a/src/main/java/HookKiller/server/board/controller/ArticleController.java b/src/main/java/HookKiller/server/board/controller/ArticleController.java index 67c4933..3da1c47 100644 --- a/src/main/java/HookKiller/server/board/controller/ArticleController.java +++ b/src/main/java/HookKiller/server/board/controller/ArticleController.java @@ -33,11 +33,7 @@ public List getArticleList(@PathVariable Long boardId, HttpSe /** * 단건 조회 */ -// @GetMapping("/{boardId}/{articleId}") -// public ArticleRequestDto getArticle(@PathVariable Long articleId, HttpServletRequest request) { -// BoardType language = BoardType.valueOf(request.getHeader("language")); -// return articleService.getArticle(boardId, articleId, language); -// } + /** * 게시글 등록 diff --git a/src/main/java/HookKiller/server/board/controller/ReplyController.java b/src/main/java/HookKiller/server/board/controller/ReplyController.java new file mode 100644 index 0000000..4877e28 --- /dev/null +++ b/src/main/java/HookKiller/server/board/controller/ReplyController.java @@ -0,0 +1,44 @@ +package HookKiller.server.board.controller; + +import HookKiller.server.board.dto.ReplyRequestDto; +import HookKiller.server.board.service.ReplyService; +import HookKiller.server.common.type.LanguageType; +import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +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 java.util.List; + +@Slf4j +@RestController +@RequestMapping("/reply") +@RequiredArgsConstructor +public class ReplyController { + + private final ReplyService replyService; + + @PostMapping + public void createReply(@RequestBody ReplyRequestDto requestDto) { + replyService.createReply(requestDto); + } + + @GetMapping("/{articleId}") + public List getReplyList(@PathVariable Long articleId, HttpServletRequest request) { + return replyService.getReplyList(articleId, LanguageType.findTypeByRequest(request)); + } + + @DeleteMapping("/{replyId}") + public ResponseEntity deleteReply(@PathVariable Long replyId) { + replyService.deleteReply(replyId); + return ResponseEntity.ok("삭제처리가 완료되었습니다."); + } + +} diff --git a/src/main/java/HookKiller/server/board/dto/ReplyRequestDto.java b/src/main/java/HookKiller/server/board/dto/ReplyRequestDto.java new file mode 100644 index 0000000..dfdf31e --- /dev/null +++ b/src/main/java/HookKiller/server/board/dto/ReplyRequestDto.java @@ -0,0 +1,38 @@ +package HookKiller.server.board.dto; + + +import HookKiller.server.board.entity.Reply; +import HookKiller.server.board.entity.ReplyContent; +import HookKiller.server.common.AbstractTimeStamp; +import HookKiller.server.common.type.LanguageType; +import HookKiller.server.user.entity.User; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ReplyRequestDto extends AbstractTimeStamp { + + private Long articleId; + + private Long replyId; + + private LanguageType orgReplyLanguage; + + private User createUser; + + private String content; + + public static ReplyRequestDto of(Reply reply, ReplyContent replyContent) { + return ReplyRequestDto.builder() + .replyId(reply.getId()) + .createUser(reply.getCreatedUser()) + .content(replyContent.getContent()) + .build(); + } + +} diff --git a/src/main/java/HookKiller/server/board/entity/Reply.java b/src/main/java/HookKiller/server/board/entity/Reply.java index a1b657f..6202c02 100644 --- a/src/main/java/HookKiller/server/board/entity/Reply.java +++ b/src/main/java/HookKiller/server/board/entity/Reply.java @@ -1,7 +1,12 @@ package HookKiller.server.board.entity; +import HookKiller.server.board.type.ReplyStatus; import HookKiller.server.common.AbstractTimeStamp; +import HookKiller.server.common.type.LanguageType; +import HookKiller.server.user.entity.User; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -10,7 +15,10 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -32,20 +40,48 @@ @Getter @Table(name = "tbl_reply") @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Builder public class Reply extends AbstractTimeStamp { - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToMany(mappedBy = "reply") + private List replyContent; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="article_id") private Article article; - @OneToMany(mappedBy = "reply") - private List replyContent; + @NotNull + private LanguageType orgReplyLanguage; + + @NotNull + @Enumerated(EnumType.STRING) + private ReplyStatus isDeleted; + + @NotNull + @ManyToOne(fetch = FetchType.EAGER) + private User createdUser; + + @NotNull + @ManyToOne(fetch = FetchType.EAGER) + private User updatedUser; + + @Builder + public Reply(Long id, LanguageType orgReplyLanguage, ReplyStatus isDeleted, + User createdUser, User updatedUser) { + this.id = id; + this.orgReplyLanguage = orgReplyLanguage; + this.isDeleted = isDeleted; + this.createdUser = createdUser; + this.updatedUser = updatedUser; + } + + public void updateStatus(ReplyStatus status) { + isDeleted = status; + } - private String orgReplyLanguage; - private boolean isDeleted; - private Long createdUserId; - private Long updatedUserId; } diff --git a/src/main/java/HookKiller/server/board/entity/ReplyContent.java b/src/main/java/HookKiller/server/board/entity/ReplyContent.java index f4f2266..349c527 100644 --- a/src/main/java/HookKiller/server/board/entity/ReplyContent.java +++ b/src/main/java/HookKiller/server/board/entity/ReplyContent.java @@ -13,6 +13,7 @@ import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -28,7 +29,7 @@ public class ReplyContent { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; + private Long id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="reply_id") @@ -41,5 +42,12 @@ public class ReplyContent { @Lob private String content; + @Builder + public ReplyContent(Long id, Reply reply, LanguageType language, String content) { + this.id = id; + this.reply = reply; + this.language = language; + this.content = content; + } } diff --git a/src/main/java/HookKiller/server/board/exception/BoardException.java b/src/main/java/HookKiller/server/board/exception/BoardException.java index 92c0e27..e4024b4 100644 --- a/src/main/java/HookKiller/server/board/exception/BoardException.java +++ b/src/main/java/HookKiller/server/board/exception/BoardException.java @@ -13,7 +13,8 @@ public enum BoardException implements BaseErrorCode { BOARD_NOT_FOUND_ERROR(NOT_FOUND.value(), "Board_404_1", "해당 게시판을 찾을 수 없습니다."), - ARTICLE_CONTENT_NOT_FOUND_ERROR(NOT_FOUND.value(), "ArticleContent_404_1", "해당 게시글을 찾을 수 없습니다."); + ARTICLE_CONTENT_NOT_FOUND_ERROR(NOT_FOUND.value(), "ArticleContent_404_1", "해당 게시글을 찾을 수 없습니다."), + REPLY_CONTENT_NOT_FOUND_ERROR(NOT_FOUND.value(), "ReplyContent_404_1", "해당 댓글을 찾을 수 없습니다."); private final Integer statusCode; private final String errorCode; diff --git a/src/main/java/HookKiller/server/board/exception/ReplyContentNotFoundException.java b/src/main/java/HookKiller/server/board/exception/ReplyContentNotFoundException.java new file mode 100644 index 0000000..8842685 --- /dev/null +++ b/src/main/java/HookKiller/server/board/exception/ReplyContentNotFoundException.java @@ -0,0 +1,13 @@ +package HookKiller.server.board.exception; + +import HookKiller.server.common.exception.BaseException; + +public class ReplyContentNotFoundException extends BaseException { + + public static final BaseException EXCEPTION = new ReplyContentNotFoundException(); + + private ReplyContentNotFoundException() { + super(BoardException.REPLY_CONTENT_NOT_FOUND_ERROR); + } + +} diff --git a/src/main/java/HookKiller/server/board/repository/ReplyContentRepository.java b/src/main/java/HookKiller/server/board/repository/ReplyContentRepository.java index 2ed9d65..315c916 100644 --- a/src/main/java/HookKiller/server/board/repository/ReplyContentRepository.java +++ b/src/main/java/HookKiller/server/board/repository/ReplyContentRepository.java @@ -1,7 +1,13 @@ package HookKiller.server.board.repository; +import HookKiller.server.board.entity.Reply; import HookKiller.server.board.entity.ReplyContent; +import HookKiller.server.common.type.LanguageType; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface ReplyContentRepository extends JpaRepository { + + Optional findByReplyAndLanguage(Reply reply, LanguageType language); } diff --git a/src/main/java/HookKiller/server/board/repository/ReplyRepository.java b/src/main/java/HookKiller/server/board/repository/ReplyRepository.java index 0a42bfb..402c9ca 100644 --- a/src/main/java/HookKiller/server/board/repository/ReplyRepository.java +++ b/src/main/java/HookKiller/server/board/repository/ReplyRepository.java @@ -1,7 +1,11 @@ package HookKiller.server.board.repository; +import HookKiller.server.board.entity.Article; import HookKiller.server.board.entity.Reply; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ReplyRepository extends JpaRepository { + List findAllByArticleAndDeleted(Article article, boolean isDeleted); } diff --git a/src/main/java/HookKiller/server/board/service/ArticleContentService.java b/src/main/java/HookKiller/server/board/service/ArticleContentService.java index ada76df..6b4bcb6 100644 --- a/src/main/java/HookKiller/server/board/service/ArticleContentService.java +++ b/src/main/java/HookKiller/server/board/service/ArticleContentService.java @@ -4,6 +4,7 @@ import HookKiller.server.board.entity.Article; import HookKiller.server.board.entity.ArticleContent; import HookKiller.server.board.repository.ArticleContentRepository; +import HookKiller.server.common.service.TranslateService; import HookKiller.server.common.type.LanguageType; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -18,6 +19,7 @@ @RequiredArgsConstructor public class ArticleContentService { private final ArticleContentRepository articleContentRepository; + private final TranslateService translateService; public void createContent(PostArticleRequestDto requestDto, Article article) { @@ -30,8 +32,8 @@ public void createContent(PostArticleRequestDto requestDto, Article article) { languageType -> ArticleContent.builder() .article(article) .language(languageType) - // .title(getTranslatePapagoTextArticleContent(requestDto.getOrgArticleLanguage().getLanguageCode(), languageType.getLanguageCode(), requestDto.getTitle())) - // .content(getTranslatePapagoHTMLArticleContent(requestDto.getOrgArticleLanguage().getLanguageCode(), languageType.getLanguageCode(), requestDto.getContent())) + // .title(translateService.naverPapagoTextTranslate(requestDto.getOrgArticleLanguage(), languageType.getLanguageCode(), requestDto.getTitle())) + // .content(translateService.naverPapagoHtmlTranslate(requestDto.getOrgArticleLanguage(), languageType.getLanguageCode(), requestDto.getContent())) .build() ).toList() ); @@ -63,8 +65,9 @@ public void updateContent(PostArticleRequestDto requestDto, Article article) { existingContents.stream() .filter(content -> content.getLanguage().equals(languageType)) .forEach(content -> { - // content.articleUpdate(getTranslatePapagoTextArticleContent(requestDto.getOrgArticleLanguage().getLanguageCode(), languageType.getLanguageCode(), requestDto.getTitle()), - // getTranslatePapagoHTMLArticleContent(requestDto.getOrgArticleLanguage().getLanguageCode(), languageType.getLanguageCode(), requestDto.getContent())); + content.articleUpdate( + getTranslatePapagoTextArticleContent(requestDto.getOrgArticleLanguage().getLanguageCode(), languageType.getLanguageCode(), requestDto.getTitle()), + getTranslatePapagoHTMLArticleContent(requestDto.getOrgArticleLanguage().getLanguageCode(), languageType.getLanguageCode(), requestDto.getContent())); }); } } diff --git a/src/main/java/HookKiller/server/board/service/ArticleService.java b/src/main/java/HookKiller/server/board/service/ArticleService.java index c3551e5..409e328 100644 --- a/src/main/java/HookKiller/server/board/service/ArticleService.java +++ b/src/main/java/HookKiller/server/board/service/ArticleService.java @@ -18,7 +18,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; import java.util.List; @Slf4j diff --git a/src/main/java/HookKiller/server/board/service/ReplyService.java b/src/main/java/HookKiller/server/board/service/ReplyService.java new file mode 100644 index 0000000..9672054 --- /dev/null +++ b/src/main/java/HookKiller/server/board/service/ReplyService.java @@ -0,0 +1,102 @@ +package HookKiller.server.board.service; + +import HookKiller.server.board.dto.ReplyRequestDto; +import HookKiller.server.board.entity.Article; +import HookKiller.server.board.entity.Reply; +import HookKiller.server.board.entity.ReplyContent; +import HookKiller.server.board.exception.ArticleContentNotFoundException; +import HookKiller.server.board.exception.ReplyContentNotFoundException; +import HookKiller.server.board.repository.ArticleRepository; +import HookKiller.server.board.repository.ReplyContentRepository; +import HookKiller.server.board.repository.ReplyRepository; +import HookKiller.server.board.type.ReplyStatus; +import HookKiller.server.common.service.TranslateService; +import HookKiller.server.common.type.LanguageType; +import HookKiller.server.common.util.UserUtils; +import HookKiller.server.user.entity.User; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Service +@RequiredArgsConstructor +public class ReplyService { + + private final UserUtils userUtils; + private final ArticleRepository articleRepository; + private final ReplyRepository replyRepository; + private final ReplyContentRepository replyContentRepository; + private final TranslateService translateService; + + @Transactional + public void createReply(ReplyRequestDto requestDto) { + + User user = userUtils.getUser(); + + Reply reply = replyRepository.save( + Reply.builder() + .isDeleted(ReplyStatus.FALSE) + .orgReplyLanguage(requestDto.getOrgReplyLanguage()) + .createdUser(user) + .updatedUser(user) + .build() + ); + + List replyContentList = new ArrayList<>(); + replyContentList.add( + ReplyContent.builder() + .reply(reply) + .language(requestDto.getOrgReplyLanguage()) + .content(requestDto.getContent()) + .build() + ); + + requestDto + .getOrgReplyLanguage() + .getTranslateTargetLanguage() + .forEach(targetLanguage -> + replyContentList.add( + ReplyContent + .builder() + .reply(reply) + .language(targetLanguage) + .content( + translateService.naverPapagoTextTranslate( + requestDto.getOrgReplyLanguage(), targetLanguage, requestDto.getContent() + ) + ) + .build() + ) + ); + + replyContentRepository.saveAll(replyContentList); + } + + + @Transactional(readOnly = true) + public List getReplyList(Long articleId, LanguageType language) { + Article article = articleRepository.findById(articleId).orElseThrow(() -> ArticleContentNotFoundException.EXCEPTION); + List replyList = replyRepository.findAllByArticleAndDeleted(article, false); + + return replyList.stream() + .map(reply -> + ReplyRequestDto.of(reply, replyContentRepository + .findByReplyAndLanguage(reply, language) + .orElseThrow(() -> ReplyContentNotFoundException.EXCEPTION))) + .toList(); + } + + @Transactional + public void deleteReply(Long replyId) { + replyRepository + .findById(replyId) + .orElseThrow(() -> ReplyContentNotFoundException.EXCEPTION) + .updateStatus(ReplyStatus.TURE); + } + +} diff --git a/src/main/java/HookKiller/server/board/type/ReplyStatus.java b/src/main/java/HookKiller/server/board/type/ReplyStatus.java new file mode 100644 index 0000000..288b366 --- /dev/null +++ b/src/main/java/HookKiller/server/board/type/ReplyStatus.java @@ -0,0 +1,13 @@ +package HookKiller.server.board.type; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum ReplyStatus { + FALSE("공개상태"), + TURE("삭제처리"); + + private final String typeName; +} diff --git a/src/main/java/HookKiller/server/common/service/TranslateService.java b/src/main/java/HookKiller/server/common/service/TranslateService.java index 18eb9a0..45774bd 100644 --- a/src/main/java/HookKiller/server/common/service/TranslateService.java +++ b/src/main/java/HookKiller/server/common/service/TranslateService.java @@ -1,6 +1,7 @@ package HookKiller.server.common.service; -import HookKiller.server.common.dto.*; +import HookKiller.server.common.dto.PapagoTextRequest; +import HookKiller.server.common.dto.PapagoTextResponse; import HookKiller.server.common.exception.NaverErrorException; import HookKiller.server.common.type.LanguageType; import HookKiller.server.properties.PapagoProperties; @@ -8,14 +9,12 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.*; -import org.springframework.http.converter.FormHttpMessageConverter; import org.springframework.stereotype.Service; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; import java.net.URI; -import java.util.HashMap; import java.util.Map; @Slf4j From 6dd81847f7db14a0c548043e206762b074571e3d Mon Sep 17 00:00:00 2001 From: lgsok00 Date: Sat, 14 Oct 2023 21:51:31 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=EB=8C=93=EA=B8=80=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=9D=B4=EC=8A=88=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/ReplyController.java | 6 +++--- ...yRequestDto.java => ReplyResponseDto.java} | 6 +++--- .../HookKiller/server/board/entity/Reply.java | 11 +++++------ .../board/repository/ReplyRepository.java | 3 ++- .../server/board/service/ReplyService.java | 19 +++++++++++-------- 5 files changed, 24 insertions(+), 21 deletions(-) rename src/main/java/HookKiller/server/board/dto/{ReplyRequestDto.java => ReplyResponseDto.java} (81%) diff --git a/src/main/java/HookKiller/server/board/controller/ReplyController.java b/src/main/java/HookKiller/server/board/controller/ReplyController.java index 4877e28..9a3423e 100644 --- a/src/main/java/HookKiller/server/board/controller/ReplyController.java +++ b/src/main/java/HookKiller/server/board/controller/ReplyController.java @@ -1,6 +1,6 @@ package HookKiller.server.board.controller; -import HookKiller.server.board.dto.ReplyRequestDto; +import HookKiller.server.board.dto.ReplyResponseDto; import HookKiller.server.board.service.ReplyService; import HookKiller.server.common.type.LanguageType; import jakarta.servlet.http.HttpServletRequest; @@ -26,12 +26,12 @@ public class ReplyController { private final ReplyService replyService; @PostMapping - public void createReply(@RequestBody ReplyRequestDto requestDto) { + public void createReply(@RequestBody ReplyResponseDto requestDto) { replyService.createReply(requestDto); } @GetMapping("/{articleId}") - public List getReplyList(@PathVariable Long articleId, HttpServletRequest request) { + public List getReplyList(@PathVariable Long articleId, HttpServletRequest request) { return replyService.getReplyList(articleId, LanguageType.findTypeByRequest(request)); } diff --git a/src/main/java/HookKiller/server/board/dto/ReplyRequestDto.java b/src/main/java/HookKiller/server/board/dto/ReplyResponseDto.java similarity index 81% rename from src/main/java/HookKiller/server/board/dto/ReplyRequestDto.java rename to src/main/java/HookKiller/server/board/dto/ReplyResponseDto.java index dfdf31e..200298c 100644 --- a/src/main/java/HookKiller/server/board/dto/ReplyRequestDto.java +++ b/src/main/java/HookKiller/server/board/dto/ReplyResponseDto.java @@ -15,7 +15,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class ReplyRequestDto extends AbstractTimeStamp { +public class ReplyResponseDto extends AbstractTimeStamp { private Long articleId; @@ -27,8 +27,8 @@ public class ReplyRequestDto extends AbstractTimeStamp { private String content; - public static ReplyRequestDto of(Reply reply, ReplyContent replyContent) { - return ReplyRequestDto.builder() + public static ReplyResponseDto of(Reply reply, ReplyContent replyContent) { + return ReplyResponseDto.builder() .replyId(reply.getId()) .createUser(reply.getCreatedUser()) .content(replyContent.getContent()) diff --git a/src/main/java/HookKiller/server/board/entity/Reply.java b/src/main/java/HookKiller/server/board/entity/Reply.java index 6202c02..1381b40 100644 --- a/src/main/java/HookKiller/server/board/entity/Reply.java +++ b/src/main/java/HookKiller/server/board/entity/Reply.java @@ -41,14 +41,13 @@ @Table(name = "tbl_reply") @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor -@Builder public class Reply extends AbstractTimeStamp { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToMany(mappedBy = "reply") + @OneToMany(mappedBy = "reply", fetch = FetchType.EAGER) private List replyContent; @ManyToOne(fetch = FetchType.LAZY) @@ -60,7 +59,7 @@ public class Reply extends AbstractTimeStamp { @NotNull @Enumerated(EnumType.STRING) - private ReplyStatus isDeleted; + private ReplyStatus replyStatus; @NotNull @ManyToOne(fetch = FetchType.EAGER) @@ -71,17 +70,17 @@ public class Reply extends AbstractTimeStamp { private User updatedUser; @Builder - public Reply(Long id, LanguageType orgReplyLanguage, ReplyStatus isDeleted, + public Reply(Long id, LanguageType orgReplyLanguage, ReplyStatus replyStatus, User createdUser, User updatedUser) { this.id = id; this.orgReplyLanguage = orgReplyLanguage; - this.isDeleted = isDeleted; + this.replyStatus = replyStatus; this.createdUser = createdUser; this.updatedUser = updatedUser; } public void updateStatus(ReplyStatus status) { - isDeleted = status; + replyStatus = status; } } diff --git a/src/main/java/HookKiller/server/board/repository/ReplyRepository.java b/src/main/java/HookKiller/server/board/repository/ReplyRepository.java index 402c9ca..0074e2e 100644 --- a/src/main/java/HookKiller/server/board/repository/ReplyRepository.java +++ b/src/main/java/HookKiller/server/board/repository/ReplyRepository.java @@ -2,10 +2,11 @@ import HookKiller.server.board.entity.Article; import HookKiller.server.board.entity.Reply; +import HookKiller.server.board.type.ReplyStatus; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; public interface ReplyRepository extends JpaRepository { - List findAllByArticleAndDeleted(Article article, boolean isDeleted); + List findAllByArticleAndReplyStatus(Article article, ReplyStatus replyStatus); } diff --git a/src/main/java/HookKiller/server/board/service/ReplyService.java b/src/main/java/HookKiller/server/board/service/ReplyService.java index 9672054..dcd9684 100644 --- a/src/main/java/HookKiller/server/board/service/ReplyService.java +++ b/src/main/java/HookKiller/server/board/service/ReplyService.java @@ -1,6 +1,6 @@ package HookKiller.server.board.service; -import HookKiller.server.board.dto.ReplyRequestDto; +import HookKiller.server.board.dto.ReplyResponseDto; import HookKiller.server.board.entity.Article; import HookKiller.server.board.entity.Reply; import HookKiller.server.board.entity.ReplyContent; @@ -9,7 +9,6 @@ import HookKiller.server.board.repository.ArticleRepository; import HookKiller.server.board.repository.ReplyContentRepository; import HookKiller.server.board.repository.ReplyRepository; -import HookKiller.server.board.type.ReplyStatus; import HookKiller.server.common.service.TranslateService; import HookKiller.server.common.type.LanguageType; import HookKiller.server.common.util.UserUtils; @@ -22,6 +21,10 @@ import java.util.ArrayList; import java.util.List; +import static HookKiller.server.board.type.ReplyStatus.FALSE; +import static HookKiller.server.board.type.ReplyStatus.TURE; + + @Slf4j @Service @RequiredArgsConstructor @@ -34,13 +37,13 @@ public class ReplyService { private final TranslateService translateService; @Transactional - public void createReply(ReplyRequestDto requestDto) { + public void createReply(ReplyResponseDto requestDto) { User user = userUtils.getUser(); Reply reply = replyRepository.save( Reply.builder() - .isDeleted(ReplyStatus.FALSE) + .replyStatus(FALSE) .orgReplyLanguage(requestDto.getOrgReplyLanguage()) .createdUser(user) .updatedUser(user) @@ -79,13 +82,13 @@ public void createReply(ReplyRequestDto requestDto) { @Transactional(readOnly = true) - public List getReplyList(Long articleId, LanguageType language) { + public List getReplyList(Long articleId, LanguageType language) { Article article = articleRepository.findById(articleId).orElseThrow(() -> ArticleContentNotFoundException.EXCEPTION); - List replyList = replyRepository.findAllByArticleAndDeleted(article, false); + List replyList = replyRepository.findAllByArticleAndReplyStatus(article, FALSE); return replyList.stream() .map(reply -> - ReplyRequestDto.of(reply, replyContentRepository + ReplyResponseDto.of(reply, replyContentRepository .findByReplyAndLanguage(reply, language) .orElseThrow(() -> ReplyContentNotFoundException.EXCEPTION))) .toList(); @@ -96,7 +99,7 @@ public void deleteReply(Long replyId) { replyRepository .findById(replyId) .orElseThrow(() -> ReplyContentNotFoundException.EXCEPTION) - .updateStatus(ReplyStatus.TURE); + .updateStatus(TURE); } } From be6f9fa72d71e81078263539e4b928ad1aaeb35e Mon Sep 17 00:00:00 2001 From: lgsok00 Date: Sun, 15 Oct 2023 18:10:38 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=EB=8C=93=EA=B8=80=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=9D=B4=EC=8A=88=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/board/controller/ReplyController.java | 4 ++-- .../server/board/service/ReplyService.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/HookKiller/server/board/controller/ReplyController.java b/src/main/java/HookKiller/server/board/controller/ReplyController.java index 9a3423e..9811918 100644 --- a/src/main/java/HookKiller/server/board/controller/ReplyController.java +++ b/src/main/java/HookKiller/server/board/controller/ReplyController.java @@ -26,8 +26,8 @@ public class ReplyController { private final ReplyService replyService; @PostMapping - public void createReply(@RequestBody ReplyResponseDto requestDto) { - replyService.createReply(requestDto); + public void createReply(@RequestBody ReplyResponseDto responseDto) { + replyService.createReply(responseDto); } @GetMapping("/{articleId}") diff --git a/src/main/java/HookKiller/server/board/service/ReplyService.java b/src/main/java/HookKiller/server/board/service/ReplyService.java index dcd9684..40e80e9 100644 --- a/src/main/java/HookKiller/server/board/service/ReplyService.java +++ b/src/main/java/HookKiller/server/board/service/ReplyService.java @@ -37,14 +37,14 @@ public class ReplyService { private final TranslateService translateService; @Transactional - public void createReply(ReplyResponseDto requestDto) { + public void createReply(ReplyResponseDto responseDto) { User user = userUtils.getUser(); Reply reply = replyRepository.save( Reply.builder() .replyStatus(FALSE) - .orgReplyLanguage(requestDto.getOrgReplyLanguage()) + .orgReplyLanguage(responseDto.getOrgReplyLanguage()) .createdUser(user) .updatedUser(user) .build() @@ -54,12 +54,12 @@ public void createReply(ReplyResponseDto requestDto) { replyContentList.add( ReplyContent.builder() .reply(reply) - .language(requestDto.getOrgReplyLanguage()) - .content(requestDto.getContent()) + .language(responseDto.getOrgReplyLanguage()) + .content(responseDto.getContent()) .build() ); - requestDto + responseDto .getOrgReplyLanguage() .getTranslateTargetLanguage() .forEach(targetLanguage -> @@ -70,7 +70,7 @@ public void createReply(ReplyResponseDto requestDto) { .language(targetLanguage) .content( translateService.naverPapagoTextTranslate( - requestDto.getOrgReplyLanguage(), targetLanguage, requestDto.getContent() + responseDto.getOrgReplyLanguage(), targetLanguage, responseDto.getContent() ) ) .build()