Skip to content

Commit

Permalink
refactor: 내 정보 수정시 이미지 없을 때 분기 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
wugawuga committed Aug 16, 2023
1 parent 68f75f2 commit 411e98a
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public enum CommonErrorCode {

UNKNOWN_SERVER_ERROR_CODE(HttpStatus.INTERNAL_SERVER_ERROR, "알 수 없는 에러입니다.", "0000"),
REQUEST_VALID_ERROR_CODE(HttpStatus.BAD_REQUEST, "요청을 다시 확인해주세요.", "0001"),
IMAGE_VALID_ERROR_CODE(HttpStatus.BAD_REQUEST, "이미지를 다시 확인해주세요.", "0002"),
;

private final HttpStatus status;
Expand Down
16 changes: 0 additions & 16 deletions backend/src/main/java/com/funeat/exception/CommonException.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.funeat.member.application;

import static com.funeat.exception.CommonErrorCode.IMAGE_VALID_ERROR_CODE;
import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW;

import com.funeat.auth.dto.SignUserDto;
import com.funeat.auth.dto.UserInfoDto;
import com.funeat.common.ImageService;
import com.funeat.exception.CommonException.ImageNotExistException;
import com.funeat.member.domain.Member;
import com.funeat.member.dto.MemberProfileResponse;
import com.funeat.member.dto.MemberRequest;
Expand Down Expand Up @@ -55,24 +53,18 @@ public MemberProfileResponse getMemberProfile(final Long memberId) {

@Transactional
public void modify(final Long memberId, final MultipartFile image, final MemberRequest request) {
checkExistImage(image);
final Member findMember = memberRepository.findById(memberId)
.orElseThrow(() -> new MemberNotFoundException(MemberErrorCode.MEMBER_NOT_FOUND, memberId));

final String nickname = request.getNickname();
final String newImageName = imageService.getRandomImageName(image);

if (findMember.isSameImage(image.getOriginalFilename())) {
findMember.modifyProfile(nickname, image.getOriginalFilename());
if (Objects.isNull(image)) {
findMember.modifyName(nickname);
return;
}

final String newImageName = imageService.getRandomImageName(image);
findMember.modifyProfile(nickname, newImageName);
imageService.upload(image, newImageName);
}

private void checkExistImage(final MultipartFile image) {
if (Objects.isNull(image)) {
throw new ImageNotExistException(IMAGE_VALID_ERROR_CODE);
}
}
}
4 changes: 2 additions & 2 deletions backend/src/main/java/com/funeat/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void modifyProfile(final String nickname, final String profileImage) {
this.profileImage = profileImage;
}

public boolean isSameImage(final String profileImage) {
return profileImage.equals(profileImage);
public void modifyName(final String nickname) {
this.nickname = nickname;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import com.funeat.auth.dto.UserInfoDto;
import com.funeat.common.ServiceTest;
import com.funeat.exception.CommonException.ImageNotExistException;
import com.funeat.member.domain.Member;
import com.funeat.member.dto.MemberProfileResponse;
import com.funeat.member.dto.MemberRequest;
import com.funeat.member.exception.MemberException.MemberNotFoundException;
Expand Down Expand Up @@ -272,18 +270,5 @@ class modify_실패_테스트 {
assertThatThrownBy(() -> memberService.modify(memberId, image, request))
.isInstanceOf(MemberUpdateException.class);
}

@Test
void 프로필_이미지_요청_값을_null_설정하면_예외가_발생해야_하지만_통과하고_있다() {
// given
final var member = new Member("before", "test.jpg", "1");
final var memberId = 단일_멤버_저장(member);

final var request = new MemberRequest("test");

// when & then
assertThatThrownBy(() -> memberService.modify(memberId, null, request))
.isInstanceOf(ImageNotExistException.class);
}
}
}

0 comments on commit 411e98a

Please sign in to comment.