Skip to content

Commit

Permalink
feat : 허용범위와 예산 조회 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ehBeak committed Dec 5, 2023
1 parent c1403db commit 74d32f2
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.connect.accountApp.domain.household.adapter.in.web.controller;

import com.connect.accountApp.domain.household.adapter.in.web.response.GetBudgetAllowanceAmountResponse;
import com.connect.accountApp.domain.household.adapter.in.web.response.GetHouseholdBudgetResponse;
import com.connect.accountApp.domain.household.application.port.in.GetHouseholdBudgetUseCase;
import com.connect.accountApp.domain.household.domain.model.Household;
import com.connect.accountApp.global.common.adapter.in.web.response.SuccessResponse;
import java.math.BigDecimal;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/household")
@RequiredArgsConstructor
public class GetHouseholdBudgetController {

private final GetHouseholdBudgetUseCase getHouseholdBudgetUseCase;

@GetMapping("/budget")
public ResponseEntity getBudgetAllowanceAmount(@AuthenticationPrincipal UserDetails userDetails) {

String userEmail = userDetails.getUsername();
Household householdBudget = getHouseholdBudgetUseCase.getHouseholdBudget(userEmail);
GetHouseholdBudgetResponse response = new GetHouseholdBudgetResponse(
householdBudget.getHouseholdBudget(),
householdBudget.getHouseholdBudgetAllowanceRatio());

return ResponseEntity.ok(SuccessResponse.create200SuccessResponse(response));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.connect.accountApp.domain.household.adapter.in.web.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigDecimal;
import java.math.RoundingMode;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
public class GetHouseholdBudgetResponse {

@JsonProperty("budget_amount")
private BigDecimal householdBudgetAmount;
@JsonProperty("budget_allowance")
private Integer householdBudgetAllowance;

public GetHouseholdBudgetResponse(BigDecimal householdBudgetAmount, Integer householdBudgetAllowance) {
this.householdBudgetAmount = householdBudgetAmount.setScale(0, RoundingMode.FLOOR);
this.householdBudgetAllowance = householdBudgetAllowance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.connect.accountApp.domain.household.application.port.in;

import com.connect.accountApp.domain.household.domain.model.Household;

public interface GetHouseholdBudgetUseCase {

Household getHouseholdBudget(String userEmail);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.connect.accountApp.domain.household.application.service;

import com.connect.accountApp.domain.household.application.port.in.GetHouseholdBudgetUseCase;
import com.connect.accountApp.domain.household.application.port.out.GetHouseholdPort;
import com.connect.accountApp.domain.household.domain.model.Household;
import com.connect.accountApp.domain.user.application.port.out.FindHouseholdUserListPort;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class GetHouseholdBudgetService implements GetHouseholdBudgetUseCase {

private final GetHouseholdPort getHouseholdPort;
private final FindHouseholdUserListPort findHouseholdUserListPort;

@Override
public Household getHouseholdBudget(String userEmail) {
Long householdId = findHouseholdUserListPort.findHouseholdId(userEmail);
Household household = getHouseholdPort.getHousehold(householdId);
return household;
}
}

0 comments on commit 74d32f2

Please sign in to comment.