Replace entire repo content with correct code from /root/shahikitchen-website/
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import type { CartRepository } from '@/domain/cart/repository';
|
||||
import type { CartItem } from '@/domain/cart/entities';
|
||||
import { STORAGE_KEYS } from '@/domain/shared/constants';
|
||||
|
||||
export class LocalStorageCartRepository implements CartRepository {
|
||||
load(): CartItem[] {
|
||||
if (typeof window === 'undefined') return [];
|
||||
|
||||
const raw = localStorage.getItem(STORAGE_KEYS.cart);
|
||||
if (!raw) return [];
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as CartItem[];
|
||||
return Array.isArray(parsed) ? parsed : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
save(items: CartItem[]): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
localStorage.setItem(STORAGE_KEYS.cart, JSON.stringify(items));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { LanguageRepository } from '@/domain/language/repository';
|
||||
import { isLanguage, type Language } from '@/domain/language/entities';
|
||||
import { STORAGE_KEYS } from '@/domain/shared/constants';
|
||||
|
||||
export class LocalStorageLanguageRepository implements LanguageRepository {
|
||||
load(): Language | null {
|
||||
if (typeof window === 'undefined') return null;
|
||||
|
||||
const saved = localStorage.getItem(STORAGE_KEYS.language);
|
||||
if (saved && isLanguage(saved)) return saved;
|
||||
return null;
|
||||
}
|
||||
|
||||
save(language: Language): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
localStorage.setItem(STORAGE_KEYS.language, language);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { WishlistRepository } from '@/domain/wishlist/repository';
|
||||
import type { WishlistItem } from '@/domain/wishlist/entities';
|
||||
import { STORAGE_KEYS } from '@/domain/shared/constants';
|
||||
|
||||
export class LocalStorageWishlistRepository implements WishlistRepository {
|
||||
load(): WishlistItem[] {
|
||||
if (typeof window === 'undefined') return [];
|
||||
|
||||
const raw = localStorage.getItem(STORAGE_KEYS.wishlist);
|
||||
if (!raw) return [];
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as WishlistItem[];
|
||||
return Array.isArray(parsed) ? parsed : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
save(items: WishlistItem[]): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
localStorage.setItem(STORAGE_KEYS.wishlist, JSON.stringify(items));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user