24 lines
756 B
TypeScript
24 lines
756 B
TypeScript
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));
|
|
}
|
|
} |