diff --git a/src/feature/customer/data/repo/customer-db-repo.ts b/src/feature/customer/data/repo/customer-db-repo.ts index fec27e1..f69239a 100644 --- a/src/feature/customer/data/repo/customer-db-repo.ts +++ b/src/feature/customer/data/repo/customer-db-repo.ts @@ -46,6 +46,11 @@ export default class CustomerDbRepo implements CustomerRepo { } } + async fetchCustomersAmount(): Promise { + const data = await sql`SELECT COUNT(*) FROM customers`as postgres.RowList; + return Number(data.count ?? '0'); + } + private customersDto(dbCustomers: customerDbResponse[]): Customer[] { return dbCustomers.map((customer) => this.customerDto(customer)); diff --git a/src/feature/customer/domain/i-repo/customer-repo.ts b/src/feature/customer/domain/i-repo/customer-repo.ts index 5c9cbf2..08e8226 100644 --- a/src/feature/customer/domain/i-repo/customer-repo.ts +++ b/src/feature/customer/domain/i-repo/customer-repo.ts @@ -2,6 +2,7 @@ import Customer from "@/feature/customer/domain/entity/customer" export default interface CustomerRepo { fetchList(query: string): Promise + fetchCustomersAmount(): Promise } export const customerRepoKey = "customerRepoKey" \ No newline at end of file diff --git a/src/feature/customer/domain/usecase/fetch-customers-amount-usecase.ts b/src/feature/customer/domain/usecase/fetch-customers-amount-usecase.ts new file mode 100644 index 0000000..608ae37 --- /dev/null +++ b/src/feature/customer/domain/usecase/fetch-customers-amount-usecase.ts @@ -0,0 +1,8 @@ +import serverDi from "@/feature/common/server-di"; +import { customerKey } from "@/feature/customer/customer-key"; +import CustomerRepo, { customerRepoKey } from "@/feature/customer/domain/i-repo/customer-repo"; + +export default function fetchCustomersAmountUsecase(): Promise { + const repo = serverDi(customerKey).resolve(customerRepoKey) + return repo.fetchCustomersAmount() +} \ No newline at end of file