Skip to content

Commit

Permalink
Merge pull request #41 from Team-Wable/feat/#39
Browse files Browse the repository at this point in the history
[FEAT] 게시물 블라인드 처리 기능 개발
  • Loading branch information
Hong0329 authored Nov 15, 2024
2 parents b7efd18 + 335e1a1 commit c19b252
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ public ResponseEntity<ApiResponse<List<ContentGetAllResponseDtoVer3>>> 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<ApiResponse<List<ContentGetAllResponseDtoVer4>>> 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<ApiResponse<List<ContentGetAllByMemberResponseDto>>> getContentAllByMemberPagination(Principal principal,
Expand All @@ -126,9 +133,23 @@ public ResponseEntity<ApiResponse<List<ContentGetAllByMemberResponseDtoVer2>>> 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<ApiResponse<List<ContentGetAllByMemberResponseDtoVer3>>> 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<ApiResponse<ContentGetDetailsResponseDtoVer3>> 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<ApiResponse<ContentGetDetailsResponseDtoVer4>> getContentDetailWithBlind(Principal principal, @PathVariable("contentId") Long contentId) {
return ApiResponse.success(GET_CONTENT_DETAIL_SUCCESS, contentQueryService.getContentDetailWithBlind(MemberUtil.getMemberId(principal), contentId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;}

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
);
}
}
Original file line number Diff line number Diff line change
@@ -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()
);
}
}
Original file line number Diff line number Diff line change
@@ -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()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,70 @@ public List<ContentGetAllByMemberResponseDtoVer2> getContentAllByMemberWithImage
commentRepository.countByContent(oneContent)))
.collect(Collectors.toList());
}

public List<ContentGetAllResponseDtoVer4> getContentAllWithBlind(Long memberId, Long cursor) {
PageRequest pageRequest = PageRequest.of(0, 20);
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 -> 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<ContentGetAllByMemberResponseDtoVer3> getContentAllByMemberWithBlind(Long memberId, Long targetMemberId, Long cursor) {
Member usingMember = memberRepository.findMemberByIdOrThrow(memberId);
Member targetMember = memberRepository.findMemberByIdOrThrow(targetMemberId);

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

Slice<Content> 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);
}
}

0 comments on commit c19b252

Please sign in to comment.