Skip to content

Commit

Permalink
Merge pull request #205 from TeamDon-tBe/feat/#204
Browse files Browse the repository at this point in the history
  • Loading branch information
bo-ram-bo-ram authored May 7, 2024
2 parents 6077658 + 72e4135 commit b2dd1c2
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,32 @@ public ResponseEntity<ApiResponse<List<ContentGetAllResponseDtoVer2>>> getConten
return ApiResponse.success(GET_CONTENT_ALL_SUCCESS, contentQueryService.getContentAllPagination(memberId, cursor));
}

@GetMapping("v2/contents")
@Operation(summary = "게시글 전체 조회 API(+페이지네이션+이미지) 입니다.",description = "Contents Get with image")
public ResponseEntity<ApiResponse<List<ContentGetAllResponseDtoVer3>>> getContentAllWithImage(Principal principal, @RequestParam(value = "cursor") Long cursor) {
Long memberId = MemberUtil.getMemberId(principal);
return ApiResponse.success(GET_CONTENT_ALL_SUCCESS, contentQueryService.getContentAllWithImage(memberId, cursor));
}

@GetMapping("v1/member/{memberId}/member-contents")
@Operation(summary = "페이지네이션이 적용된 멤버에 해당하는 게시글 리스트 조회 API 입니다.",description = "ContentByMemberPagination")
public ResponseEntity<ApiResponse<List<ContentGetAllByMemberResponseDto>>> getContentAllByMemberPagination(Principal principal,
@PathVariable("memberId") Long targetMemberId, @RequestParam(value = "cursor") Long cursor) {
Long memberId = MemberUtil.getMemberId(principal);
return ApiResponse.success(GET_MEMBER_CONTENT_SUCCESS, contentQueryService.getContentAllByMemberPagination(memberId, targetMemberId, cursor));
}

@GetMapping("v2/member/{memberId}/member-contents")
@Operation(summary = "멤버에 해당하는 게시글 리스트 조회 API(+페이지네이션+이미지) 입니다.",description = "Contents By Member with image")
public ResponseEntity<ApiResponse<List<ContentGetAllByMemberResponseDtoVer2>>> getContentAllByMemberWithImage(Principal principal,
@PathVariable("memberId") Long targetMemberId, @RequestParam(value = "cursor") Long cursor) {
Long memberId = MemberUtil.getMemberId(principal);
return ApiResponse.success(GET_MEMBER_CONTENT_SUCCESS, contentQueryService.getContentAllByMemberWithImage(memberId, targetMemberId, cursor));
}

