diff --git a/src/main/java/HookKiller/server/board/exception/BoardException.java b/src/main/java/HookKiller/server/board/exception/BoardException.java index 1d78f39..2907160 100644 --- a/src/main/java/HookKiller/server/board/exception/BoardException.java +++ b/src/main/java/HookKiller/server/board/exception/BoardException.java @@ -5,6 +5,7 @@ import HookKiller.server.common.exception.BaseErrorCode; import lombok.AllArgsConstructor; import lombok.Getter; +import org.springframework.http.HttpStatus; import static org.springframework.http.HttpStatus.*; @@ -16,7 +17,9 @@ public enum BoardException implements BaseErrorCode { ARTICLE_CONTENT_NOT_FOUND_ERROR(NOT_FOUND.value(), "ArticleContent_404_1", "해당 게시글을 찾을 수 없습니다."), ARTICLE_UPDATE_UNAUTHORIZED_USER_ERROR(UNAUTHORIZED.value(), "Article_401_1", "게시물 수정에 대한 권한이 없습니다."), ARTICLE_DELETE_UNAUTHORIZED_USER_ERROR(UNAUTHORIZED.value(), "Article_401_2", "게시물 삭제에 대한 권한이 없습니다."), - REPLY_CONTENT_NOT_FOUND_ERROR(NOT_FOUND.value(), "ReplyContent_404_1", "해당 댓글을 찾을 수 없습니다."); + REPLY_CONTENT_NOT_FOUND_ERROR(NOT_FOUND.value(), "ReplyContent_404_1", "해당 댓글을 찾을 수 없습니다."), + REPLY_DELETE_UNAUTHORIZED_USER_ERROR(UNAUTHORIZED.value(), "Reply_404_1", "댓글 삭제에 대한 권한이 없습니다."), + ; private final Integer statusCode; private final String errorCode; diff --git a/src/main/java/HookKiller/server/board/exception/ReplyDeleteUnauthorizedUserException.java b/src/main/java/HookKiller/server/board/exception/ReplyDeleteUnauthorizedUserException.java new file mode 100644 index 0000000..7c79c1b --- /dev/null +++ b/src/main/java/HookKiller/server/board/exception/ReplyDeleteUnauthorizedUserException.java @@ -0,0 +1,12 @@ +package HookKiller.server.board.exception; + +import HookKiller.server.common.exception.BaseException; + +public class ReplyDeleteUnauthorizedUserException extends BaseException { + + public static final BaseException EXCEPTION = new ReplyDeleteUnauthorizedUserException(); + + private ReplyDeleteUnauthorizedUserException() { + super(BoardException.REPLY_DELETE_UNAUTHORIZED_USER_ERROR); + } +} diff --git a/src/main/java/HookKiller/server/board/repository/ArticleRepository.java b/src/main/java/HookKiller/server/board/repository/ArticleRepository.java index a6c15d3..43cde28 100644 --- a/src/main/java/HookKiller/server/board/repository/ArticleRepository.java +++ b/src/main/java/HookKiller/server/board/repository/ArticleRepository.java @@ -4,6 +4,7 @@ import HookKiller.server.board.entity.Board; import HookKiller.server.common.type.ArticleStatus; +import HookKiller.server.common.type.LanguageType; import HookKiller.server.user.entity.User; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -30,24 +31,24 @@ Page
findAllByBoardAndArticleStatusAndCreateAtBetweenOrderByLikeCountDe ); @Query( - value = "select a.id, u.nick_name as nickName, ac.title, ac.content, a.like_count as likeCount " + + value = "select a.id, u.nick_name as nickName, ac.title, a.like_count as likeCount " + "from tbl_article a " + "join tbl_article_content ac " + "on a.id = ac.article_id " + "join tbl_user u " + "on a.created_user_id = u.id " + - "where (ac.title like concat('%', :word, '%') or ac.content like concat('%', :word, '%')) and a.article_status='PUBLIC'", nativeQuery = true + "where ac.title like concat('%', :word, '%') and a.article_status='PUBLIC' and a.org_article_language=:lang", nativeQuery = true ) - Page retrieveArticleListDown(@Param(value = "word") String word, Pageable pageable); + Page retrieveArticleListDown(@Param(value = "lang") String languageType, @Param(value = "word") String word, Pageable pageable); @Query( - value = "select a.id, u.nick_name as nickName, ac.title, ac.content, a.like_count as likeCount " + + value = "select a.id, u.nick_name as nickName, ac.title, a.like_count as likeCount " + "from tbl_article a " + "join tbl_article_content ac " + "on a.id = ac.article_id " + "join tbl_user u " + "on a.created_user_id = u.id " + - "where (ac.title like concat('%', :word, '%') or ac.content like concat('%', :word, '%')) and a.article_status='PUBLIC'", nativeQuery = true + "where ac.title like concat('%', :word, '%') and a.article_status='PUBLIC' and a.org_article_language=:lang", nativeQuery = true ) - List retrieveAllArticleByWord(@Param(value = "word") String word); + List retrieveAllArticleByWord(@Param(value = "lang") String languageType, @Param(value = "word") String word); } \ No newline at end of file diff --git a/src/main/java/HookKiller/server/board/service/ReplyService.java b/src/main/java/HookKiller/server/board/service/ReplyService.java index 9f10d93..5dda58b 100644 --- a/src/main/java/HookKiller/server/board/service/ReplyService.java +++ b/src/main/java/HookKiller/server/board/service/ReplyService.java @@ -7,6 +7,7 @@ import HookKiller.server.board.entity.ReplyContent; import HookKiller.server.board.exception.ArticleContentNotFoundException; import HookKiller.server.board.exception.ReplyContentNotFoundException; +import HookKiller.server.board.exception.ReplyDeleteUnauthorizedUserException; import HookKiller.server.board.repository.ArticleRepository; import HookKiller.server.board.repository.ReplyContentRepository; import HookKiller.server.board.repository.ReplyRepository; @@ -15,6 +16,8 @@ import HookKiller.server.common.type.LanguageType; import HookKiller.server.common.util.UserUtils; import HookKiller.server.user.entity.User; +import HookKiller.server.user.repository.UserRepository; +import HookKiller.server.user.type.UserRole; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -25,6 +28,7 @@ import static HookKiller.server.board.type.ReplyStatus.USABLE; import static HookKiller.server.board.type.ReplyStatus.DELETED; +import static HookKiller.server.user.type.UserRole.*; @Slf4j @@ -37,6 +41,7 @@ public class ReplyService { private final ReplyRepository replyRepository; private final ReplyContentRepository replyContentRepository; private final TranslateService translateService; + private final UserRepository userRepository; @Transactional public void createReply(PostReplyRequestDto requestDto) { @@ -98,16 +103,20 @@ public List getReplyList(Long articleId, LanguageType language } /** - * TODO : 관리자도 삭제 가능하게 만들기 - * * @param replyId */ @Transactional public void deleteReply(Long replyId) { - replyRepository - .findById(replyId) - .orElseThrow(() -> ReplyContentNotFoundException.EXCEPTION) - .updateStatus(DELETED); + User user = userUtils.getUser(); + + Reply reply = replyRepository.findById(replyId) + .orElseThrow(() -> ReplyContentNotFoundException.EXCEPTION); + + if (reply.getCreatedUser().equals(user) || user.getRole().equals(ADMIN)) { + reply.updateStatus(DELETED); + } else { + throw ReplyDeleteUnauthorizedUserException.EXCEPTION; + } } } diff --git a/src/main/java/HookKiller/server/search/controller/SearchController.java b/src/main/java/HookKiller/server/search/controller/SearchController.java index e0419f3..cedf96c 100644 --- a/src/main/java/HookKiller/server/search/controller/SearchController.java +++ b/src/main/java/HookKiller/server/search/controller/SearchController.java @@ -1,7 +1,9 @@ package HookKiller.server.search.controller; +import HookKiller.server.common.type.LanguageType; import HookKiller.server.search.dto.SimpleArticleVo; import HookKiller.server.search.service.SearchService; +import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.PageRequest; @@ -22,15 +24,17 @@ public class SearchController { @GetMapping("/{word}") public List searchArticles( + HttpServletRequest request, @PathVariable String word, @RequestParam int offset, @RequestParam int limit) { - return searchService.getSearchResult(word, PageRequest.of(offset, limit)); + return searchService.getSearchResult(LanguageType.findTypeByRequest(request), word, PageRequest.of(offset, limit)); } @GetMapping("/all/{word}") public List searchAllArticlesByWord( + HttpServletRequest request, @PathVariable String word) { - return searchService.getAllSearchResultByWord(word); + return searchService.getAllSearchResultByWord(LanguageType.findTypeByRequest(request), word); } } diff --git a/src/main/java/HookKiller/server/search/service/SearchService.java b/src/main/java/HookKiller/server/search/service/SearchService.java index a3bc734..5dfea2a 100644 --- a/src/main/java/HookKiller/server/search/service/SearchService.java +++ b/src/main/java/HookKiller/server/search/service/SearchService.java @@ -4,6 +4,7 @@ import HookKiller.server.board.dto.ArticleRequestDto; import HookKiller.server.board.repository.ArticleContentRepository; import HookKiller.server.board.repository.ArticleRepository; +import HookKiller.server.common.type.LanguageType; import HookKiller.server.search.dto.SimpleArticleVo; import HookKiller.server.user.entity.User; import HookKiller.server.user.repository.UserRepository; @@ -23,15 +24,15 @@ public class SearchService { private final ArticleRepository articleRepository; private final ArticleContentRepository articleContentRepository; - public List getSearchResult(String word, PageRequest pageRequest) { - return articleRepository.retrieveArticleListDown(word, pageRequest) + public List getSearchResult(LanguageType languageType, String word, PageRequest pageRequest) { + return articleRepository.retrieveArticleListDown(languageType.name(), word, pageRequest) .stream() .map(SimpleArticleVo::from) .toList(); } - public List getAllSearchResultByWord(String word) { - return articleRepository.retrieveAllArticleByWord(word).stream().map(SimpleArticleVo::from).toList(); + public List getAllSearchResultByWord(LanguageType languageType, String word) { + return articleRepository.retrieveAllArticleByWord(languageType.name(), word).stream().map(SimpleArticleVo::from).toList(); } } diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index bbb7ad8..2626db9 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -2,7 +2,7 @@ hook: db: url: db-it7f7-kr.vpc-pub-cdb.ntruss.com - database: jw + database: sh username: hooklocal password: hooklocal1234! port: 3306