UNPKG

ruch

Version:

Revolutionary React TypeScript CLI with hexagonal architecture & AI-powered development assistance. Create maintainable, scalable applications with domain-driven design and integrated AI tooling.

55 lines (49 loc) 1.85 kB
import type { PaymentEntity, PaymentCreationData, PaymentUpdateData } from '../entities/Payment'; import type { PaymentPort } from '../ports/PaymentPort'; import { PaymentError } from '../services/PaymentService'; import { httpClient } from '../../../lib/http-client'; /** * HTTP Adapter implementation for Payment domain */ export class PaymentAdapter implements PaymentPort { private readonly endpoint = '/payment'; async getAll(): Promise<PaymentEntity[]> { try { const response = await httpClient.get<PaymentEntity[]>(this.endpoint); return response.data; } catch (error) { throw new PaymentError('REQUEST_ERROR', `Failed to fetch payment list`); } } async getById(id: string): Promise<PaymentEntity> { try { const response = await httpClient.get<PaymentEntity>(`${this.endpoint}/${id}`); return response.data; } catch (error) { throw new PaymentError('REQUEST_ERROR', `Failed to fetch payment with id ${id}`); } } async create(data: PaymentCreationData): Promise<PaymentEntity> { try { const response = await httpClient.post<PaymentEntity>(this.endpoint, data); return response.data; } catch (error) { throw new PaymentError('REQUEST_ERROR', `Failed to create payment`); } } async update(id: string, data: PaymentUpdateData): Promise<PaymentEntity> { try { const response = await httpClient.put<PaymentEntity>(`${this.endpoint}/${id}`, data); return response.data; } catch (error) { throw new PaymentError('REQUEST_ERROR', `Failed to update payment with id ${id}`); } } async delete(id: string): Promise<void> { try { await httpClient.delete(`${this.endpoint}/${id}`); } catch (error) { throw new PaymentError('REQUEST_ERROR', `Failed to delete payment with id ${id}`); } } }