Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/reply logic 변경 #101

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,24 +31,24 @@ Page<Article> 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<ArticleInterface> retrieveArticleListDown(@Param(value = "word") String word, Pageable pageable);
Page<ArticleInterface> 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<ArticleInterface> retrieveAllArticleByWord(@Param(value = "word") String word);
List<ArticleInterface> retrieveAllArticleByWord(@Param(value = "lang") String languageType, @Param(value = "word") String word);
}
21 changes: 15 additions & 6 deletions src/main/java/HookKiller/server/board/service/ReplyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -98,16 +103,20 @@ public List<ReplyResponseDto> 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;
}
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,15 +24,17 @@ public class SearchController {

@GetMapping("/{word}")
public List<SimpleArticleVo> 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<SimpleArticleVo> searchAllArticlesByWord(
HttpServletRequest request,
@PathVariable String word) {
return searchService.getAllSearchResultByWord(word);
return searchService.getAllSearchResultByWord(LanguageType.findTypeByRequest(request), word);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,15 +24,15 @@ public class SearchService {
private final ArticleRepository articleRepository;
private final ArticleContentRepository articleContentRepository;

public List<SimpleArticleVo> getSearchResult(String word, PageRequest pageRequest) {
return articleRepository.retrieveArticleListDown(word, pageRequest)
public List<SimpleArticleVo> getSearchResult(LanguageType languageType, String word, PageRequest pageRequest) {
return articleRepository.retrieveArticleListDown(languageType.name(), word, pageRequest)
.stream()
.map(SimpleArticleVo::from)
.toList();
}

public List<SimpleArticleVo> getAllSearchResultByWord(String word) {
return articleRepository.retrieveAllArticleByWord(word).stream().map(SimpleArticleVo::from).toList();
public List<SimpleArticleVo> getAllSearchResultByWord(LanguageType languageType, String word) {
return articleRepository.retrieveAllArticleByWord(languageType.name(), word).stream().map(SimpleArticleVo::from).toList();
}
}

2 changes: 1 addition & 1 deletion src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading