44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import type {
|
|
GetPrivateAlbumsInput,
|
|
IPrivateZoneRepository,
|
|
} from "@/data/repositories/interfaces";
|
|
import {
|
|
type PrivateAlbumsResponse,
|
|
type PrivateAlbumUnlockResponse,
|
|
UnlockPrivateAlbumRequestSchema,
|
|
} from "@/data/schemas/private-zone";
|
|
import {
|
|
PrivateZoneApi,
|
|
privateZoneApi,
|
|
} from "@/data/services/api/private_zone_api";
|
|
import { Result } from "@/utils/result";
|
|
|
|
import { createLazySingleton } from "./lazy_singleton";
|
|
|
|
export class PrivateZoneRepository implements IPrivateZoneRepository {
|
|
constructor(private readonly api: PrivateZoneApi) {}
|
|
|
|
getAlbums(
|
|
input: GetPrivateAlbumsInput,
|
|
): Promise<Result<PrivateAlbumsResponse>> {
|
|
return Result.wrap(() => this.api.getAlbums(input));
|
|
}
|
|
|
|
unlockAlbum(
|
|
albumId: string,
|
|
expectedCost: number,
|
|
): Promise<Result<PrivateAlbumUnlockResponse>> {
|
|
return Result.wrap(() =>
|
|
this.api.unlockAlbum(
|
|
albumId,
|
|
UnlockPrivateAlbumRequestSchema.parse({ expectedCost }),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
export const getPrivateZoneRepository =
|
|
createLazySingleton<IPrivateZoneRepository>(
|
|
() => new PrivateZoneRepository(privateZoneApi),
|
|
);
|