Skip to content

Commit

Permalink
자유게시판, 성지순례 인증글 response DTO, status 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jorippppong committed Sep 24, 2024
1 parent 27ee133 commit cca1718
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 75 deletions.
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(
Expand All @@ -46,15 +45,14 @@ 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
);
}
Expand All @@ -68,30 +66,32 @@ public ResponseEntity<?> sendGuestBookNotification(
return ResponseEntity.ok().build();
}

@ApiResponses(value = {
@ApiResponse(responseCode = "204")
})
@PutMapping("/comments/{comment_id}")
public ResponseEntity<PostResponseDto.SuccessResponseDto> modifyGuestBookComment(
public ResponseEntity<?> 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
);
}

@ApiResponses(value = {
@ApiResponse(responseCode = "204")
})
@DeleteMapping("/comments/{comment_id}")
public ResponseEntity<PostResponseDto.SuccessResponseDto> deleteGuestBookComment(
public ResponseEntity<?> 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
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<?> 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
);
}

@ApiResponses(value = {
@ApiResponse(responseCode = "204")
})
@DeleteMapping("/{guestbook_id}")
public ResponseEntity<PostResponseDto.SuccessResponseDto> deleteGuestBook(
public ResponseEntity<?> 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
);
}

// 성지순례 장소 방문 인증글 작성하기
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.favoriteplace.app.service.MyPageCommandService;
import com.favoriteplace.app.service.MyPageQueryService;
import com.favoriteplace.global.util.SecurityUtil;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -89,6 +91,9 @@ public MyPageDto.MyModifyBlockDto modifyMemberBlock(
}

