Skip to content

Commit

Permalink
[refactor] #98 게시글 리스트 조회 factory 패턴으로 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
qogustj committed Aug 28, 2024
2 parents 823d899 + aba533a commit 0f818bb
Show file tree
Hide file tree
Showing 49 changed files with 518 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ public ResponseEntity<ApiResponse<?>> createPostComment(@Parameter(hidden = true
요청 url 상에 postId 와 commentId를 받습니다. 즉, 게시물 id와 댓글 id를 받습니다.
PostCommentUpdateRequest 요청 json에 content 필드를 이용하여 댓글 내용을 작성합니다.
""")
@PatchMapping("/posts/{postId}/comments/{commentId}")
@PatchMapping("/posts/comments/{commentId}")
public ResponseEntity<ApiResponse<?>> editPostComment(@Parameter(hidden = true) @UserId Long userId,
@PathVariable(name = "postId") Long postId,
@PathVariable(name = "commentId") Long commentId,
@RequestBody PostCommentUpdateRequest postCommentUpdateRequest) {
commentService.editComment(userId, postId, commentId, postCommentUpdateRequest);
commentService.editComment(userId, commentId, postCommentUpdateRequest);
return ApiResponse.success(null);
}

Expand All @@ -69,4 +68,4 @@ public ResponseEntity<ApiResponse<?>> deletePostComment(@Parameter(hidden = true
commentService.deleteComment(commentId);
return ApiResponse.success(null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ public ResponseEntity<ApiResponse<?>> createPostReplyComment(@Parameter(hidden =
요청 url 상에 commentId 와 reply-commentId를 받습니다. 즉, 댓글 id와 대댓글 id를 받습니다.
PostReplyCommentUpdateRequest 요청 json에 content 필드를 이용하여 댓글 내용을 작성합니다.
""")
@PatchMapping("/posts/comments/{commentId}/reply-comments/{reply-commentId}")
@PatchMapping("/posts/comments/reply-comments/{reply-commentId}")
public ResponseEntity<ApiResponse<?>> editPostReplyComment(@Parameter(hidden = true) @UserId Long userId,
@PathVariable(name = "commentId") Long commentId,
@PathVariable(name = "reply-commentId") Long replyCommentId,
@RequestBody PostReplyCommentUpdateRequest postReplyCommentUpdateRequest) {
postReplyCommentService.editReplyComment(userId, commentId, replyCommentId, postReplyCommentUpdateRequest);
postReplyCommentService.editReplyComment(userId, replyCommentId, postReplyCommentUpdateRequest);
return ApiResponse.success(null);
}

Expand All @@ -57,4 +56,4 @@ public ResponseEntity<ApiResponse<?>> deletePostReplyComment(@Parameter(hidden =
postReplyCommentService.deleteReplyComment(replyCommentId);
return ApiResponse.success(null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public PostCommentResponse createComment(Long userId, Long postId, PostCommentCr
}

@Transactional
public PostCommentResponse editComment(Long userId, Long postId, Long commentId, PostCommentUpdateRequest postCommentUpdateRequest){
public PostCommentResponse editComment(Long userId, Long commentId, PostCommentUpdateRequest postCommentUpdateRequest){
PostComment postComment = postCommentReader.getPostComment(commentId);
PostComment editedPostComment = postCommentModifier.updateComment(postComment, userId, postId, commentId, postCommentUpdateRequest);
PostComment editedPostComment = postCommentModifier.updateComment(postComment, userId, commentId, postCommentUpdateRequest);
// PostComment postComment = postCommentModifier.updateComment(userId, postId, commentId, , postCommentUpdateRequest);
// return postCommentFormatter.format(postComment.getPostId(), postComment.getUserId(), postComment.getCommentType());
return postCommentFormatter.format(editedPostComment, userId);
Expand All @@ -60,4 +60,4 @@ private Pageable setPageable(int page, int take){
return PageRequest.of(page, take);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import ussum.homepage.domain.comment.PostComment;
import ussum.homepage.domain.comment.service.PostCommentFormatter;
import ussum.homepage.domain.comment.service.PostCommentReader;
import ussum.homepage.domain.reaction.service.PostCommentReactionManager;
import ussum.homepage.domain.reaction.service.PostReplyCommentReactionManager;


import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public PostReplyCommentResponse createReplyComment(Long userId, Long commentId,
}

@Transactional
public PostReplyCommentResponse editReplyComment(Long userId, Long commentId, Long replyCommentId, PostReplyCommentUpdateRequest postReplyCommentUpdateRequest) {
public PostReplyCommentResponse editReplyComment(Long userId, Long replyCommentId, PostReplyCommentUpdateRequest postReplyCommentUpdateRequest) {
PostReplyComment postReplyComment = postReplyCommentReader.getPostReplyComment(replyCommentId);
return postReplyCommentFormatter.format(postReplyCommentModifier.updatePostReplyComment(postReplyComment, userId, commentId, postReplyCommentUpdateRequest), userId);
return postReplyCommentFormatter.format(postReplyCommentModifier.updatePostReplyComment(postReplyComment, userId, postReplyCommentUpdateRequest), userId);
}

@Transactional
public void deleteReplyComment(Long replyCommentId) {
postReplyCommentModifier.deletePostReplyComment(replyCommentId); //일단은 자기것만 삭제
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
public record PostCommentUpdateRequest(
String content
) {
public PostComment toDomain(PostComment postComment, Long commentId, Long postId, Long userId) {
public PostComment toDomain(PostComment postComment, Long commentId, Long userId) {
return PostComment.of(
commentId,
content,
postId,
postComment.getPostId(),
userId,
postComment.getCommentType(),
DateUtils.parseHourMinSecFromCustomString(postComment.getCreatedAt()),
Expand All @@ -23,4 +23,4 @@ public PostComment toDomain(PostComment postComment, Long commentId, Long postId
);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
public record PostReplyCommentUpdateRequest(
String content
) {
public PostReplyComment toDomain(PostReplyComment postReplyComment, Long userId, Long commentId) {
public PostReplyComment toDomain(PostReplyComment postReplyComment, Long userId) {
return PostReplyComment.of(
postReplyComment.getId(),
content,
commentId,
postReplyComment.getCommentId(),
userId,
DateUtils.parseHourMinSecFromCustomString(postReplyComment.getCreatedAt()),
LocalDateTime.now(),
Expand All @@ -21,4 +21,4 @@ public PostReplyComment toDomain(PostReplyComment postReplyComment, Long userId,
DateUtils.parseHourMinSecFromCustomString(postReplyComment.getDeletedAt())
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public record PostCommentResponse(
String lastEditedAt,
Integer likeCount,
Boolean isAuthor,
Boolean isLiked,
Boolean isDeleted,
List<PostReplyCommentResponse> postReplyComments
) {
public static PostCommentResponse of(PostComment postComment, User user, String commentType, Integer likeCount, Boolean isAuthor, List<PostReplyCommentResponse> postReplyComments) {
public static PostCommentResponse of(PostComment postComment, User user, String commentType, Integer likeCount, Boolean isAuthor, Boolean isLiked, List<PostReplyCommentResponse> postReplyComments) {
String studentId = user.getStudentId();
String content = postComment.getContent();
if (postComment.getIsDeleted().equals(true)) {
Expand All @@ -36,6 +37,7 @@ public static PostCommentResponse of(PostComment postComment, User user, String
postComment.getLastEditedAt(),
likeCount,
isAuthor,
isLiked,
postComment.getIsDeleted(),
postReplyComments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ public record PostReplyCommentResponse(
String lastEditedAt,
Integer likeCount,
Boolean isAuthor,
Boolean isLiked,
Boolean isDeleted
) {
public static PostReplyCommentResponse of(PostReplyComment postReplyComment, User user, Integer likeCount, Boolean isAuthor) {
public static PostReplyCommentResponse of(PostReplyComment postReplyComment, User user, Integer likeCount, Boolean isAuthor, Boolean isLiked) {
String studentId = user.getStudentId();
String content = postReplyComment.getContent();
if (postReplyComment.getIsDeleted().equals(true)) {
Expand All @@ -30,6 +31,7 @@ public static PostReplyCommentResponse of(PostReplyComment postReplyComment, Use
postReplyComment.getLastEditedAt(),
likeCount,
isAuthor,
isLiked,
postReplyComment.getIsDeleted()
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@
package ussum.homepage.application.post.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ussum.homepage.application.post.service.PostService;
import ussum.homepage.application.post.service.dto.request.PostCreateRequest;
import ussum.homepage.application.post.service.dto.response.TopLikedPostListResponse;
import ussum.homepage.global.ApiResponse;
import ussum.homepage.global.config.auth.UserId;

@RestController
@RequiredArgsConstructor
@RequestMapping("/boards")
public class PostController {
private final PostService postService;
// private final PostService postService;

// @GetMapping("/{boardCode}/posts")
// public ResponseEntity<ApiResponse<?>> getBoardPostsList(@RequestParam(value = "page", defaultValue = "0") int page,
// @RequestParam(value = "take") int take,
// @PathVariable(name = "boardCode") String boardCode) {
// @PathVariable(name = "boardCode") String boardCode) {
//
// PostListResponse postList = postService.getPostList(PageRequest.of(page, take, Sort.by("id").descending()), boardCode);
// return ApiResponse.success(postList);
// }

@Operation(summary = "게시판 인기청원 조회 api", description = """
게시판 인기청원 조회 시 필요한 데이터를 조회하는 api 입니다.
요청으로 boardCode 그리고 qeury param 형식으로 page, take를 입력하시면 됩니다.
""")
@GetMapping("/{boardCode}/posts/top-liked")
public ResponseEntity<ApiResponse<?>> getTopLikedBoardPostList(@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "take") int take,
@PathVariable(name = "boardCode") String boardCode) {

TopLikedPostListResponse postList = postService.getTopLikedPostList(page, take, boardCode);
return ApiResponse.success(postList);
}
// @Operation(summary = "게시판 인기청원 조회 api", description = """
// 게시판 인기청원 조회 시 필요한 데이터를 조회하는 api 입니다.
// 요청으로 boardCode 그리고 qeury param 형식으로 page, take를 입력하시면 됩니다.
// """)
// @GetMapping("/{boardCode}/posts/top-liked")
// public ResponseEntity<ApiResponse<?>> getTopLikedBoardPostList(@RequestParam(value = "page", defaultValue = "0") int page,
// @RequestParam(value = "take") int take,
// @PathVariable(name = "boardCode") String boardCode) {
//
// TopLikedPostListResponse postList = postService.getTopLikedPostList(page, take, boardCode);
// return ApiResponse.success(postList);
// }

// @GetMapping("/{boardCode}/posts/{postId}")
// public ResponseEntity<ApiResponse<?>> getBoardPost(@PathVariable(name = "boardCode") String boardCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ussum.homepage.application.post.service.dto.request.PostFileDeleteRequest;
import ussum.homepage.application.post.service.dto.request.PostUpdateRequest;
import ussum.homepage.application.post.service.dto.request.PostUserRequest;
import ussum.homepage.application.post.service.dto.response.TopLikedPostListResponse;
import ussum.homepage.global.ApiResponse;
import ussum.homepage.global.config.auth.UserId;

Expand Down Expand Up @@ -67,7 +68,6 @@ public ResponseEntity<ApiResponse<?>> getDataPostsList(@RequestParam(value = "pa
public ResponseEntity<ApiResponse<?>> getBoardPost(@PathVariable(name = "boardCode") String boardCode,
@PathVariable(name = "postId") Long postId,
@RequestParam(required = false) Long userId) {

return ApiResponse.success(postManageService.getPost(userId, boardCode, postId));
}

Expand Down Expand Up @@ -119,7 +119,6 @@ public ResponseEntity<ApiResponse<?>> createBoardPostFile(@Parameter(hidden = tr
@PathVariable(name = "boardCode") String boardCode,
@RequestPart(value = "files", required = false) MultipartFile[] files,
@RequestPart(value = "images", required = false) MultipartFile[] images) {

return ApiResponse.success(postManageService.createBoardPostFile(userId, boardCode, files, images));
}

Expand Down Expand Up @@ -157,4 +156,35 @@ public ResponseEntity<ApiResponse<?>> deleteBoardPost(@Parameter(hidden = true)
return ApiResponse.success(null);
}

@Operation(summary = "검색키워드를 활용한 게시판 별 게시물 리스트 조회 api", description = """
검색키워드를 활용하여 게시판 별 게시물 리스트 조회 시 필요한 데이터를 조회하는 api 입니다.
요청인자에 q는 검색키워드를 의미하여 필수 값은 아닙니다. 아래 설명은 게시판 별 게시물 리스트 조회와 동일합니다.
q(검색 키워드)를 넣고 요청하지 않으면 아무런 값이 반환되지 않습니다. (totalElements는 0)
요청으로 boardCode 그리고 queryParam 형식으로 , groupCode(중앙기구, 단과대학생회), memberCode(중앙운영위원회), category(필터링), page(입력 안 할시 첫번째 페이지), take(몇개 가져올지) 값을 넣으면 됩니다.
공지사항게시판을 사용할때만 groupCode, memberCode에 값을 넣어서 사용하시면 됩니다.
나머지 게시판 필터링은 category에 값을 넣고 사용하시면 됩니다.
""")
@GetMapping("/{boardCode}/posts/search")
public ResponseEntity<ApiResponse<?>> searchBoardPost(@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "take") int take,
@RequestParam(value = "q",required = false) String q,
@PathVariable(name = "boardCode") String boardCode,
@RequestParam(value = "groupCode", required = false) String groupCode,
@RequestParam(value = "memberCode", required = false) String memberCode,
@RequestParam(value = "category", required = false) String category) {
return ApiResponse.success(postManageService.searchPost(page, take, q, boardCode, groupCode, memberCode, category));
}

@Operation(summary = "게시판 인기청원 조회 api", description = """
게시판 인기청원 조회 시 필요한 데이터를 조회하는 api 입니다.
요청으로 boardCode 그리고 qeury param 형식으로 page, take를 입력하시면 됩니다.
""")
@GetMapping("/{boardCode}/posts/top-liked")
public ResponseEntity<ApiResponse<?>> getTopLikedBoardPostList(@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "take") int take,
@PathVariable(name = "boardCode") String boardCode) {
TopLikedPostListResponse postList = postManageService.getTopLikedPostList(page, take, boardCode);
return ApiResponse.success(postList);
}

}
Loading

0 comments on commit 0f818bb

Please sign in to comment.