Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/153 ✨내집다방 화면 조회, 한줄 소개 변경, 기본 프로필로 변경 API 구현 #158

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
4 changes: 4 additions & 0 deletions src/main/java/zipdabang/server/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public void setNickname(String nickname) {
this.nickname = nickname;
}

public void setCaption(String caption) {
this.caption = caption;
}

public void inactivateStatus(){
this.status = StatusType.INACTIVE;}
}
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);

}
7 changes: 6 additions & 1 deletion src/main/java/zipdabang/server/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +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 @@ -41,12 +42,15 @@
import zipdabang.server.web.dto.requestDto.MemberRequestDto;
import zipdabang.server.web.dto.responseDto.MemberResponseDto;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Service
Expand All @@ -72,15 +76,24 @@ public class MemberServiceImpl implements MemberService {

private final InqueryRepository inqueryRepository;
private final AmazonS3Manager s3Manager;
private static AmazonS3Manager staticAmazonS3Manager;
private final DeregisterRepository deregisterRepository;
private final DeregisterReasonRepository deregisterReasonRepository;
private final BlockedMemberRepository blockedMemberRepository;

private final FollowRepository followRepository;
private static String defaultProfileImage;

@Value("${paging.size}")
private Integer pageSize;

@Value("${cloud.aws.s3.user-default-image}")
public void setDefaultImage(String value) {
defaultProfileImage = value;
}
@PostConstruct
public void init(){
this.staticAmazonS3Manager = this.s3Manager;}

@Override
@Transactional
public OAuthResult.OAuthResultDto SocialLogin(MemberRequestDto.OAuthRequestDto request,String type) {
Expand Down Expand Up @@ -400,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 @@ -411,10 +430,66 @@ public Page<Follow> findFollower(Member member, Integer page) {
return followerMember;
}

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


@Override
@Transactional
public void updateCaption(Member member, MemberRequestDto.changeCaptionDto captionDto) {
member.setCaption(captionDto.getCaption());

}

public static String toKeyName(String imageUrl) {
String input = imageUrl;

Pattern regex = Pattern.compile(staticAmazonS3Manager.getPattern());
Matcher matcher = regex.matcher(input);
String extractedString = null;
if (matcher.find())
extractedString = matcher.group(1);

return extractedString;

}

@Override
@Transactional
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 @@ -390,7 +390,7 @@ public ResponseDto<MemberResponseDto.MemberStatusDto> unblock(@AuthMember Member
return ResponseDto.of(MemberConverter.toMemberStatusDto(member.getMemberId(), "Unblock"));
}

@Operation(summary = "차단 유저 목록 조회 API 🔑", description = "차단 유저 목록 조회 API 입니다.")
@Operation(summary = "차단 유저 목록 조회 API ✔️🔑", description = "차단 유저 목록 조회 API 입니다.")
@Parameters({
@Parameter(name = "member", hidden = true),
@Parameter(name = "page", description = "페이지 번호, 1부터 시작")
Expand Down Expand Up @@ -459,5 +459,56 @@ public ResponseDto<MemberResponseDto.FollowerListDto> getFollowerMember(@CheckPa
Page<Follow> follower = memberService.findFollower(member, page);
return ResponseDto.of(MemberConverter.toFollowerListDto(follower, member));
}


@Operation(summary = "🎪figma[내집다방 - 회원 정보 수정4] 한줄소개 변경 API ✔️🔑", description = "한줄 소개 변경 API 입니다.")
@PatchMapping("/members/caption")
@Parameters({
@Parameter(name = "member", hidden = true)
})
@ApiResponses({
@ApiResponse(responseCode = "2000", description = "OK 성공"),
})
public ResponseDto<MemberResponseDto.MemberStatusDto> updateCaption(@AuthMember Member member, MemberRequestDto.changeCaptionDto captionDto) {
memberService.updateCaption(member, captionDto);
return ResponseDto.of(MemberConverter.toMemberStatusDto(member.getMemberId(), "UpdateCaption"));
}


@Operation(summary = "🎪figma[내집다방 - 프로필 사진 변경2] 기본 프로필로 변경 API ✔️🔑", description = "유저 기본 프로필로 변경 API 입니다.")
@PatchMapping("/members/defaultProfile")
@Parameters({
@Parameter(name = "member", hidden = true)
})
@ApiResponses({
@ApiResponse(responseCode = "2000", description = "OK 성공"),
})
public ResponseDto<MemberResponseDto.MemberStatusDto> updateProfileDefault(@AuthMember Member member) {
memberService.updateProfileDefault(member);

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 @@ -147,6 +147,12 @@ public static class changeNicknameDto {
String nickname;
}

@Getter
@Setter
public static class changeCaptionDto {
String caption;
}

@Getter
@Setter
public static class changeProfileDto {
Expand Down
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;

}
}