-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT #49] 댓글(자유게시판&성지순례) 수정&삭제
- Loading branch information
Showing
25 changed files
with
514 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/com/favoriteplace/app/controller/GuestBookCommentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.favoriteplace.app.controller; | ||
|
||
import com.favoriteplace.app.domain.Member; | ||
import com.favoriteplace.app.dto.community.CommentResponseDto; | ||
import com.favoriteplace.app.dto.community.GuestBookRequestDto; | ||
import com.favoriteplace.app.dto.community.GuestBookResponseDto; | ||
import com.favoriteplace.app.dto.community.PostResponseDto; | ||
import com.favoriteplace.app.service.community.CommentCommandService; | ||
import com.favoriteplace.app.service.community.CommentQueryService; | ||
import com.favoriteplace.global.util.SecurityUtil; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/posts/guestbooks") | ||
@RequiredArgsConstructor | ||
public class GuestBookCommentController { | ||
private final SecurityUtil securityUtil; | ||
private final CommentQueryService commentQueryService; | ||
private final CommentCommandService commentCommandService; | ||
|
||
@GetMapping("/my-comments") | ||
public GuestBookResponseDto.MyGuestBookCommentDto getMyComments( | ||
@RequestParam(required = false, defaultValue = "1") int page, | ||
@RequestParam(required = false, defaultValue = "10") int size | ||
){ | ||
Member member = securityUtil.getUser(); | ||
Page<GuestBookResponseDto.MyGuestBookComment> myComments = commentQueryService.getMyGuestBookComments(member, page, size); | ||
return GuestBookResponseDto.MyGuestBookCommentDto.builder() | ||
.page((long) (myComments.getNumber()+1)) | ||
.size((long) myComments.getSize()) | ||
.comment(myComments.getContent()) | ||
.build(); | ||
} | ||
|
||
@GetMapping("/{guestbook_id}/comments") | ||
public CommentResponseDto.PostCommentDto getGuestBookComments( | ||
@PathVariable("guestbook_id") Long guestbookId, | ||
@RequestParam(required = false, defaultValue = "1") int page, | ||
@RequestParam(required = false, defaultValue = "10") int size, | ||
HttpServletRequest request | ||
){ | ||
Member member = securityUtil.getUserFromHeader(request); | ||
Page<CommentResponseDto.PostComment> comments = commentQueryService.getGuestBookComments(page, size, member, guestbookId); | ||
return CommentResponseDto.PostCommentDto.builder() | ||
.page((long) comments.getNumber() +1) | ||
.size((long) comments.getSize()) | ||
.comment(comments.getContent()) | ||
.build(); | ||
} | ||
|
||
@PostMapping("/{guestbook_id}/comments") | ||
public ResponseEntity<PostResponseDto.SuccessResponseDto> createGuestBookComment( | ||
@PathVariable("guestbook_id") Long guestbookId, | ||
@RequestBody GuestBookRequestDto.GuestBookCommentDto guestBookCommentDto | ||
){ | ||
Member member = securityUtil.getUser(); | ||
commentCommandService.createGuestBookComment(member, guestbookId, guestBookCommentDto); | ||
return new ResponseEntity<>( | ||
PostResponseDto.SuccessResponseDto.builder().message("댓글이 성공적으로 등록했습니다.").build(), | ||
HttpStatus.OK | ||
); | ||
} | ||
|
||
@PutMapping("/comments/{comment_id}") | ||
public ResponseEntity<PostResponseDto.SuccessResponseDto> modifyGuestBookComment( | ||
@PathVariable("comment_id") Long commentId, | ||
@RequestBody GuestBookRequestDto.GuestBookCommentDto guestBookCommentDto | ||
){ | ||
Member member = securityUtil.getUser(); | ||
commentCommandService.modifyGuestBookComment(member, commentId, guestBookCommentDto.getContent()); | ||
return new ResponseEntity<>( | ||
PostResponseDto.SuccessResponseDto.builder().message("댓글 성공적으로 수정했습니다.").build(), | ||
HttpStatus.OK | ||
); | ||
} | ||
|
||
@DeleteMapping("/comments/{comment_id}") | ||
public ResponseEntity<PostResponseDto.SuccessResponseDto> deleteGuestBookComment( | ||
@PathVariable("comment_id") Long commentId | ||
){ | ||
Member member = securityUtil.getUser(); | ||
commentCommandService.deleteGuestBookComment(member, commentId); | ||
return new ResponseEntity<>( | ||
PostResponseDto.SuccessResponseDto.builder().message("댓글 성공적으로 삭제했습니다.").build(), | ||
HttpStatus.OK | ||
); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/com/favoriteplace/app/controller/PostCommentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.favoriteplace.app.controller; | ||
|
||
import com.favoriteplace.app.domain.Member; | ||
import com.favoriteplace.app.dto.community.CommentRequestDto; | ||
import com.favoriteplace.app.dto.community.CommentResponseDto; | ||
import com.favoriteplace.app.dto.community.PostResponseDto; | ||
import com.favoriteplace.app.service.community.CommentCommandService; | ||
import com.favoriteplace.app.service.community.CommentQueryService; | ||
import com.favoriteplace.global.util.SecurityUtil; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/posts/free") | ||
@RequiredArgsConstructor | ||
public class PostCommentController { | ||
|
||
private final SecurityUtil securityUtil; | ||
private final CommentQueryService commentQueryService; | ||
private final CommentCommandService commentCommandService; | ||
|
||
@GetMapping("/my-comments") | ||
public PostResponseDto.MyCommentDto getMyComments( | ||
@RequestParam(required = false, defaultValue = "1") int page, | ||
@RequestParam(required = false, defaultValue = "10") int size | ||
){ | ||
Member member = securityUtil.getUser(); | ||
Page<PostResponseDto.MyComment> comments = commentQueryService.getMyPostComments(member, page, size); | ||
return PostResponseDto.MyCommentDto.builder() | ||
.page((long) comments.getNumber()+1) | ||
.size((long) comments.getSize()) | ||
.comment(comments.getContent()) | ||
.build(); | ||
} | ||
|
||
@GetMapping("/{post_id}/comments") | ||
public CommentResponseDto.PostCommentDto getPostComments( | ||
@PathVariable("post_id") Long postId, | ||
@RequestParam(required = false, defaultValue = "1") int page, | ||
@RequestParam(required = false, defaultValue = "10") int size, | ||
HttpServletRequest request | ||
){ | ||
Member member = securityUtil.getUserFromHeader(request); | ||
Page<CommentResponseDto.PostComment> comments = commentQueryService.getPostComments(member, page, size, postId); | ||
return CommentResponseDto.PostCommentDto.builder() | ||
.page((long)comments.getNumber()+1) | ||
.size((long) comments.getSize()) | ||
.comment(comments.getContent()) | ||
.build(); | ||
} | ||
|
||
@PostMapping("/{post_id}/comments") | ||
public ResponseEntity<PostResponseDto.SuccessResponseDto> createPostComment( | ||
@PathVariable("post_id") long postId, | ||
@RequestBody CommentRequestDto dto | ||
){ | ||
Member member = securityUtil.getUser(); | ||
commentCommandService.createPostComment(member, postId, dto.getContent()); | ||
return new ResponseEntity<>( | ||
PostResponseDto.SuccessResponseDto.builder().message("댓글을 성공적으로 등록했습니다.").build(), | ||
HttpStatus.OK | ||
); | ||
} | ||
|
||
@PutMapping("/comments/{comment_id}") | ||
public ResponseEntity<PostResponseDto.SuccessResponseDto> modifyPostComment( | ||
@PathVariable("comment_id") long commentId, | ||
@RequestBody CommentRequestDto dto | ||
){ | ||
Member member = securityUtil.getUser(); | ||
commentCommandService.modifyPostComment(member, commentId, dto.getContent()); | ||
return new ResponseEntity<>( | ||
PostResponseDto.SuccessResponseDto.builder().message("댓글을 성공적으로 수정했습니다.").build(), | ||
HttpStatus.OK | ||
); | ||
} | ||
|
||
@DeleteMapping("/comments/{comment_id}") | ||
public ResponseEntity<PostResponseDto.SuccessResponseDto> deletePostComment( | ||
@PathVariable("comment_id") long commentId | ||
){ | ||
Member member = securityUtil.getUser(); | ||
commentCommandService.deletePostComment(member, commentId); | ||
return new ResponseEntity<>( | ||
PostResponseDto.SuccessResponseDto.builder().message("댓글을 성공적으로 삭제했습니다.").build(), | ||
HttpStatus.OK | ||
); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.