Skip to content

Commit

Permalink
Merge pull request #78 from Modagbul/fix/auth
Browse files Browse the repository at this point in the history
s3 이미지 삭제 메서드 추가 및 회원탈퇴 오류 해결
  • Loading branch information
minsu20 authored Nov 17, 2023
2 parents 2c2d0e5 + a5c5099 commit e3cf2a3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ public Member(String email, String profileImage, Gender gender, LocalDate birthD
this.role = role;
}


public void updateMember(String nickName, String fcmToken) {
this.nickName = nickName;
this.fcmToken = fcmToken;
}

public void updateProfile(String profileImage, String nickName, String introduction) {
this.profileImage = profileImage;
this.nickName = nickName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.moing.backend.domain.member.domain.service.MemberGetService;
import com.moing.backend.domain.mypage.application.dto.request.UpdateProfileRequest;
import com.moing.backend.domain.mypage.application.dto.response.GetProfileResponse;
import com.moing.backend.global.config.s3.S3Service;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -14,6 +15,7 @@
public class ProfileUserCase {

private final MemberGetService memberGetService;
private final S3Service s3Service;

public GetProfileResponse getProfile(String socialId){
Member member=memberGetService.getMemberBySocialId(socialId);
Expand All @@ -23,6 +25,7 @@ public GetProfileResponse getProfile(String socialId){
@Transactional
public void updateProfile(String socialId, UpdateProfileRequest updateProfileRequest) {
Member member = memberGetService.getMemberBySocialId(socialId);
deletePreviousImage(updateProfileRequest, member);
member.updateProfile(
getUpdatedValue(updateProfileRequest.getProfileImage(), member.getProfileImage()),
getUpdatedValue(updateProfileRequest.getNickName(), member.getNickName()),
Expand All @@ -31,7 +34,16 @@ public void updateProfile(String socialId, UpdateProfileRequest updateProfileReq
}

private String getUpdatedValue(String newValue, String currentValue) {
return newValue != null ? newValue : currentValue;
if (newValue != null) {
return newValue;
}
return currentValue;
}

private void deletePreviousImage(UpdateProfileRequest updateProfileRequest, Member member) {
if (updateProfileRequest.getProfileImage() != null) {
s3Service.deleteImage(member.getProfileImage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.moing.backend.domain.mypage.application.dto.request.WithdrawRequest;
import com.moing.backend.domain.mypage.domain.service.FeedbackSaveService;
import com.moing.backend.domain.mypage.exception.ExistingTeamException;
import com.moing.backend.domain.team.domain.service.TeamGetService;
import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService;
import com.moing.backend.global.config.security.jwt.TokenUtil;
import lombok.RequiredArgsConstructor;
Expand All @@ -25,6 +26,7 @@ public class WithdrawUserCase {
private final TokenUtil tokenUtil;
private final MemberDeleteService memberDeleteService;
private final TeamMemberGetService teamMemberGetService;
private final TeamGetService teamGetService;
private final Map<String, WithdrawProvider> withdrawProviders;

public void withdraw(String socialId, String providerInfo, WithdrawRequest withdrawRequest) throws IOException {
Expand All @@ -45,7 +47,7 @@ private void withdraw(String providerInfo, String token) throws IOException {
}

private void checkMemberIsNotPartOfAnyTeam(Member member) {
if (!teamMemberGetService.getNotDeletedTeamMember(member.getMemberId()).isEmpty()) {
if (!teamGetService.getTeamIdByMemberId(member.getMemberId()).isEmpty()) {
throw new ExistingTeamException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.moing.backend.domain.team.domain.entity.Team;
import com.moing.backend.domain.team.domain.service.TeamGetService;
import com.moing.backend.domain.team.exception.NotAuthByTeamException;
import com.moing.backend.global.config.s3.S3Service;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -20,11 +21,13 @@ public class UpdateTeamUserCase {
private final MemberGetService memberGetService;
private final TeamGetService teamGetService;
private final CheckLeaderUserCase checkLeaderUserCase;
private final S3Service s3Service;

public UpdateTeamResponse updateTeam(UpdateTeamRequest updateTeamRequest, String socialId, Long teamId){
Member member = memberGetService.getMemberBySocialId(socialId);
Team team=teamGetService.getTeamByTeamId(teamId);
if (checkLeaderUserCase.isTeamLeader(member, team)) {
s3Service.deleteImage(team.getProfileImgUrl());
team.updateTeam(updateTeamRequest.getName(), updateTeamRequest.getIntroduction(), updateTeamRequest.getProfileImgUrl());
} else {
throw new NotAuthByTeamException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.Headers;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.DeleteObjectRequest;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import com.moing.backend.domain.infra.image.application.dto.ImageFileExtension;
import com.moing.backend.domain.infra.image.application.dto.ImageUrlDto;
Expand Down Expand Up @@ -37,6 +38,13 @@ public ImageUrlDto issuePreSignedUrl(ImageFileExtension fileExtension) {
return ImageUrlDto.of(url, fileName);
}

public void deleteImage(String fileUrl) {
String splitStr = ".com/";
String fileName = fileUrl.substring(fileUrl.lastIndexOf(splitStr) + splitStr.length());

amazonS3.deleteObject(new DeleteObjectRequest(bucket, fileName));
}

private String createFileName(String fileExtension) {
return UUID.randomUUID() + "." + fileExtension;
}
Expand Down

0 comments on commit e3cf2a3

Please sign in to comment.