```python from fastapi import FastAPI, HTTPException from pydantic import BaseModel from typing import List, Dict, Optional app = FastAPI() class Book(BaseModel): title: str author_id: int publisher_id: int genre_id: int price: float class Author(BaseModel): name: str birth_year: int nationality: str bio: str class Publisher(BaseModel): name: str country: str founded_year: int website: str class Genre(BaseModel): name: str description: str parent_genre_id: Optional[int] = None is_active: bool class Customer(BaseModel): name: str email: str phone: str address: str books: Dict[int, Book] = {} authors: Dict[int, Author] = {} publishers: Dict[int, Publisher] = {} genres: Dict[int, Genre] = {} customers: Dict[int, Customer] = {} book_counter = 0 author_counter = 0 publisher_counter = 0 genre_counter = 0 customer_counter = 0 def list_books() -> List[Book]: """Return all books.""" return list(books.values()) def get_book(book_id: int) -> Book: """Get a book by its id.""" if book_id not in books: raise HTTPException(status_code=404, detail="Book not found") return books[book_id] def create_book(book: Book) -> Book: """Create a new book.""" global book_counter book_counter += 1 books[book_counter] = book return book def update_book(book_id: int, book: Book) -> Book: """Update an existing book.""" if book_id not in books: raise HTTPException(status_code=404, detail="Book not found") books[book_id] = book return book def delete_book(book_id: int) -> None: """Delete a book by its id.""" if book_id not in books: raise HTTPException(status_code=404, detail="Book not found") del books[book_id] def list_authors() -> List[Author]: """Return all authors.""" return list(authors.values()) def get_author(author_id: int) -> Author: """Get an author by their id.""" if author_id not in authors: raise HTTPException(status_code=404, detail="Author not found") return authors[author_id] def create_author(author: Author) -> Author: """Create a new author.""" global author_counter author_counter += 1 authors[author_counter] = author return author def update_author(author_id: int, author: Author) -> Author: """Update an existing author.""" if author_id not in authors: raise HTTPException(status_code=404, detail="Author not found") authors[author_id] = author return author def delete_author(author_id: int) -> None: """Delete an author by their id.""" if author_id not in authors: raise HTTPException(status_code=404, detail="Author not found") del authors[author_id] def list_publishers() -> List[Publisher]: """Return all publishers.""" return list(publishers.values()) def get_publisher(publisher_id: int) -> Publisher: """Get a publisher by their id.""" if publisher_id not in publishers: raise HTTPException(status_code=404, detail="Publisher not found") return publishers[publisher_id] def create_publisher(publisher: Publisher) -> Publisher: """Create a new publisher.""" global publisher_counter publisher_counter += 1 publishers[publisher_counter] = publisher return publisher def update_publisher(publisher_id: int, publisher: Publisher) -> Publisher: """Update an existing publisher.""" if publisher_id not in publishers: raise HTTPException(status_code=404, detail="Publisher not found") publishers[publisher_id] = publisher return publisher def delete_publisher(publisher_id: int) -> None: """Delete a publisher by their id.""" if publisher_id not in publishers: raise HTTPException(status_code=404, detail="Publisher not found") del publishers[publisher_id] def list_genres() -> List[Genre]: """Return all genres.""" return list(genres.values()) def get_genre(genre_id: int) -> Genre: """Get a genre by its id.""" if genre_id not in genres: raise HTTPException(status_code=404, detail="Genre not found") return genres[genre_id] def create_genre(genre: Genre) -> Genre: """Create a new genre.""" global genre_counter genre_counter += 1 genres[genre_counter] = genre return genre def update_genre(genre_id: int, genre: Genre) -> Genre: """Update an existing genre.""" if genre_id not in genres: raise HTTPException(status_code=404, detail="Genre not found") genres[genre_id] = genre return genre def delete_genre(genre_id: int) -> None: """Delete a genre by its id.""" if genre_id not in genres: raise HTTPException(status_code=404, detail="Genre not found") del genres[genre_id] def list_customers() -> List[Customer]: """Return all customers.""" return list(customers.values()) def get_customer(customer_id: int) -> Customer: """Get a customer by their id.""" if customer_id not in customers: raise HTTPException(status_code=404, detail="Customer not found") return customers[customer_id] def create_customer(customer: Customer) -> Customer: """Create a new customer.""" global customer_counter customer_counter += 1 customers[customer_counter] = customer return customer def update_customer(customer_id: int, customer: Customer) -> Customer: """Update an existing customer.""" if customer_id not in customers: raise HTTPException(status_code=404, detail="Customer not found") customers[customer_id] = customer return customer def delete_customer(customer_id: int) -> None: """Delete a customer by their id.""" if customer_id not in customers: raise HTTPException(status_code=404, detail="Customer not found") del customers[customer_id] @app.get("/books", response_model=List[Book]) def books_list() -> List[Book]: """List all books.""" return list_books() @app.get("/books/{book_id}", response_model=Book) def books_get(book_id: int) -> Book: """Get a book by id.""" return get_book(book_id) @app.post("/books", response_model=Book) def books_create(book: Book) -> Book: """Create a new book.""" return create_book(book) @app.put("/books/{book_id}", response_model=Book) def books_update(book_id: int, book: Book) -> Book: """Update a book by id.""" return update_book(book_id, book) @app.delete("/books/{book_id}") def books_delete(book_id: int) -> None: """Delete a book by id.""" delete_book(book_id) @app.get("/authors", response_model=List[Author]) def authors_list() -> List[Author]: """List all authors.""" return list_authors() @app.get("/authors/{author_id}", response_model=Author) def authors_get(author_id: int) -> Author: """Get an author by id.""" return get_author(author_id) @app.post("/authors", response_model=Author) def authors_create(author: Author) -> Author: """Create a new author.""" return create_author(author) @app.put("/authors/{author_id}", response_model=Author) def authors_update(author_id: int, author: Author) -> Author: """Update an author by id.""" return update_author(author_id, author) @app.delete("/authors/{author_id}") def authors_delete(author_id: int) -> None: """Delete an author by id.""" delete_author(author_id) @app.get("/publishers", response_model=List[Publisher]) def publishers_list() -> List[Publisher]: """List all publishers.""" return list_publishers() @app.get("/publishers/{publisher_id}", response_model=Publisher) def publishers_get(publisher_id: int) -> Publisher: """Get a publisher by id.""" return get_publisher(publisher_id) @app.post("/publishers", response_model=Publisher) def publishers_create(publisher: Publisher) -> Publisher: """Create a new publisher.""" return create_publisher(publisher) @app.put("/publishers/{publisher_id}", response_model=Publisher) def publishers_update(publisher_id: int, publisher: Publisher) -> Publisher: """Update a publisher by id.""" return update_publisher(publisher_id, publisher) @app.delete("/publishers/{publisher_id}") def publishers_delete(publisher_id: int) -> None: """Delete a publisher by id.""" delete_publisher(publisher_id) @app.get("/genres", response_model=List[Genre]) def genres_list() -> List[Genre]: """List all genres.""" return list_genres() @app.get("/genres/{genre_id}", response_model=Genre) def genres_get(genre_id: int) -> Genre: """Get a genre by id.""" return get_genre(genre_id) @app.post("/genres", response_model=Genre) def genres_create(genre: Genre) -> Genre: """Create a new genre.""" return create_genre(genre) @app.put("/genres/{genre_id}", response_model=Genre) def genres_update(genre_id: int, genre: Genre) -> Genre: """Update a genre by id.""" return update_genre(genre_id, genre) @app.delete("/genres/{genre_id}") def genres_delete(genre_id: int) -> None: """Delete a genre by id.""" delete_genre(genre_id) @app.get("/customers", response_model=List[Customer]) def customers_list() -> List[Customer]: """List all customers.""" return list_customers() @app.get("/customers/{customer_id}", response_model=Customer) def customers_get(customer_id: int) -> Customer: """Get a customer by id.""" return get_customer(customer_id) @app.post("/customers", response_model=Customer) def customers_create(customer: Customer) -> Customer: """Create a new customer.""" return create_customer(customer) @app.put("/customers/{customer_id}", response_model=Customer) def customers_update(customer_id: int, customer: Customer) -> Customer: """Update a customer by id.""" return update_customer(customer_id, customer) @app.delete("/customers/{customer_id}") def customers_delete(customer_id: int) -> None: """Delete a customer by id.""" delete_customer(customer_id) ```