Skip to content

Commit

Permalink
#339 refactor : 마이페이지 기능 리팩터링 (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongyun1206 authored Jan 10, 2025
2 parents 8b4773c + 942618c commit 7d52d35
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public ApiResponse<?> joinProcess(@RequestBody JoinRequest joinRequest) {
return ApiResponse.onSuccess("회원가입 성공");
}

@DeleteMapping("/member/delete")
@Operation(summary = "사용자 탈퇴", description = "사용자 정보를 삭제합니다.")
public ApiResponse<?> deleteProcess(@AuthenticationPrincipal PrincipalDetail principalDetail, HttpServletResponse response){
memberService.deleteMemberByUsername(principalDetail.getUsername());
tokenService.deleteRefreshTokenAndAccessToken(response, principalDetail.getUsername());
return ApiResponse.onSuccess("회원 탈퇴 성공");
}

@PatchMapping("/member")
@Operation(summary = "사용자 초기 정보 추가", description = "첫 로그인 여부에 따라 isFirst 속성이 true인 경우 사용자 초기 정보를 추가합니다.")
Expand All @@ -41,17 +48,6 @@ public ApiResponse<?> addMemberDetail(@RequestPart(value = "multipartFile", requ
return ApiResponse.onSuccess("사용자 초기 정보 추가 완료");
}

@DeleteMapping("/member/delete")
@Operation(summary = "사용자 탈퇴", description = "사용자 정보를 삭제합니다.")

public ApiResponse<?> deleteProcess(@AuthenticationPrincipal PrincipalDetail principalDetail, HttpServletResponse response){
memberService.deleteMemberByUsername(principalDetail.getUsername());
tokenService.deleteRefreshTokenAndAccessToken(response, principalDetail.getUsername());
return ApiResponse.onSuccess("회원 탈퇴 성공");


}

@GetMapping("/member/info")
@Operation(summary = "마이페이지 ", description = "유저 정보를 불러옵니다.")
public ApiResponse<MemberInfoResponse> getMemberInfo(@AuthenticationPrincipal PrincipalDetail principalDetail) {
Expand All @@ -66,9 +62,9 @@ public ApiResponse<NameCheckResponse> checkNickname(@AuthenticationPrincipal Pri

@PatchMapping("/member/info")
@Operation(summary = "마이페이지 정보 수정 ", description = "마이페이지의 정보를 수정합니다.")
public ApiResponse<?> updateMemberInfo(@AuthenticationPrincipal PrincipalDetail principalDetail, @RequestPart(value = "multipartFile", required = false) MultipartFile multipartFile, @RequestPart("memberUpdateRequest") MemberUpdateRequest memberUpdateRequest){
public ApiResponse<?> updateMemberInfo(@AuthenticationPrincipal PrincipalDetail principalDetail, @RequestBody MemberUpdateRequest memberUpdateRequest){

memberService.updateMemberInfo(principalDetail,memberUpdateRequest, multipartFile);
memberService.updateMemberInfo(memberUpdateRequest, principalDetail.getUsername());
return ApiResponse.onSuccess("정보 수정 성공");
}

Expand All @@ -78,4 +74,11 @@ public ApiResponse<UsernameCheckResponse> checkUsername(@RequestBody UsernameChe
UsernameCheckResponse usernameCheckResponse = joinService.isDuplicatedUsername(usernameCheckRequest);
return ApiResponse.onSuccess(usernameCheckResponse);
}

@PostMapping("/member/profileImage")
@Operation(summary = "프로필 이미지 업로드", description = "프로필 이미지를 업로드합니다.")
public ApiResponse<?> uploadProfileImage(@RequestPart(value = "profileImg") MultipartFile profileImg, @AuthenticationPrincipal PrincipalDetail principalDetail) {
String imageUrl = memberService.uploadProfileImage(profileImg, principalDetail.getUsername());
return ApiResponse.onSuccess(imageUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.drinkeg.drinkeg.domain.member.converter.StringListConverter;
import com.drinkeg.drinkeg.domain.member.dto.MemberUpdateRequest;
import com.drinkeg.drinkeg.domain.myWine.domain.MyWine;
import com.drinkeg.drinkeg.domain.member.enums.Provider;
import com.drinkeg.drinkeg.domain.member.enums.Role;
Expand Down Expand Up @@ -99,10 +100,15 @@ public Member(String name, String email, Role role, Provider provider, String us
}


public void updateMemberInfo(MemberUpdateRequest memberUpdateRequest) {
if (memberUpdateRequest.getName() != null) name = memberUpdateRequest.getName();
if (memberUpdateRequest.getRegion() != null) region = memberUpdateRequest.getRegion();
}

public void updateEmail(String email) { this.email = email; };
public void updateImageUrl(String imageUrl){this.imageUrl=imageUrl;};
public void updateRegion(String region){this.region=region;};
public void updateName(String name){this.name = name;};
public void updateImageUrl(String imageUrl) {
if (imageUrl != null) this.imageUrl = imageUrl;
};

public static Member createMember(String username, String password, boolean isFirst) {
return Member.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
@AllArgsConstructor
@NoArgsConstructor
public class MemberUpdateRequest {

private String username;

private String city;




private String name;
private String region;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ public interface MemberRepository extends JpaRepository<Member, Long>{
boolean existsByName(String nickname);

void deleteByUsername(String username);

Member findMemberByUsername(String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import org.springframework.web.multipart.MultipartFile;

public interface MemberService {

public Member getMemberById(Long memberId);

public Member loadMemberByPrincipalDetail(PrincipalDetail principalDetail);

public void deleteMemberByUsername(String username);
Expand All @@ -19,5 +16,7 @@ public interface MemberService {

public NameCheckResponse isNicknameAvailable(String nickname);

public void updateMemberInfo(PrincipalDetail principalDetail, MemberUpdateRequest memberUpdateRequest, MultipartFile multipartFile);
public void updateMemberInfo(MemberUpdateRequest memberUpdateRequest, String username);

public String uploadProfileImage(MultipartFile multipartFile, String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class MemberServiceImpl implements MemberService {

private final MemberRepository memberRepository;
private final StorageService storageService;
private final ApplicationEventPublisher eventPublisher;

@Override
public Member getMemberById(Long memberId) {

return memberRepository.findById(memberId).orElseThrow(()
-> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND));
}

@Override
public Member loadMemberByPrincipalDetail(PrincipalDetail principalDetail) {
// 현재 로그인한 사용자 정보 가져오기
Expand All @@ -42,52 +36,43 @@ public Member loadMemberByPrincipalDetail(PrincipalDetail principalDetail) {
return memberRepository.findByUsername(username).orElseThrow(()
-> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND));
}

@Override
@Transactional
public void deleteMemberByUsername(String username){
eventPublisher.publishEvent(new RemoveTastingNoteMemberEvent(username));
memberRepository.deleteByUsername(username);
}

@Override
@Transactional
public void deleteMemberByUsername(String username){
eventPublisher.publishEvent(new RemoveTastingNoteMemberEvent(username));
memberRepository.deleteByUsername(username);
}

@Override
public MemberInfoResponse showMemberInfo(String username){

@Override
public MemberInfoResponse showMemberInfo(String username){
Member member = memberRepository.findByUsername(username)
.orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND));
return MemberInfoResponse.create(member);
}

return MemberInfoResponse.create(member);
}

@Override
public NameCheckResponse isNicknameAvailable(String nickname){


return NameCheckResponse.create(!memberRepository.existsByName(nickname));
}

@Override
@Transactional
public void updateMemberInfo(PrincipalDetail principalDetail, MemberUpdateRequest memberUpdateRequest, MultipartFile multipartFile){


Member member = loadMemberByPrincipalDetail(principalDetail);

if (multipartFile != null ) {

String profileImage = storageService.uploadFile(multipartFile, StoragePathName.MEMBER_PROFILE);
@Override
public NameCheckResponse isNicknameAvailable(String nickname){
return NameCheckResponse.create(!memberRepository.existsByName(nickname));
}

if (profileImage != null) {
member.updateImageUrl(profileImage);
}
}
if (memberUpdateRequest.getCity() != null) {
member.updateRegion(memberUpdateRequest.getCity());
}
@Override
@Transactional
public void updateMemberInfo(MemberUpdateRequest memberUpdateRequest, String username){
Member member = memberRepository.findByUsername(username)
.orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND));

if (memberUpdateRequest.getUsername() != null) {
member.updateName(memberUpdateRequest.getUsername());
}
member.updateMemberInfo(memberUpdateRequest);
}

}
@Override
public String uploadProfileImage(MultipartFile profileImg, String username) {
String profileImgUrl = storageService.uploadFile(profileImg, StoragePathName.MEMBER_PROFILE);
Member member = memberRepository.findByUsername(username)
.orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND));
if (member.getImageUrl() != null)
storageService.deleteFile(member.getImageUrl());
member.updateImageUrl(profileImgUrl);
return profileImgUrl;
}
}

0 comments on commit 7d52d35

Please sign in to comment.