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

6th-lemorning-springboot-24 CreditCardController 기능 동작 점검해주세요 #27

Closed
wants to merge 1 commit into from
Closed
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 @@ -51,10 +51,11 @@ public Response findOne(@PathVariable("id") Long cardId) {

try {
CreditCardInfo findCard = creditCardService.findOne(cardId);
SavedCardRes resDto = SavedCardRes.toDto(findCard);
response.setCode(200);
response.setResponse("success");
response.setMessage("카드 조회에 성공하였습니다.");
response.setData(findCard);
response.setData(resDto);
} catch (Exception e) {
response.setCode(500);
response.setResponse("failed");
Expand All @@ -66,15 +67,17 @@ public Response findOne(@PathVariable("id") Long cardId) {
}

@PostMapping("/update/{id}")
public Response update(@PathVariable("id") Long cardId, @RequestBody CreditCardInfo creditCardInfo) {
public Response update(@PathVariable("id") Long cardId, @RequestBody CreditCardInfoDto dto) {
Response response = new Response();

try {
creditCardService.update(cardId, creditCardInfo);
CreditCardInfo creditCardInfo = CreditCardInfoDto.toEntity(dto);
CreditCardInfo update = creditCardService.update(cardId, creditCardInfo);
CreditCardInfoDto creditCardInfoDto = CreditCardInfoDto.toDto(update);
response.setCode(200);
response.setResponse("success");
response.setMessage("카드 수정에 성공하였습니다.");
response.setData(creditCardInfo);
response.setData(creditCardInfoDto);
} catch (Exception e) {
response.setCode(500);
response.setResponse("failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public CreditCardInfo findOne(Long id) {
}

@Transactional
public void update(Long id, CreditCardInfo creditCardInfo) {
public CreditCardInfo update(Long id, CreditCardInfo creditCardInfo) {
CreditCardInfo findCreditCard = creditCardRepository.findById(id).orElseThrow(EntityNotFoundException::new);

findCreditCard.updateCreditCard(creditCardInfo);
return findCreditCard;
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ public class CreditCardInfoDto {
private int expireMonth;
private LocalDate birth;
private String simplePassword;
private User user;
private List<CustomOrder> customOrders = new ArrayList<>();
private List<Order> orders = new ArrayList<>();
private String email;

/**
* 신용카드 등록을 위한 dto to entity
Expand All @@ -44,12 +42,21 @@ public static CreditCardInfo toEntity(CreditCardInfoDto dto) {
.expireMonth(dto.getExpireMonth())
.birth(dto.getBirth())
.simplePassword(dto.getSimplePassword())
.user(dto.getUser())
.customOrders(dto.getCustomOrders())
.orders(dto.getOrders())
.build();
}

public static CreditCardInfoDto toDto(CreditCardInfo entity) {
return CreditCardInfoDto.builder()
.cardNickname(entity.getCardNickname())
.creditCardBank(entity.getCreditCardBank())
.cardNum(entity.getCardNum())
.expireYear(entity.getExpireYear())
.expireMonth(entity.getExpireMonth())
.birth(entity.getBirth())
.simplePassword(entity.getSimplePassword())
.email(entity.getUser().getEmail())
.build();
}


public void updateCreditCard(CreditCardInfoDto creditCardInfo) {
Expand Down