Skip to content

Commit

Permalink
Merge pull request #100 from Na-o-man/feat/#98/feat-and-fix-member-an…
Browse files Browse the repository at this point in the history
…d-presignedUrl

[FEAT] 내 memberId 조회, 샘플이미지 존재 여부 조회 API 구현, 일부 API fix
  • Loading branch information
bflykky authored Aug 12, 2024
2 parents fc1fd85 + afcbd12 commit bfcdbe9
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.umc.naoman.domain.member.converter.MemberConverter;
import com.umc.naoman.domain.member.dto.MemberResponse;
import com.umc.naoman.domain.member.dto.MemberResponse.HasSamplePhoto;
import com.umc.naoman.domain.member.dto.MemberResponse.MemberId;
import com.umc.naoman.domain.member.dto.MemberResponse.MemberInfo;
import com.umc.naoman.domain.member.entity.Member;
import com.umc.naoman.domain.member.service.MemberService;
Expand All @@ -21,7 +23,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.umc.naoman.global.result.code.MemberResultCode.CHECK_MEMBER_REGISTRATION;
import static com.umc.naoman.global.result.code.MemberResultCode.*;

@RestController
@RequestMapping("/members")
Expand Down Expand Up @@ -51,6 +53,12 @@ public ResultResponse<MemberInfo> getMyInfo(@LoginMember Member member) {
return ResultResponse.of(CHECK_MEMBER_REGISTRATION, memberService.getMyInfo(member));
}

@GetMapping("/my-memberId")
@Operation(summary = "내 memberId 조회 API", description = "자신의 memberId를 조회하는 API입니다.")
public ResultResponse<MemberId> getMyMemberId(@LoginMember Member member) {
return ResultResponse.of(GET_MY_MEMBERID, memberService.getMyMemberId(member));
}

@GetMapping("/terms/{memberId}")
@Operation(summary = "마케팅 약관 동의 여부 조회 API", description = "[PathVariable]\n memberId\n[request]\n" +
"[response]\n 마케팅 동의 여부 -> 동의 => true, 비동의 => false")
Expand All @@ -63,4 +71,10 @@ public ResultResponse<MemberResponse.MarketingAgreed> getMarketingAgreed(@PathVa
Member member = memberService.findMember(memberId);
return ResultResponse.of(MemberResultCode.CHECK_MARKETING_AGREED, memberConverter.toMarketingAgreed(member));
}

