Skip to content

Commit

Permalink
#293 Feat: post 축약되어 나오는 부분 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-haeseung committed Jan 13, 2025
1 parent 80ecb4b commit e4ef3c9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private void sendMemberNewPostAlert(Post post) {
// 이벤트 저장
AlertEvent event = saveEvent(
EventCategory.FOLLOWING_MEMBER_NEW_POST,
PostConverter.toSimplePostResponseDto(post),
PostConverter.toPostPreviewDTO(post),
receiverIdList
);

Expand Down Expand Up @@ -383,7 +383,7 @@ private void sendTeamNewPostAlertToTeamFollowers(Post post) {
// 이벤트 저장
AlertEvent event = saveEvent(
EventCategory.FOLLOWING_TEAM_NEW_POST,
PostConverter.toSimplePostResponseDto(post),
PostConverter.toPostPreviewDTO(post),
receiverIdList
);

Expand Down Expand Up @@ -415,7 +415,7 @@ private void sendTeamNewPostAlertToTeamMembers(Post post) {
// 이벤트 저장
AlertEvent event = saveEvent(
EventCategory.MY_TEAM_NEW_POST,
PostConverter.toSimplePostResponseDto(post),
PostConverter.toPostPreviewDTO(post),
receiverIdList
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.codiary.backend.global.apiPayload.exception.GeneralException;
import com.codiary.backend.global.jwt.JwtTokenProvider;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
Expand Down Expand Up @@ -185,7 +184,7 @@ public ApiResponse<PostResponseDTO.PostAdjacentDTO> findAdjacentPosts(@PathVaria
// 전체 인기글 or 최신글 조회
@Operation(summary = "공개글 리스트 조회", description = "popular/latest 입력 시 인기글/최신글 조회")
@GetMapping("/list")
public ApiResponse<Page<PostResponseDTO.SimplePostResponseDTO>> getPostList(
public ApiResponse<Page<PostResponseDTO.PostPreviewDTO>> getPostList(
@PageableDefault(size = 9) Pageable pageable
) {
Page<Post> postPage = postService.getPostList(pageable);
Expand All @@ -195,7 +194,7 @@ public ApiResponse<Page<PostResponseDTO.SimplePostResponseDTO>> getPostList(
// 카테고리 인기글 조회
@Operation(summary = "카테고리 인기글/최신글 조회 (popular/latest 입력 (기본 popular)")
@GetMapping("/category/{category_id}")
public ApiResponse<Page<PostResponseDTO.SimplePostResponseDTO>> getCategoryPopularPosts(
public ApiResponse<Page<PostResponseDTO.PostPreviewDTO>> getCategoryPopularPosts(
@AuthenticationPrincipal CustomMemberDetails memberDetails,
@PathVariable("category_id") Long categoryId,
@PageableDefault(size = 9, sort = "popular") Pageable pageable
Expand All @@ -220,7 +219,7 @@ public ApiResponse<Page<PostResponseDTO.SimplePostResponseDTO>> getCategoryPopul
// 게시글 검색 결과 페이지네이션
@Operation(summary = "게시글 검색 결과 페이지네이션", description = "게시글(제목/내용) 키워드 검색 결과를 페이지네이션하여 반환합니다.")
@GetMapping("/search")
public ApiResponse<Page<PostResponseDTO.SimplePostResponseDTO>> searchPost(
public ApiResponse<Page<PostResponseDTO.PostPreviewDTO>> searchPost(
@RequestParam(value = "keyword", defaultValue = "", required = false) String keyword,
@AuthenticationPrincipal CustomMemberDetails memberDetails,
@PageableDefault(size = 9) Pageable pageable
Expand Down Expand Up @@ -249,7 +248,7 @@ public ApiResponse<PostResponseDTO.UpdatePostResultDTO> setPostCategory(
// 게시글 검색 (저자 이름, 팀 이름, 프로젝트 이름으로 검색)
@GetMapping("/search_by_name")
@Operation(summary = "게시글 검색 (저자 이름, 팀 이름, 프로젝트 이름으로 검색)")
public ApiResponse<Page<PostResponseDTO.SimplePostResponseDTO>> searchByName(
public ApiResponse<Page<PostResponseDTO.PostPreviewDTO>> searchByName(
@RequestParam(value = "author", defaultValue = "", required = false) String authorName,
@RequestParam(value = "team", defaultValue = "", required = false) String teamName,
@RequestParam(value = "project", defaultValue = "", required = false) String projectName,
Expand Down Expand Up @@ -300,8 +299,8 @@ public ApiResponse<PostResponseDTO.PostPreviewListDTO> findPostByFollowing(@Auth

@GetMapping("/bookmark/paging")
@Operation(summary = "북마크한 게시글 조회")
public ApiResponse<Page<PostResponseDTO.SimplePostResponseDTO>> getBookmarkPost(@AuthenticationPrincipal CustomMemberDetails memberDetails,
@PageableDefault(size = 9) Pageable pageable) {
public ApiResponse<Page<PostResponseDTO.PostPreviewDTO>> getBookmarkPost(@AuthenticationPrincipal CustomMemberDetails memberDetails,
@PageableDefault(size = 9) Pageable pageable) {
return ApiResponse.onSuccess(SuccessStatus.POST_OK,
PostConverter.toPostListResponseDto(postQueryService.getBookmarkPost(memberDetails.getId(), pageable)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,29 @@

public class PostConverter {

public static Page<PostResponseDTO.SimplePostResponseDTO> toPostListResponseDto(Page<Post> postList) {
return postList.map(PostConverter::toSimplePostResponseDto);
public static Page<PostResponseDTO.PostPreviewDTO> toPostListResponseDto(Page<Post> postList) {
return postList.map(PostConverter::toPostPreviewDTO);
}

public static PostResponseDTO.SimplePostResponseDTO toSimplePostResponseDto(Post post) {
return PostResponseDTO.SimplePostResponseDTO.builder()
public static PostResponseDTO.PostPreviewDTO toPostPreviewDTO(Post post) {
return PostResponseDTO.PostPreviewDTO.builder()
.id(post.getPostId())
.title(post.getPostTitle())
.body(post.getPostBody())
.author(post.getMember() != null ? post.getMember().getNickname() : null)
.authorImageUrl((post.getMember() != null && post.getMember().getImage() != null)
? post.getMember().getImage().getImageUrl()
: "")
.thumbnailImageUrl(post.getThumbnailImage() != null ? post.getThumbnailImage().getFileUrl() : "")
.teamProfileImageUrl((post.getTeam() != null && post.getTeam().getProfileImage() != null)
? post.getTeam().getProfileImage().getImageUrl()
: "")
.teamBannerImageUrl((post.getTeam() != null && post.getTeam().getBannerImage() != null)
? post.getTeam().getBannerImage().getImageUrl()
: "")
.thumbnailImageUrl(post.getThumbnailImage().getFileUrl())
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())

.authorId(post.getMember().getMemberId())
.authorName(post.getMember().getNickname())
.authorImageUrl(post.getMember().getImage().getImageUrl())

.numberOfCoauthor(post.getAuthorList().size())

.teamExist((post.getTeam() != null) ? true : false)
.teamId((post.getTeam() != null) ? post.getTeam().getTeamId() : null)
.teamName((post.getTeam() != null) ? post.getTeam().getName() : null)
.teamProfileImageUrl((post.getTeam() != null) ? post.getTeam().getProfileImage().getImageUrl() : null)
.build();
}

Expand Down Expand Up @@ -118,45 +119,6 @@ public static PostResponseDTO.UpdatePostResultDTO toUpdatePostResultDTO(Post pos
.build();
}

// Post 조회
public static PostResponseDTO.PostPreviewDTO toPostPreviewDTO(Post post) {
List<String> postCategories = post.getCategoriesList().stream()
.map(Category::getName)
.collect(Collectors.toList());

return PostResponseDTO.PostPreviewDTO.builder()
.postId(post.getPostId())
.memberId(post.getMember().getMemberId())
.authorNickname(post.getMember().getNickname())
.teamId(post.getTeam() != null ? post.getTeam().getTeamId() : null)
.projectId(post.getProject() != null ? post.getProject().getProjectId() : null)
.postTitle(post.getPostTitle())
.postBody(post.getPostBody())
.postStatus(post.getPostStatus())
.postCategory(String.join(", ", postCategories))
.coauthorIds(post.getAuthorList().stream()
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.authorProfileImageUrl((post.getMember().getImage() != null)
? post.getMember().getImage().getImageUrl()
: "")
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.teamProfileImageUrl((post.getTeam() != null && post.getTeam().getProfileImage() != null)
? post.getTeam().getProfileImage().getImageUrl()
: "")
.teamBannerImageUrl((post.getTeam() != null && post.getTeam().getBannerImage() != null)
? post.getTeam().getBannerImage().getImageUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
.authorNickname(post.getMember().getNickname())
.build();
}

// Post 전체 리스트 조회
public static PostResponseDTO.PostPreviewListDTO toPostPreviewListDTO(Page<Post> posts) {
List<PostResponseDTO.PostPreviewDTO> postPreviewDTOList = posts.getContent().stream()
Expand All @@ -173,8 +135,6 @@ public static PostResponseDTO.PostPreviewListDTO toPostPreviewListDTO(Page<Post>
.build();
}



// 저자별 Post 조회
public static PostResponseDTO.MemberPostPreviewDTO toMemberPostPreviewDTO(Post post) {
List<String> postCategories = post.getCategoriesList().stream()
Expand Down Expand Up @@ -445,52 +405,13 @@ public static PostResponseDTO.MemberPostInTeamPreviewListDTO toMemberPostInTeamP
.build();
}

// 특정 Post의 인접한 Post 조회 (이전, 다음 Post 조회)
public static PostResponseDTO.PostAdjacentDTO.PostAdjacentPreviewDTO toPostAdjacentPreviewDTO(Post post) {
if (post == null) return null;

List<String> postCategories = post.getCategoriesList().stream()
.map(Category::getName)
.collect(Collectors.toList());

return PostResponseDTO.PostAdjacentDTO.PostAdjacentPreviewDTO.builder()
.postId(post.getPostId())
.memberId(post.getMember().getMemberId())
.authorNickname(post.getMember().getNickname())
.teamId(post.getTeam() != null ? post.getTeam().getTeamId() : null)
.projectId(post.getProject() != null ? post.getProject().getProjectId() : null)
.postTitle(post.getPostTitle())
.postBody(post.getPostBody())
.postStatus(post.getPostStatus())
.postCategory(String.join(", ", postCategories))
.coauthorIds(post.getAuthorList().stream()
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.authorProfileImageUrl((post.getMember().getImage() != null)
? post.getMember().getImage().getImageUrl()
: "")
.thumbnailImageUrl((post.getThumbnailImage() != null)
? post.getThumbnailImage().getFileUrl()
: "")
.teamProfileImageUrl((post.getTeam() != null && post.getTeam().getProfileImage() != null)
? post.getTeam().getProfileImage().getImageUrl()
: "")
.teamBannerImageUrl((post.getTeam() != null && post.getTeam().getBannerImage() != null)
? post.getTeam().getBannerImage().getImageUrl()
: "")
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
.build();
}

// 인접 post 조회
public static PostResponseDTO.PostAdjacentDTO toPostAdjacentDTO(Post.PostAdjacent adjacent) {
return PostResponseDTO.PostAdjacentDTO.builder()
.hadOlder(adjacent.getOlderPost() != null)
.hasLater(adjacent.getLaterPost() != null)
.olderPost(toPostAdjacentPreviewDTO(adjacent.getOlderPost()))
.laterPost(toPostAdjacentPreviewDTO(adjacent.getLaterPost()))
.olderPost(toPostPreviewDTO(adjacent.getOlderPost()))
.laterPost(toPostPreviewDTO(adjacent.getLaterPost()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@ public class PostResponseDTO {
@Builder
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public record SimplePostResponseDTO(
public record PostPreviewDTO(
// post 자체 정보
Long id,
String title,
String body,
String author,
String authorImageUrl,
String thumbnailImageUrl,
String teamProfileImageUrl,
String teamBannerImageUrl,
LocalDateTime createdAt,
LocalDateTime updatedAt
LocalDateTime updatedAt,
Integer numberOfBookmark,
// author 정보
Long authorId,
String authorName,
String authorImageUrl,
// coauthor 정보
Integer numberOfCoauthor,
// team 정보
Boolean teamExist, // true 인 경우 아래 내용 작성
Long teamId,
String teamName,
String teamProfileImageUrl
) {
}

Expand Down Expand Up @@ -89,32 +98,6 @@ public static class UpdatePostResultDTO {
LocalDateTime updatedAt;
}


@Builder
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public record PostPreviewDTO ( // Post 조회
Long postId,
Long memberId,
String authorNickname,
String authorProfileImageUrl,
Long teamId,
String teamProfileImageUrl,
String teamBannerImageUrl,
Long projectId,
String postTitle,
String postBody,
String thumbnailImageUrl,
Boolean postStatus,
String postCategory,
Set<Long> coauthorIds,
PostAccess postAccess,
PostFileResponseDTO.PostFileListDTO postFileList,
LocalDateTime createdAt,
LocalDateTime updatedAt
){
}

@Builder
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down Expand Up @@ -327,8 +310,8 @@ public record MemberPostInTeamPreviewListDTO(
public record PostAdjacentDTO(
Boolean hasLater,
Boolean hadOlder,
PostAdjacentPreviewDTO laterPost,
PostAdjacentPreviewDTO olderPost
PostPreviewDTO laterPost,
PostPreviewDTO olderPost
) {
@Builder
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
Expand Down

0 comments on commit e4ef3c9

Please sign in to comment.