Skip to content

Commit

Permalink
✨ 내집다방 화면 조회 API
Browse files Browse the repository at this point in the history
  • Loading branch information
HyoBN committed Oct 4, 2023
2 parents 712ba1d + dba7627 commit 82ee738
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main/java/zipdabang/server/base/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public enum Code {
//FORBIDDEN
SELF_FOLLOW_FORBIDDEN(HttpStatus.OK, 4065, "스스로 팔로우는 안됩니다."),

BLOCKED_MEMBER(HttpStatus.OK, 4066, "내가 차단한 사용자입니다."),


// market error

//recipe error
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/zipdabang/server/converter/MemberConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -116,6 +120,7 @@ public static MemberResponseDto.SocialJoinDto toSocialJoinDto(OAuthJoin.OAuthJoi
public void init() {
this.staticMemberRepository = this.memberRepository;
this.staticAmazonS3Manager = amazonS3Manager;
this.staticMemberService = memberService;
}


Expand Down Expand Up @@ -399,4 +404,19 @@ public static MemberResponseDto.FollowerListDto toFollowerListDto(Page<Follow> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
public interface FollowRepository extends JpaRepository<Follow, Long> {

Page<Follow> findAllByFollowee(Member member, PageRequest pageRequest);
Long countByFollowee(Member followee);

Page<Follow> findAllByFollower(Member member, PageRequest pageRequest);

Long countByFollower(Member follower);
Optional<Follow> findByFollowerAndFollowee(Member follower, Member followee);

boolean existsByFollowerAndFollowee(Member follower, Member followee);

}
6 changes: 5 additions & 1 deletion src/main/java/zipdabang/server/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ public interface MemberService {
public Follow toggleFollow(Long targetId, Member member);

Page<Follow> findFollowing(Member member, Integer page);
public Long getFollowingCount(Member member);

Page<Follow> 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -412,6 +413,12 @@ public Page<Follow> findFollowing(Member member, Integer page) {
return followingMember;
}

@Override
public Long getFollowingCount(Member member) {
return followRepository.countByFollower(member);
}


@Override
public Page<Follow> findFollower(Member member, Integer page) {
page -= 1;
Expand All @@ -423,6 +430,11 @@ public Page<Follow> findFollower(Member member, Integer page) {
return followerMember;
}

@Override
public Long getFollowerCount(Member member) {
return followRepository.countByFollowee(member);
}


@Override
@Transactional
Expand Down Expand Up @@ -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<Category> categories = findMemberPreferCategories(member);
MemberResponseDto.MemberPreferCategoryDto memberPreferCategoryDto = MemberConverter.toMemberPreferCategoryDto(categories);

return MemberConverter.toMyZipdabangDto(target, checkSelf, isFollowing, memberPreferCategoryDto);

}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public ResponseDto<MemberResponseDto.FollowerListDto> 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)
Expand All @@ -475,7 +475,7 @@ public ResponseDto<MemberResponseDto.MemberStatusDto> 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)
Expand All @@ -489,5 +489,26 @@ public ResponseDto<MemberResponseDto.MemberStatusDto> updateProfileDefault(@Auth
return ResponseDto.of(MemberConverter.toMemberStatusDto(member.getMemberId(), "UpdateProfileDefault"));
}


@Operation(summary = "🎪figma[내집다방 - 원본] 내집다방 화면 조회 API ✔️🔑", description = "내집다방 화면 조회 API 입니다.<br>"
+ "\"checkSelf\" : 자신의 내집다방을 조회하는 경우 true, 남이면 false <br>"
+"\"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<MemberResponseDto.MyZipdabangDto> getMyZipdabang(@CheckTempMember @AuthMember Member member, Long targetMemberId) {

return ResponseDto.of(memberService.getMyZipdabang(member, targetMemberId));


}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
}

0 comments on commit 82ee738

Please sign in to comment.