Skip to content

Commit

Permalink
refactor(bill): 조회시 사용되는 컨트롤러와 포트 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
ehBeak committed Dec 26, 2023
1 parent 2005fd3 commit e7f7ad3
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 148 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.connect.accountApp.domain.bill.adapter.in.web.controller;

import com.connect.accountApp.domain.bill.adapter.in.web.response.GetBillResponse;
import com.connect.accountApp.domain.bill.adapter.in.web.response.GetBillsResponse;
import com.connect.accountApp.domain.bill.adapter.in.web.response.RecentBillCategoriesResponse;
import com.connect.accountApp.domain.bill.application.port.command.BillCommand;
import com.connect.accountApp.domain.bill.application.port.command.RecentBillCategoryCommand;
import com.connect.accountApp.domain.bill.application.port.in.GetBillUseCase;
import com.connect.accountApp.domain.bill.domain.model.Bill;
import com.connect.accountApp.domain.bill.domain.model.BillCategory;
import com.connect.accountApp.global.common.adapter.in.web.response.SuccessResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -23,10 +29,29 @@ public class GetBillController {
@GetMapping("/bill/{bill_id}")
public ResponseEntity getBillsUseCase(@AuthenticationPrincipal UserDetails userDetails,
@PathVariable("bill_id") Long billId) {

Bill bill = getBillUseCase.getBill(billId);

GetBillResponse response = new GetBillResponse(bill);
return ResponseEntity.ok(SuccessResponse.create200SuccessResponse(response));
}

@GetMapping("/bills/{bill-category}")
public ResponseEntity getBillsUseCase(@AuthenticationPrincipal UserDetails userDetails,
@PathVariable("bill-category") BillCategory billCategory) {

String userEmail = userDetails.getUsername();
List<BillCommand> commands = getBillUseCase.getBills(userEmail, billCategory);

GetBillsResponse response = new GetBillsResponse(commands);
return ResponseEntity.ok(SuccessResponse.create200SuccessResponse(response));
}

@GetMapping("bills/category")
public ResponseEntity getBillsUseCase(@AuthenticationPrincipal UserDetails userDetails) {

String userEmail = userDetails.getUsername();
List<RecentBillCategoryCommand> commands = getBillUseCase.getRecentBillCategory(userEmail);

RecentBillCategoriesResponse response = new RecentBillCategoriesResponse(commands);
return ResponseEntity.ok(SuccessResponse.create200SuccessResponse(response));
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.connect.accountApp.domain.bill.application.port.in;

import com.connect.accountApp.domain.bill.application.port.command.BillCommand;
import com.connect.accountApp.domain.bill.application.port.command.RecentBillCategoryCommand;
import com.connect.accountApp.domain.bill.domain.model.Bill;
import com.connect.accountApp.domain.bill.domain.model.BillCategory;
import java.util.List;

public interface GetBillUseCase {

Bill getBill(Long billId);

List<BillCommand> getBills(String userEmail, BillCategory billCategory);

List<RecentBillCategoryCommand> getRecentBillCategory(String userEmail);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.connect.accountApp.domain.bill.application.service;

import com.connect.accountApp.domain.bill.application.port.command.BillCommand;
import com.connect.accountApp.domain.bill.application.port.command.RecentBillCategoryCommand;
import com.connect.accountApp.domain.bill.application.port.in.GetBillUseCase;
import com.connect.accountApp.domain.bill.application.port.out.FindBillPort;
import com.connect.accountApp.domain.bill.domain.model.Bill;
import com.connect.accountApp.domain.bill.domain.model.BillCategory;
import com.connect.accountApp.domain.household.domain.model.Household;
import com.connect.accountApp.domain.user.application.port.out.GetUserPort;
import com.connect.accountApp.domain.user.domain.model.User;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -11,11 +18,25 @@
public class GetBillService implements GetBillUseCase {

private final FindBillPort findBillPort;
private final GetUserPort getUserPort;

@Override
public Bill getBill(Long billId) {
Bill bill = findBillPort.findBill(billId);
return bill;
}

@Override
public List<BillCommand> getBills(String userEmail, BillCategory billCategory) {
User userWithHousehold = getUserPort.findUserWithHousehold(userEmail);
Household household = userWithHousehold.getHousehold();
return findBillPort.findBills(household.getHouseholdId(), billCategory);
}

@Override
public List<RecentBillCategoryCommand> getRecentBillCategory(String userEmail) {
User userWithHousehold = getUserPort.findUserWithHousehold(userEmail);
Long householdId = userWithHousehold.getHousehold().getHouseholdId();
return findBillPort.findRecentBills(householdId);
}
}

This file was deleted.

This file was deleted.

0 comments on commit e7f7ad3

Please sign in to comment.