import type { Book } from './Book';

export async function getAllBooks(): Promise<Book[]> {
  const response = await fetch(`${import.meta.env.VITE_API_SERVER}/books`);
  if (!response.ok) {
    throw new Error('Anfrage fehlgeschlagen');
  }
  const data = await response.json();
  return data;
}

export async function deleteBook(id: number): Promise<void> {
  const response = await fetch(
    `${import.meta.env.VITE_API_SERVER}/books/${id}`,
    {
      method: 'DELETE',
    }
  );
  if (!response.ok) {
    throw new Error('Löschen fehlgeschlagen');
  }
}