//FCM token 등록 & 변경
@ApiResponses(value = {
@ApiResponse(responseCode = "204")
})
@PatchMapping("/fcmToken")
public ResponseEntity<?> modifyFcmToken(
@Valid @RequestBody MyFcmTokenDto request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.favoriteplace.app.dto.NotificationResponseDto;
import com.favoriteplace.app.service.NotificationService;
import com.favoriteplace.global.util.SecurityUtil;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -30,6 +32,9 @@ public ResponseEntity<NotificationResponseDto> getAllNotification(
}

// 알림 한번에 다 읽음 처리
@ApiResponses(value = {
@ApiResponse(responseCode = "204")
})
@PatchMapping()
public ResponseEntity<?> readAllNotification(){
Member member = securityUtil.getUser();
Expand All @@ -38,6 +43,9 @@ public ResponseEntity<?> readAllNotification(){
}

// 특정 알림 읽음 처리
@ApiResponses(value = {
@ApiResponse(responseCode = "204")
})
@PatchMapping("/{notificationId}")
public ResponseEntity<?> readNotification(
@PathVariable Long notificationId
Expand All @@ -48,6 +56,9 @@ public ResponseEntity<?> readNotification(
}

// 특정 알림 삭제
@ApiResponses(value = {
@ApiResponse(responseCode = "204")
})
@DeleteMapping("/{notificationId}")
public ResponseEntity<?> deleteNotification(
@PathVariable Long notificationId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
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.repository.MemberRepository;
import com.favoriteplace.app.service.community.CommentCommandService;
import com.favoriteplace.app.service.community.CommentQueryService;
import com.favoriteplace.global.exception.ErrorCode;
import com.favoriteplace.global.exception.RestApiException;
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;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.favoriteplace.app.dto.community.PostResponseDto.*;
import static com.favoriteplace.app.dto.community.PostResponseDto.MyCommentDto;
import static com.favoriteplace.app.dto.community.PostResponseDto.CommentSuccessResponseDto;

@RestController
@RequestMapping("/posts/free")
Expand All @@ -28,15 +25,13 @@ public class PostCommentController {
private final SecurityUtil securityUtil;
private final CommentQueryService commentQueryService;
private final CommentCommandService commentCommandService;
private final MemberRepository memberRepository;

@GetMapping("/my-comments")
public ResponseEntity<MyCommentDto> getMyComments(
@RequestParam(required = false, defaultValue = "1") int page,
@RequestParam(required = false, defaultValue = "10") int size
){
//Member member = securityUtil.getUser();
Member member = memberRepository.findById(1L).orElseThrow(() -> new RestApiException(ErrorCode.USER_NOT_FOUND));
Member member = securityUtil.getUser();
return ResponseEntity.ok(commentQueryService.getMyPostComments(member, page, size));
}

Expand All @@ -52,15 +47,14 @@ public ResponseEntity<CommentResponseDto.CommentDto> getPostComments(
}

@PostMapping("/{post_id}/comments")
public ResponseEntity<SuccessResponseDto> createPostComment(
public ResponseEntity<CommentSuccessResponseDto> createPostComment(
@PathVariable("post_id") Long postId,
@RequestBody CommentRequestDto.CreateComment dto
){
Member member = securityUtil.getUser();
// Member member = memberRepository.findById(1L).orElseThrow(() -> new RestApiException(ErrorCode.USER_NOT_FOUND));
Long commentId = commentCommandService.createPostComment(member, postId, dto);
return new ResponseEntity<>(
SuccessResponseDto.builder().commentId(commentId).message("댓글을 성공적으로 등록했습니다.").build(),
CommentSuccessResponseDto.builder().commentId(commentId).build(),
HttpStatus.OK
);
}
Expand All @@ -74,30 +68,32 @@ public ResponseEntity<?> sendPostNotification(
return ResponseEntity.ok().build();
}

@ApiResponses(value = {
@ApiResponse(responseCode = "204")
})
@PutMapping("/comments/{comment_id}")
public ResponseEntity<SuccessResponseDto> modifyPostComment(
public ResponseEntity<?> modifyPostComment(
@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<>(
SuccessResponseDto.builder().message("댓글을 성공적으로 수정했습니다.").build(),
HttpStatus.OK
HttpStatus.NO_CONTENT
);
}

@ApiResponses(value = {
@ApiResponse(responseCode = "204")
})
@DeleteMapping("/comments/{comment_id}")
public ResponseEntity<SuccessResponseDto> deletePostComment(
public ResponseEntity<CommentSuccessResponseDto> deletePostComment(
@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<>(
SuccessResponseDto.builder().message("댓글을 성공적으로 삭제했습니다.").build(),
HttpStatus.OK
HttpStatus.NO_CONTENT
);
}

Expand Down
25 changes: 15 additions & 10 deletions src/main/java/com/favoriteplace/app/controller/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import com.favoriteplace.app.domain.Member;
import com.favoriteplace.app.dto.community.PostRequestDto;
import com.favoriteplace.app.dto.community.PostResponseDto;
import com.favoriteplace.app.service.MemberService;
import com.favoriteplace.app.service.community.LikedPostService;
import com.favoriteplace.app.service.community.PostCommandService;
import com.favoriteplace.app.service.community.PostQueryService;
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;
Expand All @@ -22,7 +23,6 @@
@RequestMapping("/posts/free")
@RequiredArgsConstructor
public class PostController {
private final MemberService memberService;
private final PostQueryService postQueryService;
private final PostCommandService postCommandService;
private final LikedPostService likedPostService;
Expand Down Expand Up @@ -92,32 +92,37 @@ public ResponseEntity<PostResponseDto.PostIdResponseDto> createPost(
HttpStatus.OK);
}

@ApiResponses(value = {
@ApiResponse(responseCode = "204")
})
@DeleteMapping("/{post_id}")
public ResponseEntity<PostResponseDto.SuccessResponseDto> deletePost(
public ResponseEntity<?> deletePost(
@PathVariable("post_id") long postId
){
Member member = securityUtil.getUser();
postCommandService.deletePost(postId, member);
return new ResponseEntity<>(
PostResponseDto.SuccessResponseDto.builder().message("게시글이 성공적으로 삭제되었습니다.").build(),
HttpStatus.OK
HttpStatus.NO_CONTENT
);
}

@PutMapping("/{post_id}/like")
public ResponseEntity<PostResponseDto.SuccessResponseDto> modifyPostLike(
@PostMapping("/{post_id}/like")
public ResponseEntity<PostResponseDto.LikeSuccessResponseDto> modifyPostLike(
@PathVariable("post_id") long postId
){
Member member = securityUtil.getUser();
String message = likedPostService.modifyPostLike(member, postId);
Long likedId = likedPostService.modifyPostLike(member, postId);
return new ResponseEntity<>(
PostResponseDto.SuccessResponseDto.builder().message(message).build(),
PostResponseDto.LikeSuccessResponseDto.builder().likedId(likedId).build(),
HttpStatus.OK
);
}

@ApiResponses(value = {
@ApiResponse(responseCode = "204")
})
@PatchMapping("/{post_id}")
public ResponseEntity<PostResponseDto.SuccessResponseDto> modifyPost(
public ResponseEntity<?> modifyPost(
@PathVariable("post_id") Long postId,
@RequestPart PostRequestDto data,
@RequestPart(required = false) List<MultipartFile> images
Expand Down
Loading

0 comments on commit cca1718

Please sign in to comment.