Introduce caching in CustomerRepository and refactor API integration

- Add in-memory caching for customer data in `CustomerRepository` to reduce API calls.
- Replace direct API calls with methods from `CustomerRepository`.
- Update customer-related pages (`[id]/page.tsx`, `customers/page.tsx`) to use `CustomerRepository` for data fetching.
- Adjust breadcrumb resolver to leverage `CustomerRepository`.
- Remove `axios` dependency from customer-related components.
This commit is contained in:
2025-07-07 22:02:55 +02:00
parent 4ae62f2911
commit 328c0537ba
4 changed files with 106 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
import {customerRoutes} from "@/app/api/customers/customerRoutes";
import {CustomerRepository} from "@/services/customers/repositories/customerRepository";
export const breadcrumbMap: Record<string, string> = {
'dashboard': 'Dashboard',
@@ -10,10 +10,11 @@ export const breadcrumbMap: Record<string, string> = {
export const breadcrumbResolvers: Record<string, (id: string) => Promise<string>> = {
"customers": async (id: string) => {
const res = await fetch(`/api${customerRoutes.getById(id)}`, {cache: "no-store"});
const customer = await res.json();
const customer = await CustomerRepository.getById(id);
if (!customer) return `ID: ${id}`;
if (customer.companyName) return `Firma: ${customer.companyName}`;
if (customer.name) return `Name: ${customer.name}`;
return `ID: ${id}`;
},
};
};