-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...t/accountApp/domain/household/adapter/in/web/controller/GetHouseholdBudgetController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...nnect/accountApp/domain/household/adapter/in/web/response/GetHouseholdBudgetResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...om/connect/accountApp/domain/household/application/port/in/GetHouseholdBudgetUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
23 changes: 23 additions & 0 deletions
23
...om/connect/accountApp/domain/household/application/service/GetHouseholdBudgetService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |