diff --git a/src/main/java/zipdabang/server/base/Code.java b/src/main/java/zipdabang/server/base/Code.java index f1a201a..b3c3c4f 100644 --- a/src/main/java/zipdabang/server/base/Code.java +++ b/src/main/java/zipdabang/server/base/Code.java @@ -96,6 +96,9 @@ public enum Code { //FORBIDDEN SELF_FOLLOW_FORBIDDEN(HttpStatus.OK, 4065, "스스로 팔로우는 안됩니다."), + BLOCKED_MEMBER(HttpStatus.OK, 4066, "내가 차단한 사용자입니다."), + + // market error //recipe error diff --git a/src/main/java/zipdabang/server/converter/MemberConverter.java b/src/main/java/zipdabang/server/converter/MemberConverter.java index 65fe47d..7ea7468 100644 --- a/src/main/java/zipdabang/server/converter/MemberConverter.java +++ b/src/main/java/zipdabang/server/converter/MemberConverter.java @@ -17,7 +17,9 @@ import zipdabang.server.domain.member.Terms; import zipdabang.server.domain.member.Member; import zipdabang.server.domain.member.MemberPreferCategory; +import zipdabang.server.repository.memberRepositories.FollowRepository; import zipdabang.server.repository.memberRepositories.MemberRepository; +import zipdabang.server.service.MemberService; import zipdabang.server.utils.converter.TimeConverter; import zipdabang.server.utils.dto.OAuthJoin; import zipdabang.server.web.dto.requestDto.MemberRequestDto; @@ -46,6 +48,8 @@ public class MemberConverter { private static String defaultProfileImage; private static AmazonS3Manager staticAmazonS3Manager; + private final MemberService memberService; + private static MemberService staticMemberService; @Value("${cloud.aws.s3.user-default-image}") public void setDefaultImage(String value) { @@ -116,6 +120,7 @@ public static MemberResponseDto.SocialJoinDto toSocialJoinDto(OAuthJoin.OAuthJoi public void init() { this.staticMemberRepository = this.memberRepository; this.staticAmazonS3Manager = amazonS3Manager; + this.staticMemberService = memberService; } @@ -399,4 +404,19 @@ public static MemberResponseDto.FollowerListDto toFollowerListDto(Page f .currentPageElements(followList.getNumberOfElements()) .build(); } + + public static MemberResponseDto.MyZipdabangDto toMyZipdabangDto(Member member, boolean checkSelf, boolean isFollowing,MemberResponseDto.MemberPreferCategoryDto memberPreferCategoryDto) { + + return MemberResponseDto.MyZipdabangDto.builder() + .memberId(member.getMemberId()) + .imageUrl(member.getProfileUrl()) + .checkSelf(checkSelf) + .checkFollowing(isFollowing) + .nickname(member.getNickname()) + .caption(member.getCaption()) + .memberPreferCategoryDto(memberPreferCategoryDto) + .followerCount(staticMemberService.getFollowerCount(member)) + .followingCount(staticMemberService.getFollowingCount(member)) + .build(); + } } diff --git a/src/main/java/zipdabang/server/repository/memberRepositories/FollowRepository.java b/src/main/java/zipdabang/server/repository/memberRepositories/FollowRepository.java index 861ccbe..4399d2a 100644 --- a/src/main/java/zipdabang/server/repository/memberRepositories/FollowRepository.java +++ b/src/main/java/zipdabang/server/repository/memberRepositories/FollowRepository.java @@ -12,7 +12,13 @@ public interface FollowRepository extends JpaRepository { Page findAllByFollowee(Member member, PageRequest pageRequest); + Long countByFollowee(Member followee); + Page findAllByFollower(Member member, PageRequest pageRequest); + Long countByFollower(Member follower); Optional findByFollowerAndFollowee(Member follower, Member followee); + + boolean existsByFollowerAndFollowee(Member follower, Member followee); + } diff --git a/src/main/java/zipdabang/server/service/MemberService.java b/src/main/java/zipdabang/server/service/MemberService.java index c92d39b..6c9d794 100644 --- a/src/main/java/zipdabang/server/service/MemberService.java +++ b/src/main/java/zipdabang/server/service/MemberService.java @@ -63,9 +63,13 @@ public interface MemberService { public Follow toggleFollow(Long targetId, Member member); Page findFollowing(Member member, Integer page); + public Long getFollowingCount(Member member); Page findFollower(Member member, Integer page); + public Long getFollowerCount(Member member); public void updateCaption(Member member, MemberRequestDto.changeCaptionDto captionDto); public void updateProfileDefault(Member member); -} + Boolean checkFollowing(Member loginMember, Member targetMember); + public MemberResponseDto.MyZipdabangDto getMyZipdabang(Member member, Long targetId); + } diff --git a/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java b/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java index 10c59e0..579c843 100644 --- a/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java +++ b/src/main/java/zipdabang/server/service/serviceImpl/MemberServiceImpl.java @@ -12,6 +12,7 @@ import zipdabang.server.auth.provider.TokenProvider; import zipdabang.server.aws.s3.AmazonS3Manager; import zipdabang.server.base.Code; +import zipdabang.server.base.ResponseDto; import zipdabang.server.base.exception.handler.AuthNumberException; import zipdabang.server.base.exception.handler.MemberException; import zipdabang.server.base.exception.handler.RecipeException; @@ -412,6 +413,12 @@ public Page findFollowing(Member member, Integer page) { return followingMember; } + @Override + public Long getFollowingCount(Member member) { + return followRepository.countByFollower(member); + } + + @Override public Page findFollower(Member member, Integer page) { page -= 1; @@ -423,6 +430,11 @@ public Page findFollower(Member member, Integer page) { return followerMember; } + @Override + public Long getFollowerCount(Member member) { + return followRepository.countByFollowee(member); + } + @Override @Transactional @@ -450,6 +462,34 @@ public void updateProfileDefault(Member member) { s3Manager.deleteFile(toKeyName(member.getProfileUrl()).substring(1)); member.setProfileUrl(defaultProfileImage); } + + @Override + public Boolean checkFollowing(Member loginMember, Member targetMember) { + return followRepository.findByFollowerAndFollowee(loginMember,targetMember).isPresent(); + } + + @Override + public MemberResponseDto.MyZipdabangDto getMyZipdabang(Member member, Long targetId) { + Member target = memberRepository.findById(targetId).orElseThrow(() -> new MemberException(Code.MEMBER_NOT_FOUND)); + boolean checkSelf = false; + boolean isFollowing = false; + if (member.getMemberId() == target.getMemberId()) { + checkSelf=true; + } + else if(blockedMemberRepository.existsByOwnerAndBlocked(member,target)){ + throw new MemberException(Code.BLOCKED_MEMBER); + } + + if (followRepository.existsByFollowerAndFollowee(member, target)) { + isFollowing=true; + } + + List categories = findMemberPreferCategories(member); + MemberResponseDto.MemberPreferCategoryDto memberPreferCategoryDto = MemberConverter.toMemberPreferCategoryDto(categories); + + return MemberConverter.toMyZipdabangDto(target, checkSelf, isFollowing, memberPreferCategoryDto); + + } } diff --git a/src/main/java/zipdabang/server/web/controller/MemberRestController.java b/src/main/java/zipdabang/server/web/controller/MemberRestController.java index de54dc5..32bb764 100644 --- a/src/main/java/zipdabang/server/web/controller/MemberRestController.java +++ b/src/main/java/zipdabang/server/web/controller/MemberRestController.java @@ -461,7 +461,7 @@ public ResponseDto getFollowerMember(@CheckPa } - @Operation(summary = "🎪figma[내집다방 - 회원 정보 수정4] 한줄소개 변경 API 🔑", description = "한줄 소개 변경 API 입니다.") + @Operation(summary = "🎪figma[내집다방 - 회원 정보 수정4] 한줄소개 변경 API ✔️🔑", description = "한줄 소개 변경 API 입니다.") @PatchMapping("/members/caption") @Parameters({ @Parameter(name = "member", hidden = true) @@ -475,7 +475,7 @@ public ResponseDto updateCaption(@AuthMember } - @Operation(summary = "🎪figma[내집다방 - 프로필 사진 변경2] 기본 프로필로 변경 API 🔑", description = "유저 기본 프로필로 변경 API 입니다.") + @Operation(summary = "🎪figma[내집다방 - 프로필 사진 변경2] 기본 프로필로 변경 API ✔️🔑", description = "유저 기본 프로필로 변경 API 입니다.") @PatchMapping("/members/defaultProfile") @Parameters({ @Parameter(name = "member", hidden = true) @@ -489,5 +489,26 @@ public ResponseDto updateProfileDefault(@Auth return ResponseDto.of(MemberConverter.toMemberStatusDto(member.getMemberId(), "UpdateProfileDefault")); } + + @Operation(summary = "🎪figma[내집다방 - 원본] 내집다방 화면 조회 API ✔️🔑", description = "내집다방 화면 조회 API 입니다.
" + + "\"checkSelf\" : 자신의 내집다방을 조회하는 경우 true, 남이면 false
" + +"\"checkFollowing\" : 자신이 follow하는 사람이면 true, 아니면 false") + @GetMapping("/members/myZipdabang") + @Parameters({ + @Parameter(name = "member", hidden = true) + }) + @ApiResponses({ + @ApiResponse(responseCode = "2000", description = "OK 성공"), + @ApiResponse(responseCode = "4052", description = "해당 사용자가 존재하지 않습니다."), + @ApiResponse(responseCode = "4059", description = "로그인 후 조회 가능합니다."), + @ApiResponse(responseCode = "4066", description = "내가 차단한 사용자입니다."), + }) + public ResponseDto getMyZipdabang(@CheckTempMember @AuthMember Member member, Long targetMemberId) { + + return ResponseDto.of(memberService.getMyZipdabang(member, targetMemberId)); + + + } + } diff --git a/src/main/java/zipdabang/server/web/dto/responseDto/MemberResponseDto.java b/src/main/java/zipdabang/server/web/dto/responseDto/MemberResponseDto.java index 3fd95e0..8727450 100644 --- a/src/main/java/zipdabang/server/web/dto/responseDto/MemberResponseDto.java +++ b/src/main/java/zipdabang/server/web/dto/responseDto/MemberResponseDto.java @@ -268,4 +268,21 @@ public static class FollowerListDto{ Boolean isFirst; Boolean isLast; } + + @Builder + @Getter + @AllArgsConstructor(access = AccessLevel.PROTECTED) + @NoArgsConstructor(access = AccessLevel.PROTECTED) + public static class MyZipdabangDto{ + Long memberId; + String imageUrl; + boolean checkSelf; + boolean checkFollowing; + String nickname; + String caption; + MemberPreferCategoryDto memberPreferCategoryDto; + Long followerCount; + Long followingCount; + + } }