This project is a RESTful API built with Spring Boot, designed to manage a database of movies, actors, and genres. It provides endpoints for CRUD operations on movies, actors, and genres, allowing clients to search, create, update, and delete entries with associated relationships. This API also includes pagination, validation, and custom exception handling for robust error management.
- Features
- Technologies Used
- Project Structure
- Endpoints
- Error Handling
- OpenAPI (Swagger) Documentation
- Getting Started
- License
- Contact
- Movies: Create, update, delete, and search for movies with details like title, release year, duration, and associated actors and genres.
- Actors: Manage actor records, including details like name and birth date, with relationships to movies.
- Genres: Manage genre records and associate them with movies.
- Pagination: Retrieve lists of entities (movies, actors, genres) with optional pagination.
- Error Handling: Custom exception handling for clear error messages on validation failures, not found resources, and more.
- OpenAPI Documentation: Integrated Swagger/OpenAPI documentation for API exploration.
- Java 17: Primary language
- Spring Boot 3.x: Framework for building the API
- Spring Data JPA: For database interaction
- Hibernate: ORM tool
- SQLite Database: A lightweight, file-based database suitable for development and testing (can be switched to other databases in production).
- Swagger (OpenAPI): API documentation
- Jakarta Validation: Input validation
-
Controllers: Define REST endpoints for interacting with Movies, Actors, and Genres:
ActorController
GenreController
MovieController
-
Entities: Represent database entities for movies, actors, and genres with JPA annotations:
Movie
Actor
Genre
-
Repositories: Database access layers using Spring Data JPA:
ActorRepository
GenreRepository
MovieRepository
-
Services: Core business logic for handling operations:
ActorService
GenreService
MovieService
-
Exceptions: Custom exceptions and global exception handling:
GlobalExceptionHandler
ResourceNotFoundException
-
Configuration: Configuration files and OpenAPI documentation setup:
OpenAPIConfig
POST /api/actors
- Create a new actorGET /api/actors
- Retrieve all actors (optional pagination)GET /api/actors/{id}
- Retrieve an actor by IDPATCH /api/actors/{id}
- Update an existing actorDELETE /api/actors/{id}
- Delete an actor (supports forced deletion)GET /api/actors/{actorId}/movies
- Retrieve movies associated with an actor
POST /api/genres
- Create a new genreGET /api/genres
- Retrieve all genres (optional pagination)GET /api/genres/{id}
- Retrieve a genre by IDPATCH /api/genres/{id}
- Update an existing genreDELETE /api/genres/{id}
- Delete a genre (supports forced deletion)
POST /api/movies
- Create a new movie, with optional genre and actor associationsGET /api/movies
- Retrieve all movies (optional filters for genre, actor, release year, and pagination)GET /api/movies/{id}
- Retrieve a movie by IDPATCH /api/movies/{id}
- Update an existing movie with optional genre and actor associationsDELETE /api/movies/{id}
- Delete a movie (supports forced deletion)GET /api/movies/{movieId}/actors
- Retrieve actors associated with a movieGET /api/movies/search
- Search movies by title
- GlobalExceptionHandler: Centralized error handling for custom exceptions and validation errors.
- Custom Exceptions:
ResourceNotFoundException
: Thrown when a requested resource is not found.
This project includes Swagger documentation for exploring the API. You can access the Swagger UI after running the application by navigating to: http://localhost:8080/swagger-ui.html
- Java 17 or higher
- Maven for project build and dependency management
- Clone the repository:
git clone https://github.com/your-username/movies-api.git
- Navigate to the project directory:
cd movies-api
- Build the project:
mvn clean install
- Run the application:
mvn spring-boot:run
The API will be available at http://localhost:8080.
Feel free to reach out with questions or for further assistance!