Skip to content

Commit

Permalink
Merge pull request #143 from Team-Daengnyang/fix/#124
Browse files Browse the repository at this point in the history
[FIX] 계좌 이미지 수정 API 수정
  • Loading branch information
a-young-kim authored Aug 31, 2024
2 parents f4cdb53 + f36c0f1 commit 60d0c49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,26 @@ public class Account {
@Column(name = "account_color")
private String accountColor;

@Column(name = "account_image")
@Setter
private String accountImage;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
private Member member;

@Builder
public Account(String accountTitle, String accountNumber, String accountColor, Member member) {
public Account(String accountTitle, String accountNumber, String accountColor, String accountImage, Member member) {
this.accountTitle = accountTitle;
this.accountNumber = accountNumber;
this.accountColor = accountColor;
this.accountImage = accountImage;
this.member = member;
}

public void updateAccountColor(String accountColor) {
public void updateAccount(String accountColor, String accountImage) {

this.accountColor = accountColor;
this.accountImage =accountImage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,15 @@ public String updateAccountImage(Long memberId, MultipartFile newImage) {
throw new RuntimeException("해당 계좌 번호를 가진 계좌를 찾을 수 없습니다.");
}

Pet pet = petRepository.findByMemberMemberId(memberId)
.orElseThrow(() -> new CustomException(ErrorCode.PET_NOT_FOUND));
Account account = optionalAccount.get();

String petImage = awsService.uploadFile(newImage, memberId);
String accountImage = awsService.uploadFile(newImage, memberId);

//url을 통해 S3에서 이미지 가져오기
String url = awsService.getImageUrl(petImage);
String url = awsService.getImageUrl(accountImage);

pet.setPetImage(url);
petRepository.save(pet);
account.setAccountColor(url);
accountRepository.save(account);

return url;
}
Expand Down Expand Up @@ -481,24 +480,15 @@ public AccountCreateColorResponse createColorAccount(AccountCreateColorRequest r
Account account = accountRepository.findByMemberId(memberId)
.orElseThrow(() -> new CustomException(ErrorCode.ACCOUNT_NOT_FOUND));

// 2. 회원과 연결된 펫 찾기
Pet pet = petRepository.findByMemberMemberId(memberId)
.orElseThrow(() -> new CustomException(ErrorCode.PET_NOT_FOUND));

// 3. 펫 이미지 업데이트
pet.setPetImage(request.getAccountImage());

// 4. 펫 및 계좌 저장 (업데이트)
petRepository.save(pet);
account.updateAccountColor(request.getAccountColor());
// 2. account 커스텀
account.updateAccount(request.getAccountColor(), request.getAccountImage());
Account createdAccount = accountRepository.save(account);
pet.setPetImage(request.getAccountImage());

// 6. 응답 데이터 생성
// 3. 응답 데이터 생성
return AccountCreateColorResponse.builder()
.accountId(createdAccount.getAccountNumber())
.accountColor(createdAccount.getAccountColor())
.accountImage(pet.getPetImage())
.accountImage(createdAccount.getAccountImage())
.build();
}
}

0 comments on commit 60d0c49

Please sign in to comment.