Skip to content
Open
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 @@ -10,6 +10,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -39,18 +40,18 @@ public void createComment(@RequestBody CommentRequestDto commentRequestDto){

// 댓글 조회
@GetMapping("")
public ResponseEntity<List<CommentResponseDto>> readComment(CommentRequestDto commentRequestDto) {
public ResponseEntity<List<CommentResponseDto>> readComment(CommentRequestDto commentRequestDto, @RequestHeader(value = "Authorization") String accessToken) {

List<CommentResponseDto> commentResponseDtoList = commentService.readComment(commentRequestDto);
List<CommentResponseDto> commentResponseDtoList = commentService.readComment(commentRequestDto, accessToken);
return ResponseEntity.ok(commentResponseDtoList);
}

// 댓글 삭제
@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteComment(@PathVariable Long id){
public void deleteComment(@PathVariable Long id, @RequestHeader(value = "Authorization") String accessToken){

commentService.deleteComment(id);
commentService.deleteComment(id, accessToken);
}

// 댓글 수정
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import com.v1.matripserver.auth.JwtTokenUtil;
import com.v1.matripserver.comment.dto.CommentRequestDto;
import com.v1.matripserver.comment.dto.CommentResponseDto;
import com.v1.matripserver.comment.entity.Comment;
Expand All @@ -34,6 +35,8 @@ public class CommentService {

private final MemberService memberService;

private static String secretKey = "test001";

// 댓글 작성
public void createComment(CommentRequestDto commentRequestDto){

Expand Down Expand Up @@ -80,11 +83,13 @@ public void createComment(CommentRequestDto commentRequestDto){
}

// 댓글 조회
public List<CommentResponseDto> readComment(CommentRequestDto commentRequestDto){
public List<CommentResponseDto> readComment(CommentRequestDto commentRequestDto, String token){

try {
Long journeyId = commentRequestDto.getJourneyId();
List<Comment> commentList = commentRepository.readComment(journeyId);
String memberEmail = JwtTokenUtil.getLoginId(token, secretKey);
Member member = memberService.getMemberByEmail(memberEmail);

// 변수 선언
Long commentWriterId;
Expand Down Expand Up @@ -112,9 +117,9 @@ public List<CommentResponseDto> readComment(CommentRequestDto commentRequestDto)
// 비밀 댓글일 때
if (comment.isSecret()) {
// 댓글 작성자 혹은 게시글 작성자일 때
log.info(comment.getId() + " " + commentWriterId);
if (commentWriterId.equals(commentRequestDto.getMemberId()) || journeyWriterId.equals(
commentRequestDto.getMemberId())) {
log.info(comment.getMemberId() + " " + commentWriterId);
if (commentWriterId.equals(member.getId()) || journeyWriterId.equals(
member.getId())) {
commentResponseDto = entityToDto(comment.getId(), comment.getContent(),
comment.isSecret(), comment.getCreated(), parentId, comment.getMemberId());
// 제 3자일 때
Expand Down Expand Up @@ -156,10 +161,11 @@ private CommentResponseDto entityToDto(Long id, String content, boolean secret,
}

// 댓글 삭제
public void deleteComment(Long id){
public void deleteComment(Long id, String token){

try {
Comment comment = commentRepository.findById(id).orElseThrow(() -> new CustomException(BaseResponseStatus.COMMON_NOT_FOUND, HttpStatus.NOT_FOUND));
String memberEmail = JwtTokenUtil.getLoginId(token, secretKey);
comment.setStatus(Status.DELETED);

commentRepository.save(comment);
Expand Down