Skip to content

Commit

Permalink
[FIX] 날짜별 예산 조회 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ssongmina committed Aug 18, 2024
1 parent ee2922b commit 9b47ac8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
15 changes: 12 additions & 3 deletions src/main/java/umc/haruchi/converter/DayBudgetConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.time.LocalDate;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

public class DayBudgetConverter {

Expand All @@ -33,10 +34,18 @@ public static DayBudgetResponseDTO.getDayBudget toGetDayBudget(Integer todayBudg
.dayBudget(todayBudget)
.build();
}

public static DayBudgetResponseDTO.getBudget toGetBudget(List<Integer> allBudget) {
public static DayBudgetResponseDTO.getBudget toGetBudget(DayBudget dayBudget) {
return DayBudgetResponseDTO.getBudget.builder()
.budget(allBudget)
.day(dayBudget.getDay())
.dayBudget(dayBudget.getDayBudget())
.build();
}

public static DayBudgetResponseDTO.getBudgetList toGetBudgetList(List<DayBudget> allBudget) {
List<DayBudgetResponseDTO.getBudget> getBudgetList = allBudget.stream()
.map(DayBudgetConverter::toGetBudget).collect(Collectors.toList());
return DayBudgetResponseDTO.getBudgetList.builder()
.budget(getBudgetList)
.build();
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/umc/haruchi/service/DayBudgetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Integer findDayBudget(Long memberId) {
return dayBudget.getDayBudget();
}

public List<Integer> findAllBudget(Long memberId) {
public List<DayBudget> findAllBudget(Long memberId) {
LocalDate now = LocalDate.now();
int year = now.getYear();
int month = now.getMonthValue();
Expand All @@ -85,12 +85,11 @@ public List<Integer> findAllBudget(Long memberId) {
dayBudgetRepository.saveAll(dayBudgets);


List<Integer> allBudget = new ArrayList<>();
List<DayBudget> allBudget = new ArrayList<>();
for(int i=day; i<=lastDay; i++){
DayBudget dayBudget = dayBudgetRepository.findByMonthBudgetAndDay(monthBudget, i)
.orElseThrow(() -> new DayBudgetHandler(NOT_SOME_DAY_BUDGET));
allBudget.add(dayBudget.getDayBudget());

allBudget.add(dayBudget);
}

return allBudget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import umc.haruchi.apiPayload.ApiResponse;
import umc.haruchi.config.login.auth.MemberDetail;
import umc.haruchi.converter.DayBudgetConverter;
import umc.haruchi.domain.DayBudget;
import umc.haruchi.domain.Expenditure;
import umc.haruchi.domain.Income;
import umc.haruchi.service.DayBudgetService;
Expand All @@ -33,9 +34,9 @@ public ApiResponse<DayBudgetResponseDTO.getDayBudget> getDailyBudget(@Authentica

@Operation(summary = "날짜별 예산 금액 조회하는 API.", description = "오늘부터 말일까지의 예산을 조회하는 API 입니다.")
@GetMapping("/list")
public ApiResponse<DayBudgetResponseDTO.getBudget> getAllBudget(@AuthenticationPrincipal MemberDetail memberDetail){
List<Integer> allBudget = dayBudgetService.findAllBudget(memberDetail.getMember().getId());
return ApiResponse.onSuccess(DayBudgetConverter.toGetBudget(allBudget));
public ApiResponse<DayBudgetResponseDTO.getBudgetList> getAllBudget(@AuthenticationPrincipal MemberDetail memberDetail){
List<DayBudget> allBudget = dayBudgetService.findAllBudget(memberDetail.getMember().getId());
return ApiResponse.onSuccess(DayBudgetConverter.toGetBudgetList(allBudget));
}

@Operation(summary = "수입 등록 API", description = "하루 수입을 등록하는 API 입니다.")
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/umc/haruchi/web/dto/DayBudgetResponseDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.haruchi.domain.DayBudget;

import java.time.LocalDate;
import java.util.List;
Expand All @@ -23,8 +24,17 @@ public static class getDayBudget {
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class getBudget {
List<Integer> budget;
public static class getBudgetList {
List<getBudget> budget;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class getBudget{
Long day;
Integer dayBudget;
}

@Builder
Expand Down

0 comments on commit 9b47ac8

Please sign in to comment.