diff --git a/src/main/java/ewha/lux/once/domain/card/controller/CardController.java b/src/main/java/ewha/lux/once/domain/card/controller/CardController.java index 5f4b4bc..7d0ee61 100644 --- a/src/main/java/ewha/lux/once/domain/card/controller/CardController.java +++ b/src/main/java/ewha/lux/once/domain/card/controller/CardController.java @@ -1,5 +1,6 @@ package ewha.lux.once.domain.card.controller; +import ewha.lux.once.domain.card.dto.CardGoalRequestDto; import ewha.lux.once.domain.card.dto.CardPerformanceRequestDto; import ewha.lux.once.domain.card.service.CardService; import ewha.lux.once.global.common.CommonResponse; @@ -52,4 +53,16 @@ public CommonResponse montlyBenefitInfo(@AuthenticationPrincipal UserAccount return new CommonResponse<>(e.getStatus()); } } + + // [Post] 카드 목표 혜택 금액 입력 + @PostMapping("/benefitgoal") + @ResponseBody + public CommonResponse cardGoal(@AuthenticationPrincipal UserAccount user, @RequestBody CardGoalRequestDto cardGoalRequestDto) { + try { + cardService.postBenefitGoal(user.getUsers(), cardGoalRequestDto); + return new CommonResponse<>(ResponseCode.SUCCESS); + } catch (CustomException e) { + return new CommonResponse<>(e.getStatus()); + } + } } diff --git a/src/main/java/ewha/lux/once/domain/card/dto/CardGoalRequestDto.java b/src/main/java/ewha/lux/once/domain/card/dto/CardGoalRequestDto.java new file mode 100644 index 0000000..ca0a539 --- /dev/null +++ b/src/main/java/ewha/lux/once/domain/card/dto/CardGoalRequestDto.java @@ -0,0 +1,14 @@ +package ewha.lux.once.domain.card.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class CardGoalRequestDto { + private int benefitGoal; +} diff --git a/src/main/java/ewha/lux/once/domain/card/service/CardService.java b/src/main/java/ewha/lux/once/domain/card/service/CardService.java index 49c4bdb..337a5b8 100644 --- a/src/main/java/ewha/lux/once/domain/card/service/CardService.java +++ b/src/main/java/ewha/lux/once/domain/card/service/CardService.java @@ -1,5 +1,6 @@ package ewha.lux.once.domain.card.service; +import ewha.lux.once.domain.card.dto.CardGoalRequestDto; import ewha.lux.once.domain.card.dto.CardPerformanceRequestDto; import ewha.lux.once.domain.card.dto.MontlyBenefitResponseDto; import ewha.lux.once.domain.card.dto.MyWalletResponseDto; @@ -12,6 +13,7 @@ import ewha.lux.once.global.repository.CardRepository; import ewha.lux.once.global.repository.ChatHistoryRepository; import ewha.lux.once.global.repository.OwnedCardRepository; +import ewha.lux.once.global.repository.UsersRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -27,6 +29,7 @@ public class CardService { private final OwnedCardRepository ownedCardRepository; private final ChatHistoryRepository chatHistoryRepository; + private final UsersRepository usersRepository; public MyWalletResponseDto.MyWalletProfileDto getMyWalletInfo(Users nowUser) throws CustomException { List ownedCards = ownedCardRepository.findOwnedCardByUsers(nowUser); @@ -114,6 +117,12 @@ public MontlyBenefitResponseDto.MontlyBenefitProfileDto getMontlyBenefitInfo(Use .build(); } + public void postBenefitGoal(Users nowUser, CardGoalRequestDto cardGoalRequestDto) throws CustomException { + nowUser.setCardGoal(cardGoalRequestDto.getBenefitGoal()); + usersRepository.save(nowUser); + return; + } + private List splitCardSummary(String cardSummary) { List cardBenefitList = new ArrayList<>(); String[] sections = cardSummary.split("###"); diff --git a/src/main/java/ewha/lux/once/domain/user/entity/Users.java b/src/main/java/ewha/lux/once/domain/user/entity/Users.java index 89f8ade..a68f428 100644 --- a/src/main/java/ewha/lux/once/domain/user/entity/Users.java +++ b/src/main/java/ewha/lux/once/domain/user/entity/Users.java @@ -103,4 +103,5 @@ public void updatePassword(String password) { this.password = password; } + public void setCardGoal(int goal) {this.benefitGoal = goal;} }