@GetMapping("/samplePhoto")
@Operation(summary = "샘플 사진 업로드 여부 조회", description = "자신이 샘플 사진을 업로드했는지 여부를 확인하는 API입니다.")
public ResultResponse<HasSamplePhoto> hasSamplePhoto(@LoginMember Member member) {
return ResultResponse.of(CHECK_HAS_SAMPLE_PHOTO, memberService.hasSamplePhoto(member));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.umc.naoman.domain.member.converter;

import com.umc.naoman.domain.member.dto.MemberRequest.SignupRequest;
import com.umc.naoman.domain.member.dto.MemberResponse;
import com.umc.naoman.domain.member.dto.MemberResponse.CheckMemberRegistration;
import com.umc.naoman.domain.member.dto.MemberResponse.HasSamplePhoto;
import com.umc.naoman.domain.member.dto.MemberResponse.LoginInfo;
import com.umc.naoman.domain.member.dto.MemberResponse.MarketingAgreed;
import com.umc.naoman.domain.member.dto.MemberResponse.MemberId;
import com.umc.naoman.domain.member.dto.MemberResponse.MemberInfo;
import com.umc.naoman.domain.member.entity.Member;
import com.umc.naoman.domain.member.entity.SocialType;
import io.jsonwebtoken.Claims;
Expand Down Expand Up @@ -40,16 +44,29 @@ public SignupRequest toSignupRequest(Claims payload, boolean marketingAgreed) {
.build();
}

public MemberResponse.MemberInfo toMemberInfo(Member member) {
return MemberResponse.MemberInfo.builder()
public MemberInfo toMemberInfo(Member member) {
return MemberInfo.builder()
.memberId(member.getId())
.name(member.getName())
.email(member.getEmail())
.image(member.getImage())
.build();
}

public MemberResponse.MarketingAgreed toMarketingAgreed(Member member) {
return MemberResponse.MarketingAgreed.builder()
public MemberId toMemberId(Long memberId) {
return new MemberId(memberId);
}

public CheckMemberRegistration toCheckMemberRegistration(boolean isRegistered) {
return new CheckMemberRegistration(isRegistered);
}

public HasSamplePhoto toHasSamplePhoto(boolean hasSamplePhoto) {
return new HasSamplePhoto(hasSamplePhoto);
}

public MarketingAgreed toMarketingAgreed(Member member) {
return MarketingAgreed.builder()
.marketingAgreed(member.getMarketingAgreed())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static class LoginInfo {
@Getter
@AllArgsConstructor
public static class MemberInfo { //특정 회원 조회
private Long memberId;
private String name;
private String email;
private String image;
Expand All @@ -41,4 +42,10 @@ public static class MemberInfo { //특정 회원 조회
public static class MarketingAgreed {
private Boolean marketingAgreed;
}

@Getter
@AllArgsConstructor
public static class HasSamplePhoto {
private Boolean hasSamplePhoto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.umc.naoman.domain.member.dto.MemberRequest.MarketingAgreedRequest;
import com.umc.naoman.domain.member.dto.MemberRequest.SignupRequest;
import com.umc.naoman.domain.member.dto.MemberResponse.CheckMemberRegistration;
import com.umc.naoman.domain.member.dto.MemberResponse.HasSamplePhoto;
import com.umc.naoman.domain.member.dto.MemberResponse.LoginInfo;
import com.umc.naoman.domain.member.dto.MemberResponse.MemberId;
import com.umc.naoman.domain.member.dto.MemberResponse.MemberInfo;
import com.umc.naoman.domain.member.entity.Member;
import com.umc.naoman.domain.member.entity.SocialType;
Expand All @@ -14,7 +16,10 @@ public interface MemberService {
LoginInfo signup(SignupRequest request);
LoginInfo login(LoginRequest request);
CheckMemberRegistration checkRegistration(LoginRequest request);
HasSamplePhoto hasSamplePhoto(Member member);
MemberInfo getMyInfo(Member member);
MemberId getMyMemberId(Member member);
Member findMember(Long memberId);
Member findMember(SocialType socialType, String authId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import com.umc.naoman.domain.member.dto.MemberRequest.MarketingAgreedRequest;
import com.umc.naoman.domain.member.dto.MemberRequest.SignupRequest;
import com.umc.naoman.domain.member.dto.MemberResponse.CheckMemberRegistration;
import com.umc.naoman.domain.member.dto.MemberResponse.HasSamplePhoto;
import com.umc.naoman.domain.member.dto.MemberResponse.LoginInfo;
import com.umc.naoman.domain.member.dto.MemberResponse.MemberId;
import com.umc.naoman.domain.member.dto.MemberResponse.MemberInfo;
import com.umc.naoman.domain.member.entity.Member;
import com.umc.naoman.domain.member.entity.SocialType;
import com.umc.naoman.domain.member.repository.MemberRepository;
import com.umc.naoman.domain.member.service.redis.RefreshTokenService;
import com.umc.naoman.domain.photo.service.PhotoService;
import com.umc.naoman.global.error.BusinessException;
import com.umc.naoman.global.security.util.JwtUtils;
import io.jsonwebtoken.Claims;
Expand All @@ -26,6 +29,7 @@
@RequiredArgsConstructor
public class MemberServiceImpl implements MemberService {
private final RefreshTokenService refreshTokenService;
private final PhotoService photoService;
private final MemberRepository memberRepository;
private final MemberConverter memberConverter;
private final JwtUtils jwtUtils;
Expand Down Expand Up @@ -82,14 +86,25 @@ public LoginInfo login(LoginRequest request) {
@Override
public CheckMemberRegistration checkRegistration(LoginRequest request) {
boolean isRegistered = memberRepository.existsBySocialTypeAndAuthId(request.getSocialType(), request.getAuthId());
return new CheckMemberRegistration(isRegistered);
return memberConverter.toCheckMemberRegistration(isRegistered);
}

@Override
public HasSamplePhoto hasSamplePhoto(Member member) {
boolean hasSamplePhoto = photoService.hasSamplePhoto(member);
return memberConverter.toHasSamplePhoto(hasSamplePhoto);
}

@Override
public MemberInfo getMyInfo(Member member) {
return memberConverter.toMemberInfo(member);
}

@Override
public MemberId getMyMemberId(Member member) {
return memberConverter.toMemberId(member.getId());
}

@Override
public Member findMember(Long memberId) {
return memberRepository.findById(memberId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public abstract class PhotoRequest {
@NoArgsConstructor
@AllArgsConstructor
public static class PreSignedUrlRequest {

@NotNull(message = "공유 그룹의 아이디 값을 입력해야 합니다.")
private Long shareGroupId;
@NotEmpty(message = "사진의 이름은 하나 이상이어야 합니다.")
private List<String> photoNameList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

@Repository
public interface SamplePhotoRepository extends JpaRepository<SamplePhoto, Long> {
boolean existsByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public interface PhotoService {
List<Photo> deletePhotoList(PhotoRequest.PhotoDeletedRequest request, Member member);

Photo findPhoto(Long photoId);
boolean hasSamplePhoto(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import com.umc.naoman.domain.member.entity.Member;
import com.umc.naoman.domain.photo.converter.PhotoConverter;
import com.umc.naoman.domain.photo.converter.SamplePhotoConverter;
import com.umc.naoman.domain.photo.dto.PhotoRequest;
import com.umc.naoman.domain.photo.dto.PhotoRequest.PhotoDeletedRequest;
import com.umc.naoman.domain.photo.dto.PhotoRequest.PhotoUploadRequest;
import com.umc.naoman.domain.photo.dto.PhotoRequest.PreSignedUrlRequest;
import com.umc.naoman.domain.photo.dto.PhotoRequest.UploadSamplePhotoRequest;
import com.umc.naoman.domain.photo.dto.PhotoResponse.PhotoDownloadUrlListInfo;
import com.umc.naoman.domain.photo.dto.PhotoResponse.PhotoUploadInfo;
Expand Down Expand Up @@ -67,9 +68,7 @@ public class PhotoServiceImpl implements PhotoService {

@Override
@Transactional
public List<PreSignedUrlInfo> getPreSignedUrlList(PhotoRequest.PreSignedUrlRequest request, Member member) {
validateShareGroupAndProfile(request.getShareGroupId(), member);

public List<PreSignedUrlInfo> getPreSignedUrlList(PreSignedUrlRequest request, Member member) {
return request.getPhotoNameList().stream()
.map(this::getPreSignedUrl)
.collect(Collectors.toList());
Expand Down Expand Up @@ -260,7 +259,7 @@ public PhotoDownloadUrlListInfo getEtcPhotoDownloadUrlList(Long shareGroupId, Me

@Override
@Transactional
public List<Photo> deletePhotoList(PhotoRequest.PhotoDeletedRequest request, Member member) {
public List<Photo> deletePhotoList(PhotoDeletedRequest request, Member member) {
validateShareGroupAndProfile(request.getShareGroupId(), member);
// 요청된 사진 ID 목록과 공유 그룹 ID를 기반으로 사진 목록 조회
List<Photo> photoList = photoRepository.findByIdInAndShareGroupId(request.getPhotoIdList(), request.getShareGroupId());
Expand Down Expand Up @@ -305,4 +304,9 @@ public Photo findPhoto(Long photoId) {
return photoRepository.findById(photoId)
.orElseThrow(() -> new BusinessException(PHOTO_NOT_FOUND));
}

@Override
public boolean hasSamplePhoto(Member member) {
return samplePhotoRepository.existsByMemberId(member.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public enum MemberResultCode implements ResultCode {
EDIT_MYPAGE_INFO(200, "SM002", "내 정보를 성공적으로 수정하였습니다."),
CHECK_MEMBER_REGISTRATION(200, "SM000", "해당 정보에 대응하는 회원의 가입 여부를 성공적으로 조회하였습니다."),
MEMBER_INFO (200,"SM005","회원 정보를 성공적으로 조회하였습니다."),
CHECK_MARKETING_AGREED(200,"SM006","마케팅동의여부를 성공적으로 조회하였습니다."),
CHECK_MARKETING_AGREED(200,"SM006","마케팅 동의 여부를 성공적으로 조회하였습니다."),
GET_MY_MEMBERID(200,"SM000","자신의 memberId를 성공적으로 조회하였습니다."),
CHECK_HAS_SAMPLE_PHOTO(200,"SM000","자신의 샘플 사진 업로드 여부를 성공적으로 조회하였습니다."),
;
private final int status;
private final String code;
Expand Down

0 comments on commit bfcdbe9

Please sign in to comment.