Skip to content

Commit

Permalink
feat: 목표 혜택 금액 입력 api 구현 (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiminnee committed Feb 8, 2024
1 parent a8b2b5e commit f4de8d7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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<OwnedCard> ownedCards = ownedCardRepository.findOwnedCardByUsers(nowUser);
Expand Down Expand Up @@ -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<MyWalletResponseDto.CardBenefitListDto> splitCardSummary(String cardSummary) {
List<MyWalletResponseDto.CardBenefitListDto> cardBenefitList = new ArrayList<>();
String[] sections = cardSummary.split("###");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ewha/lux/once/domain/user/entity/Users.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ public void updatePassword(String password) {
this.password = password;
}

public void setCardGoal(int goal) {this.benefitGoal = goal;}
}

0 comments on commit f4de8d7

Please sign in to comment.