Skip to content

Commit

Permalink
[FIX] 회원가입 시 생성한 monthBudget 저장하는 코드 추가 및 Optional 레포지토리에서 찾을 때 orEls…
Browse files Browse the repository at this point in the history
…e(null) 코드 추가
  • Loading branch information
hcg0127 committed Aug 1, 2024
1 parent 87bb743 commit 29d2076
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/main/java/umc/haruchi/domain/DayBudget.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public void setStatus(DayBudgetStatus status) {

public void setDayBudget(int distributedAmount) {
dayBudget = distributedAmount;
}

public void setExpenditure(long amount, int how) {
if(how == 0)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/umc/haruchi/domain/MonthBudget.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void updateMonthBudget(Long monthBudget) {
this.year = now.getYear();
this.month = now.getMonthValue();
this.monthBudget = monthBudget;
}

public void setMonthUse(long amount, int how) {
if(how == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ public PushPlusClosing closingPlusOrZero(BudgetRedistributionRequestDTO.createCl
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new MemberHandler(NO_MEMBER_EXIST)); //영속화

MonthBudget monthBudget = monthBudgetRepository.findByMemberIdAndYearAndMonth(member.getId(), request.getYear(), request.getMonth());
DayBudget dayBudget = dayBudgetRepository.findByMonthBudgetAndDay(monthBudget, request.getDay());
MonthBudget monthBudget = monthBudgetRepository.findByMemberIdAndYearAndMonth(member.getId(), request.getYear(), request.getMonth()).orElse(null);
DayBudget dayBudget = dayBudgetRepository.findByMonthBudgetAndDay(monthBudget, request.getDay()).orElse(null);

//이미 마감된 날 에러처리
if(dayBudget.getDayBudgetStatus().equals(DayBudgetStatus.INACTIVE)) {
Expand Down Expand Up @@ -394,8 +394,9 @@ public PullMinusClosing closingMinus(BudgetRedistributionRequestDTO.createClosin
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new MemberHandler(NO_MEMBER_EXIST)); //영속화

MonthBudget monthBudget = monthBudgetRepository.findByMemberIdAndYearAndMonth(member.getId(), request.getYear(), request.getMonth());
DayBudget dayBudget = dayBudgetRepository.findByMonthBudgetAndDay(monthBudget, request.getDay());
//orElse(null)을 붙여 수정함 -> null일 때 throw 처리 해야 할 수도?
MonthBudget monthBudget = monthBudgetRepository.findByMemberIdAndYearAndMonth(member.getId(), request.getYear(), request.getMonth()).orElse(null);
DayBudget dayBudget = dayBudgetRepository.findByMonthBudgetAndDay(monthBudget, request.getDay()).orElse(null);

//이미 마감된 날 에러처리
if(dayBudget.getDayBudgetStatus().equals(DayBudgetStatus.INACTIVE)) {
Expand Down Expand Up @@ -479,7 +480,7 @@ public PullMinusClosing closingMinus(BudgetRedistributionRequestDTO.createClosin

public Long calculatingAmount(int year, int month, int day, Long amount, Long memberId) {

MonthBudget monthBudget = monthBudgetRepository.findByMemberIdAndYearAndMonth(memberId, year, month);
MonthBudget monthBudget = monthBudgetRepository.findByMemberIdAndYearAndMonth(memberId, year, month).orElse(null);

//이번 달 남은 일 수 알아내기(본인 제외)
long dayCount = monthBudget.getDayBudgetList().stream()
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/umc/haruchi/service/DayBudgetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public Income joinIncome(DayBudgetRequestDTO.createIncomeDTO request, Long membe
public Expenditure joinExpenditure(DayBudgetRequestDTO.createExpenditureDTO request, Long memberId) {
MonthBudget monthBudget = check(memberId);

DayBudget dayBudget = dayBudgetRepository.findByMonthBudgetAndDay(monthBudget, day);
DayBudget dayBudget = dayBudgetRepository.findByMonthBudgetAndDay(monthBudget, day).orElse(null);
if(dayBudget == null){
throw new DayBudgetHandler(ErrorStatus.NOT_DAY_BUDGET);
}
Expand All @@ -154,7 +154,7 @@ public Expenditure joinExpenditure(DayBudgetRequestDTO.createExpenditureDTO requ
public void deleteExpenditure(Long memberId, Long expenditureId) {
MonthBudget monthBudget = check(memberId);

DayBudget dayBudget = dayBudgetRepository.findByMonthBudgetAndDay(monthBudget, day);
DayBudget dayBudget = dayBudgetRepository.findByMonthBudgetAndDay(monthBudget, day).orElse(null);
if(dayBudget == null){
throw new DayBudgetHandler(ErrorStatus.NOT_DAY_BUDGET);
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/umc/haruchi/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@
import umc.haruchi.apiPayload.code.status.ErrorStatus;
import umc.haruchi.apiPayload.exception.handler.JwtExceptionHandler;
import umc.haruchi.apiPayload.exception.handler.MemberHandler;
import umc.haruchi.apiPayload.exception.handler.MonthBudgetHandler;
import umc.haruchi.config.login.jwt.JwtUtil;
import umc.haruchi.converter.MemberConverter;
import umc.haruchi.converter.MonthBudgetConverter;
import umc.haruchi.domain.Member;

import umc.haruchi.domain.MemberToken;
import umc.haruchi.domain.MonthBudget;
import umc.haruchi.domain.Withdrawer;
import umc.haruchi.domain.DayBudget;
import umc.haruchi.repository.*;

import umc.haruchi.web.dto.MemberRequestDTO;
import umc.haruchi.web.dto.MemberResponseDTO;
import umc.haruchi.web.dto.MonthBudgetRequestDTO;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -61,6 +58,7 @@ public Member joinMember(MemberRequestDTO.MemberJoinDTO request) throws Exceptio
//회원가입 시 monthBudget 생성
MonthBudget monthBudget = MonthBudgetConverter.toMonthBudget(request.getMonthBudget());
monthBudget.setMember(newMember);
monthBudgetRepository.save(monthBudget);

return memberRepository.save(newMember);
}
Expand Down

0 comments on commit 29d2076

Please sign in to comment.