From 335e1a14d7624a63b6cb4a9f6842d682285c906b Mon Sep 17 00:00:00 2001 From: Hong0329 Date: Sat, 16 Nov 2024 00:14:07 +0900 Subject: [PATCH] feat : content with blind --- .../content/controller/ContentController.java | 21 ++++++ .../api/content/domain/Content.java | 3 + .../ContentGetAllByMemberResponseDtoVer3.java | 43 ++++++++++++ .../ContentGetAllResponseDtoVer4.java | 45 +++++++++++++ .../ContentGetDetailsResponseDtoVer4.java | 43 ++++++++++++ .../content/service/ContentQueryService.java | 66 +++++++++++++++++++ 6 files changed, 221 insertions(+) create mode 100644 WableServer/src/main/java/com/wable/www/WableServer/api/content/dto/response/ContentGetAllByMemberResponseDtoVer3.java create mode 100644 WableServer/src/main/java/com/wable/www/WableServer/api/content/dto/response/ContentGetAllResponseDtoVer4.java create mode 100644 WableServer/src/main/java/com/wable/www/WableServer/api/content/dto/response/ContentGetDetailsResponseDtoVer4.java diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/content/controller/ContentController.java b/WableServer/src/main/java/com/wable/www/WableServer/api/content/controller/ContentController.java index 1bfb719..ac23351 100644 --- a/WableServer/src/main/java/com/wable/www/WableServer/api/content/controller/ContentController.java +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/content/controller/ContentController.java @@ -110,6 +110,13 @@ public ResponseEntity>> getConten return ApiResponse.success(GET_CONTENT_ALL_SUCCESS, contentQueryService.getContentAllWithImage(memberId, cursor)); } + @GetMapping("v3/contents") + @Operation(summary = "게시글 전체 조회 API(+Blind) 입니다.",description = "Contents Get with Blind") + public ResponseEntity>> getContentAllWithBlind(Principal principal, @RequestParam(value = "cursor") Long cursor) { + Long memberId = MemberUtil.getMemberId(principal); + return ApiResponse.success(GET_CONTENT_ALL_SUCCESS, contentQueryService.getContentAllWithBlind(memberId, cursor)); + } + @GetMapping("v1/member/{memberId}/member-contents") @Operation(summary = "페이지네이션이 적용된 멤버에 해당하는 게시글 리스트 조회 API 입니다.",description = "ContentByMemberPagination") public ResponseEntity>> getContentAllByMemberPagination(Principal principal, @@ -126,9 +133,23 @@ public ResponseEntity>> g return ApiResponse.success(GET_MEMBER_CONTENT_SUCCESS, contentQueryService.getContentAllByMemberWithImage(memberId, targetMemberId, cursor)); } + @GetMapping("v3/member/{memberId}/contents") + @Operation(summary = "멤버에 해당하는 게시글 리스트 조회 API(+Blind) 입니다.",description = "Contents By Member with Blind") + public ResponseEntity>> getContentAllByMemberWithBlind(Principal principal, + @PathVariable("memberId") Long targetMemberId, @RequestParam(value = "cursor") Long cursor) { + Long memberId = MemberUtil.getMemberId(principal); + return ApiResponse.success(GET_MEMBER_CONTENT_SUCCESS, contentQueryService.getContentAllByMemberWithBlind(memberId, targetMemberId, cursor)); + } + @GetMapping("v2/content/{contentId}") @Operation(summary = "게시글 상세 조회 API 입니다.",description = "Content Get Detail") public ResponseEntity> getContentDetailWithImage(Principal principal, @PathVariable("contentId") Long contentId) { return ApiResponse.success(GET_CONTENT_DETAIL_SUCCESS, contentQueryService.getContentDetailWithImage(MemberUtil.getMemberId(principal), contentId)); } + + @GetMapping("v3/content/{contentId}") + @Operation(summary = "게시글 상세 조회 API 입니다(+Blind)",description = "Content Get Detail with Blind") + public ResponseEntity> getContentDetailWithBlind(Principal principal, @PathVariable("contentId") Long contentId) { + return ApiResponse.success(GET_CONTENT_DETAIL_SUCCESS, contentQueryService.getContentDetailWithBlind(MemberUtil.getMemberId(principal), contentId)); + } } diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/content/domain/Content.java b/WableServer/src/main/java/com/wable/www/WableServer/api/content/domain/Content.java index 1903eb6..62daa32 100644 --- a/WableServer/src/main/java/com/wable/www/WableServer/api/content/domain/Content.java +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/content/domain/Content.java @@ -52,6 +52,9 @@ public class Content extends BaseTimeEntity { private LocalDateTime deleteAt; + @Column(name = "is_blind", columnDefinition = "BOOLEAN DEFAULT false") + private boolean isBlind; + public void setContentImage(String contentImageUrl) { this.contentImage = contentImageUrl ;} diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/content/dto/response/ContentGetAllByMemberResponseDtoVer3.java b/WableServer/src/main/java/com/wable/www/WableServer/api/content/dto/response/ContentGetAllByMemberResponseDtoVer3.java new file mode 100644 index 0000000..648ccbc --- /dev/null +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/content/dto/response/ContentGetAllByMemberResponseDtoVer3.java @@ -0,0 +1,43 @@ +package com.wable.www.WableServer.api.content.dto.response; + +import com.wable.www.WableServer.api.content.domain.Content; +import com.wable.www.WableServer.api.member.domain.Member; + +public record ContentGetAllByMemberResponseDtoVer3( + Long memberId, + String memberProfileUrl, + String memberNickname, + Long contentId, + String contentTitle, + String contentText, + String time, + boolean isGhost, + int memberGhost, + boolean isLiked, + int likedNumber, + int commentNumber, + String contentImageUrl, + String memberFanTeam, + Boolean isBlind + +) { + public static ContentGetAllByMemberResponseDtoVer3 of(Member writerMember, int writerGhost, Content content, boolean isGhost, boolean isLiked, String time, int likedNumber, int commentNumber) { + return new ContentGetAllByMemberResponseDtoVer3( + writerMember.getId(), + writerMember.getProfileUrl(), + writerMember.getNickname(), + content.getId(), + content.getContentTitle(), + content.getContentText(), + time, + isGhost, + writerGhost, + isLiked, + likedNumber, + commentNumber, + content.getContentImage(), + writerMember.getMemberFanTeam(), + content.isBlind() + ); + } +} \ No newline at end of file diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/content/dto/response/ContentGetAllResponseDtoVer4.java b/WableServer/src/main/java/com/wable/www/WableServer/api/content/dto/response/ContentGetAllResponseDtoVer4.java new file mode 100644 index 0000000..2a66758 --- /dev/null +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/content/dto/response/ContentGetAllResponseDtoVer4.java @@ -0,0 +1,45 @@ +package com.wable.www.WableServer.api.content.dto.response; + +import com.wable.www.WableServer.api.content.domain.Content; +import com.wable.www.WableServer.api.member.domain.Member; + +public record ContentGetAllResponseDtoVer4( + Long memberId, + String memberProfileUrl, + String memberNickname, + Long contentId, + String contentTitle, + String contentText, + String time, + boolean isGhost, + int memberGhost, + boolean isLiked, + int likedNumber, + int commentNumber, + Boolean isDeleted, + String contentImageUrl, + String memberFanTeam, + Boolean isBlind + +) { + public static ContentGetAllResponseDtoVer4 of(Member writerMember, Content content, boolean isGhost, int refinedMemberGhost, boolean isLiked, String time, int likedNumber, int commentNumber) { + return new ContentGetAllResponseDtoVer4( + writerMember.getId(), + writerMember.getProfileUrl(), + writerMember.getNickname(), + content.getId(), + content.getContentTitle(), + content.getContentText(), + time, + isGhost, + refinedMemberGhost, + isLiked, + likedNumber, + commentNumber, + writerMember.isDeleted(), + content.getContentImage(), + writerMember.getMemberFanTeam(), + content.isBlind() + ); + } +} \ No newline at end of file diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/content/dto/response/ContentGetDetailsResponseDtoVer4.java b/WableServer/src/main/java/com/wable/www/WableServer/api/content/dto/response/ContentGetDetailsResponseDtoVer4.java new file mode 100644 index 0000000..f0c817a --- /dev/null +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/content/dto/response/ContentGetDetailsResponseDtoVer4.java @@ -0,0 +1,43 @@ +package com.wable.www.WableServer.api.content.dto.response; + +import com.wable.www.WableServer.api.content.domain.Content; +import com.wable.www.WableServer.api.member.domain.Member; + +public record ContentGetDetailsResponseDtoVer4( + Long memberId, + String memberProfileUrl, + String memberNickname, + boolean isGhost, + int memberGhost, + boolean isLiked, + String time, + int likedNumber, + int commentNumber, + String contentTitle, + String contentText, + Boolean isDeleted, + String contentImageUrl, + String memberFanTeam, + Boolean isBlind + +) { + public static ContentGetDetailsResponseDtoVer4 of(Member member, int memberGhost, Content content, boolean isGhost, boolean isLiked, String time, int likedNumber, int commentNumber) { + return new ContentGetDetailsResponseDtoVer4( + member.getId(), + member.getProfileUrl(), + member.getNickname(), + isGhost, + memberGhost, + isLiked, + time, + likedNumber, + commentNumber, + content.getContentTitle(), + content.getContentText(), + member.isDeleted(), + content.getContentImage(), + member.getMemberFanTeam(), + content.isBlind() + ); + } +} diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/content/service/ContentQueryService.java b/WableServer/src/main/java/com/wable/www/WableServer/api/content/service/ContentQueryService.java index 31a14ae..fd9f97d 100644 --- a/WableServer/src/main/java/com/wable/www/WableServer/api/content/service/ContentQueryService.java +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/content/service/ContentQueryService.java @@ -208,4 +208,70 @@ public List getContentAllByMemberWithImage commentRepository.countByContent(oneContent))) .collect(Collectors.toList()); } + + public List getContentAllWithBlind(Long memberId, Long cursor) { + PageRequest pageRequest = PageRequest.of(0, 20); + Member usingMember = memberRepository.findMemberByIdOrThrow(memberId); + Slice contentList; + + if (cursor==-1) { + contentList = contentRepository.findTop30ByOrderByCreatedAtDesc(pageRequest); + } else { + contentList = contentRepository.findContentsNextPage(cursor, pageRequest); + } + + return contentList.stream() + .map(oneContent -> ContentGetAllResponseDtoVer4.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 getContentAllByMemberWithBlind(Long memberId, Long targetMemberId, Long cursor) { + Member usingMember = memberRepository.findMemberByIdOrThrow(memberId); + Member targetMember = memberRepository.findMemberByIdOrThrow(targetMemberId); + + PageRequest pageRequest = PageRequest.of(0, 15); + + Slice contentList; + + if (cursor==-1) { + contentList = contentRepository.findContestsTop20ByMemberIdOrderByCreatedAtDesc(targetMemberId, pageRequest); + } else { + contentList = contentRepository.findContentsByMemberNextPage(cursor, targetMemberId ,pageRequest); + } + + return contentList.stream() + .map(oneContent -> ContentGetAllByMemberResponseDtoVer3.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()); + } + + public ContentGetDetailsResponseDtoVer4 getContentDetailWithBlind(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 ContentGetDetailsResponseDtoVer4.of(writerMember, writerMemberGhost, content, isGhost, isLiked, time, likedNumber, commentNumber); + } }