Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] 계좌 이미지 수정 API 수정 #143

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

Comment on lines +28 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

결국 다시 죽지도 않고 돌아온 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();
}
}
Loading