-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Refactor #153] 자유게시판, 성지순례 인증글 response DTO, status 수정 #154
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,28 @@ | ||
package com.favoriteplace.app.controller; | ||
|
||
import com.favoriteplace.app.domain.Member; | ||
import com.favoriteplace.app.dto.community.*; | ||
import com.favoriteplace.app.repository.MemberRepository; | ||
import com.favoriteplace.app.dto.community.CommentRequestDto; | ||
import com.favoriteplace.app.dto.community.CommentResponseDto; | ||
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 com.google.api.Http; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.parameters.P; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/posts/guestbooks") | ||
@RequiredArgsConstructor | ||
public class GuestBookCommentController { | ||
private final SecurityUtil securityUtil; | ||
private final CommentQueryService commentQueryService; | ||
private final CommentCommandService commentCommandService; | ||
private final MemberRepository memberRepository; | ||
|
||
@GetMapping("/my-comments") | ||
public ResponseEntity<GuestBookResponseDto.MyGuestBookCommentDto> getMyComments( | ||
|
@@ -46,52 +45,53 @@ public ResponseEntity<CommentResponseDto.CommentDto> getGuestBookComments( | |
} | ||
|
||
@PostMapping("/{guestbook_id}/comments") | ||
public ResponseEntity<PostResponseDto.SuccessResponseDto> createGuestBookComment( | ||
public ResponseEntity<PostResponseDto.CommentSuccessResponseDto> createGuestBookComment( | ||
@PathVariable("guestbook_id") Long guestbookId, | ||
@RequestBody CommentRequestDto.CreateComment guestBookCommentDto | ||
){ | ||
Member member = securityUtil.getUser(); | ||
// Member member = memberRepository.findById(1L).orElseThrow(() -> new RestApiException(ErrorCode.USER_NOT_FOUND)); | ||
Long commentId = commentCommandService.createGuestBookComment(member, guestbookId, guestBookCommentDto); | ||
return new ResponseEntity<>( | ||
PostResponseDto.SuccessResponseDto.builder().commentId(commentId).message("댓글이 성공적으로 등록했습니다.").build(), | ||
PostResponseDto.CommentSuccessResponseDto.builder().commentId(commentId).build(), | ||
HttpStatus.OK | ||
); | ||
} | ||
|
||
@PostMapping("/{guestbook_id}/comments/{comment_id}/notification") | ||
public ResponseEntity<?> sendGuestBookNotification( | ||
public ResponseEntity<Void> sendGuestBookNotification( | ||
@PathVariable("guestbook_id") Long guestbookId, | ||
@PathVariable("comment_id") Long commentId | ||
){ | ||
commentCommandService.sendGuestBookNotification(guestbookId, commentId); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "204") | ||
}) | ||
@PutMapping("/comments/{comment_id}") | ||
public ResponseEntity<PostResponseDto.SuccessResponseDto> modifyGuestBookComment( | ||
public ResponseEntity<Void> modifyGuestBookComment( | ||
@PathVariable("comment_id") Long commentId, | ||
@RequestBody CommentRequestDto.ModifyComment dto | ||
){ | ||
Member member = securityUtil.getUser(); | ||
// Member member = memberRepository.findById(1L).orElseThrow(() -> new RestApiException(ErrorCode.USER_NOT_FOUND)); | ||
commentCommandService.modifyComment(member, commentId, dto.getContent()); | ||
return new ResponseEntity<>( | ||
PostResponseDto.SuccessResponseDto.builder().message("댓글 성공적으로 수정했습니다.").build(), | ||
HttpStatus.OK | ||
HttpStatus.NO_CONTENT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. http status에 대한 이해 없이 개발을 하다보니 놓친 부분이었는데, 유리님이 코드 수정해주셔서 저도 다른 api를 웹 규약에 맞게 수정해야겠다는 생각이 들었네요. 감사합니다! |
||
); | ||
} | ||
|
||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "204") | ||
}) | ||
@DeleteMapping("/comments/{comment_id}") | ||
public ResponseEntity<PostResponseDto.SuccessResponseDto> deleteGuestBookComment( | ||
public ResponseEntity<Void> deleteGuestBookComment( | ||
@PathVariable("comment_id") Long commentId | ||
){ | ||
Member member = securityUtil.getUser(); | ||
// Member member = memberRepository.findById(1L).orElseThrow(() -> new RestApiException(ErrorCode.USER_NOT_FOUND)); | ||
commentCommandService.deleteComment(member, commentId); | ||
return new ResponseEntity<>( | ||
PostResponseDto.SuccessResponseDto.builder().message("댓글 성공적으로 삭제했습니다.").build(), | ||
HttpStatus.OK | ||
HttpStatus.NO_CONTENT | ||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
import com.favoriteplace.app.service.community.GuestBookQueryService; | ||
import com.favoriteplace.app.service.community.LikedPostService; | ||
import com.favoriteplace.global.util.SecurityUtil; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
@@ -80,47 +82,51 @@ public GuestBookResponseDto.DetailGuestBookDto getDetailGuestBook( | |
return guestBookQueryService.getDetailGuestBookInfo(guestBookId, member); | ||
} | ||
|
||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "204") | ||
}) | ||
@PatchMapping("/{guestbook_id}") | ||
public ResponseEntity<PostResponseDto.SuccessResponseDto> modifyGuestBook( | ||
public ResponseEntity<Void> modifyGuestBook( | ||
@PathVariable("guestbook_id") Long guestbookId, | ||
@RequestPart GuestBookRequestDto.ModifyGuestBookDto data, | ||
@RequestPart(required = false) List<MultipartFile> images | ||
) throws IOException { | ||
Member member = securityUtil.getUser(); | ||
guestBookCommandService.modifyGuestBook(member, guestbookId, data, images); | ||
return new ResponseEntity<>( | ||
PostResponseDto.SuccessResponseDto.builder().message("성지순례 인증글을 성공적으로 수정했습니다.").build(), | ||
HttpStatus.OK | ||
HttpStatus.NO_CONTENT | ||
); | ||
} | ||
Comment on lines
96
to
99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spring은 취향 차이일 수도 있지만 해당 코드를 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오! 빌더 좋은 것 같아요! |
||
|
||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "204") | ||
}) | ||
@DeleteMapping("/{guestbook_id}") | ||
public ResponseEntity<PostResponseDto.SuccessResponseDto> deleteGuestBook( | ||
public ResponseEntity<Void> deleteGuestBook( | ||
@PathVariable("guestbook_id") Long guestbookId | ||
){ | ||
Member member = securityUtil.getUser(); | ||
guestBookCommandService.deleteGuestBook(member, guestbookId); | ||
return new ResponseEntity<>( | ||
PostResponseDto.SuccessResponseDto.builder().message("성지순례 인증글을 성공적으로 삭제했습니다.").build(), | ||
HttpStatus.OK | ||
HttpStatus.NO_CONTENT | ||
); | ||
} | ||
|
||
@PostMapping("/{guestbook_id}/like") | ||
public ResponseEntity<PostResponseDto.SuccessResponseDto> modifyGuestBookLike( | ||
public ResponseEntity<PostResponseDto.LikeSuccessResponseDto> modifyGuestBookLike( | ||
@PathVariable("guestbook_id") Long guestbookId | ||
){ | ||
Member member = securityUtil.getUser(); | ||
String message = likedPostService.modifyGuestBookLike(member, guestbookId); | ||
Long likedId = likedPostService.modifyGuestBookLike(member, guestbookId); | ||
return new ResponseEntity<>( | ||
PostResponseDto.SuccessResponseDto.builder().message(message).build(), | ||
PostResponseDto.LikeSuccessResponseDto.builder().likedId(likedId).build(), | ||
HttpStatus.OK | ||
); | ||
} | ||
Comment on lines
115
to
125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. message 대신, 생성된 likeId만 담아서 보내는 방향으로 리팩하신 이유가 궁금해요! ㅎㅎ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 API는 특정 게시글에 좋아요, 좋아요 취소를 제공하는 기능입니다! 기존의 방식에는 "좋아요를 눌렀습니다", "좋아요를 취소했습니다."를 message에 전달했는데, 해당 값은 프론트에서 유의미 하게 쓰이는 값이 아니라서 message는 제거를 했습니다. LikedId는 Post 행위인 만큼 생성된 자원의 id를 반환하고자 추가를 했는데, 사실 likedId를 사용하는 API가 없네요..허헣ㅎㅎ |
||
|
||
// 성지순례 장소 방문 인증글 작성하기 | ||
@PostMapping("/{pilgrimage_id}") | ||
public PostResponseDto.SuccessResponseDto postToPilgrimage( | ||
public PostResponseDto.GuestBookIdResponseDto postToPilgrimage( | ||
@PathVariable("pilgrimage_id") Long pilgrimageId, | ||
@RequestPart GuestBookRequestDto.ModifyGuestBookDto data, | ||
@RequestPart(required = false) List<MultipartFile> images | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 스웨거 문서화를 위해 추가해주신건가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네! 해당 코드를 추가하지 않으면 코드에는 204로 설정해도, 스웨거에서는 200으로 뜨더라구요.