@GetMapping("v2/content/{contentId}")
@Operation(summary = "게시글 상세 조회 API 입니다.",description = "Content Get Detail")
public ResponseEntity<ApiResponse<ContentGetDetailsResponseDtoVer3>> getContentDetailWithImage(Principal principal, @PathVariable("contentId") Long contentId) {
return ApiResponse.success(GET_CONTENT_DETAIL_SUCCESS, contentQueryService.getContentDetailWithImage(MemberUtil.getMemberId(principal), contentId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.dontbe.www.DontBeServer.api.content.dto.response;

import com.dontbe.www.DontBeServer.api.content.domain.Content;
import com.dontbe.www.DontBeServer.api.member.domain.Member;

public record ContentGetAllByMemberResponseDtoVer2(
Long memberId,
String memberProfileUrl,
String memberNickname,
Long contentId,
String contentText,
String time,
boolean isGhost,
int memberGhost,
boolean isLiked,
int likedNumber,
int commentNumber,
String contentImageUrl
) {
public static ContentGetAllByMemberResponseDtoVer2 of(Member writerMember, int writerGhost, Content content, boolean isGhost, boolean isLiked, String time, int likedNumber, int commentNumber) {
return new ContentGetAllByMemberResponseDtoVer2(
writerMember.getId(),
writerMember.getProfileUrl(),
writerMember.getNickname(),
content.getId(),
content.getContentText(),
time,
isGhost,
writerGhost,
isLiked,
likedNumber,
commentNumber,
content.getContentImage()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.dontbe.www.DontBeServer.api.content.dto.response;

import com.dontbe.www.DontBeServer.api.content.domain.Content;
import com.dontbe.www.DontBeServer.api.member.domain.Member;

public record ContentGetAllResponseDtoVer3(
Long memberId,
String memberProfileUrl,
String memberNickname,
Long contentId,
String contentText,
String time,
boolean isGhost,
int memberGhost,
boolean isLiked,
int likedNumber,
int commentNumber,
Boolean isDeleted,
String contentImageUrl
) {
public static ContentGetAllResponseDtoVer3 of(Member writerMember, Content content, boolean isGhost, int refinedMemberGhost, boolean isLiked, String time, int likedNumber, int commentNumber) {
return new ContentGetAllResponseDtoVer3(
writerMember.getId(),
writerMember.getProfileUrl(),
writerMember.getNickname(),
content.getId(),
content.getContentText(),
time,
isGhost,
refinedMemberGhost,
isLiked,
likedNumber,
commentNumber,
writerMember.isDeleted(),
content.getContentImage()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.dontbe.www.DontBeServer.api.content.dto.response;

import com.dontbe.www.DontBeServer.api.content.domain.Content;
import com.dontbe.www.DontBeServer.api.member.domain.Member;

public record ContentGetDetailsResponseDtoVer3(
Long memberId,
String memberProfileUrl,
String memberNickname,
boolean isGhost,
int memberGhost,
boolean isLiked,
String time,
int likedNumber,
int commentNumber,
String contentText,
Boolean isDeleted,
String contentImageUrl
) {
public static ContentGetDetailsResponseDtoVer3 of(Member member, int memberGhost, Content content, boolean isGhost, boolean isLiked, String time, int likedNumber, int commentNumber) {
return new ContentGetDetailsResponseDtoVer3(
member.getId(),
member.getProfileUrl(),
member.getNickname(),
isGhost,
memberGhost,
isLiked,
time,
likedNumber,
commentNumber,
content.getContentText(),
member.isDeleted(),
content.getContentImage()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ public ContentGetDetailsResponseDtoVer2 getContentDetailVer2(Long memberId, Long
return ContentGetDetailsResponseDtoVer2.of(writerMember, writerMemberGhost, content, isGhost, isLiked, time, likedNumber, commentNumber);
}

public ContentGetDetailsResponseDtoVer3 getContentDetailWithImage(Long memberId, Long contentId) {
Member member = memberRepository.findMemberByIdOrThrow(memberId);
Content content = contentRepository.findContentByIdOrThrow(contentId);
Member writerMember = memberRepository.findMemberByIdOrThrow(content.getMember().getId());
int writerMemberGhost = GhostUtil.refineGhost(writerMember.getMemberGhost());
Long writerMemberId = content.getMember().getId();
boolean isGhost = ghostRepository.existsByGhostTargetMemberIdAndGhostTriggerMemberId(writerMemberId, memberId);
boolean isLiked = contentLikedRepository.existsByContentAndMember(content,member);
String time = TimeUtilCustom.refineTime(content.getCreatedAt());
int likedNumber = contentLikedRepository.countByContent(content);
int commentNumber = commentRepository.countByContent(content);

return ContentGetDetailsResponseDtoVer3.of(writerMember, writerMemberGhost, content, isGhost, isLiked, time, likedNumber, commentNumber);
}

public List<ContentGetAllResponseDto> getContentAll(Long memberId) { //페이지네이션 적용 후 지우기
Member usingMember = memberRepository.findMemberByIdOrThrow(memberId);
List<Content> contents = contentRepository.findAllByOrderByCreatedAtDesc();
Expand Down Expand Up @@ -100,6 +115,30 @@ public List<ContentGetAllResponseDtoVer2> getContentAllPagination(Long memberId,
.collect(Collectors.toList());
}

public List<ContentGetAllResponseDtoVer3> getContentAllWithImage(Long memberId, Long cursor) {
PageRequest pageRequest = PageRequest.of(0, 30);
Member usingMember = memberRepository.findMemberByIdOrThrow(memberId);
Slice<Content> contentList;

if (cursor==-1) {
contentList = contentRepository.findTop30ByOrderByCreatedAtDesc(pageRequest);
} else {
contentList = contentRepository.findContentsNextPage(cursor, pageRequest);
}

return contentList.stream()
.map(oneContent -> ContentGetAllResponseDtoVer3.of(
oneContent.getMember(),
oneContent,
ghostRepository.existsByGhostTargetMemberAndGhostTriggerMember(oneContent.getMember(),usingMember),
GhostUtil.refineGhost(oneContent.getMember().getMemberGhost()),
contentLikedRepository.existsByContentAndMember(oneContent,usingMember),
TimeUtilCustom.refineTime(oneContent.getCreatedAt()),
contentLikedRepository.countByContent(oneContent),
commentRepository.countByContent(oneContent)))
.collect(Collectors.toList());
}

public List<ContentGetAllByMemberResponseDto> getContentAllByMember(Long memberId, Long targetMemberId) { //페이지네이션 적용 후 지우기
Member usingMember = memberRepository.findMemberByIdOrThrow(memberId);
Member targetMember = memberRepository.findMemberByIdOrThrow(targetMemberId);
Expand Down Expand Up @@ -142,4 +181,31 @@ public List<ContentGetAllByMemberResponseDto> getContentAllByMemberPagination(Lo
commentRepository.countByContent(oneContent)))
.collect(Collectors.toList());
}

public List<ContentGetAllByMemberResponseDtoVer2> getContentAllByMemberWithImage(Long memberId, Long targetMemberId, Long cursor) {
Member usingMember = memberRepository.findMemberByIdOrThrow(memberId);
Member targetMember = memberRepository.findMemberByIdOrThrow(targetMemberId);

PageRequest pageRequest = PageRequest.of(0, 20);

Slice<Content> contentList;

if (cursor==-1) {
contentList = contentRepository.findContestsTop20ByMemberIdOrderByCreatedAtDesc(targetMemberId, pageRequest);
} else {
contentList = contentRepository.findContentsByMemberNextPage(cursor, targetMemberId ,pageRequest);
}

return contentList.stream()
.map(oneContent -> ContentGetAllByMemberResponseDtoVer2.of(
targetMember,
GhostUtil.refineGhost(oneContent.getMember().getMemberGhost()),
oneContent,
ghostRepository.existsByGhostTargetMemberAndGhostTriggerMember(targetMember,usingMember),
contentLikedRepository.existsByContentAndMember(oneContent,usingMember),
TimeUtilCustom.refineTime(oneContent.getCreatedAt()),
contentLikedRepository.countByContent(oneContent),
commentRepository.countByContent(oneContent)))
.collect(Collectors.toList());
}
}

0 comments on commit b2dd1c2

Please sign in to comment.