This project is a Spring Boot application designed to manage animals and their breeds. It includes features for creating, updating, and retrieving animals and their related data. The project follows a clean architecture with DTOs, services, repositories, and controllers.
- CRUD operations for animals and breeds.
- Global exception handling.
- Unit and integration tests for services and controllers.
- Database migrations with Liquibase.
To run this project, you need the following:
- Java 17
- PostgreSQL 14
- Maven 3.6 or higher
- Git
git clone https://github.com/roman-ustinov/interview-a2c6-548f9bd6e187.git
cd interview-a2c6-548f9bd6e187
- Create a PostgreSQL database:
createdb animals_db
The application supports two profiles:
- localhost: Used for local development.
spring.profiles.active=localhost spring.datasource.url=jdbc:postgresql://localhost:5432/animals_db spring.datasource.username=local_user spring.datasource.password=local_password
- prod: Used for production.
spring.profiles.active=prod spring.datasource.url=jdbc:postgresql://prod-db-server:5432/animals_db spring.datasource.username=prod_user spring.datasource.password=prod_password
Profiles can be switched by setting the spring.profiles.active
property in the application.properties
file or passing it as a command-line argument:
-Dspring.profiles.active=prod
- Build the application:
mvn clean install
- Run the application:
mvn spring-boot:run
- API Base URL:
http://localhost:8080
- Swagger UI:
http://localhost:8080/swagger-ui.html
src/main/java
:controller
: REST controllers for handling HTTP requests.service
: Service layer with business logic.repository
: JPA repositories for database interactions.model
: JPA entity classes.dto
: Data Transfer Objects.mapper
: MapStruct mappers for converting between entities and DTOs.config
: Configuration classes.exception
: Custom exceptions and global exception handler.
src/main/resources
:application.properties
: Main configuration file.application-localhost.properties
: Localhost configuration file.application-prod.properties
: Production configuration file.db/
: Liquibase migration files.
src/test/java
: Unit and integration tests.
Liquibase is used for managing database schema changes. Update db/liquibase-changelog.xml
for new migrations. Run migrations automatically when the application starts or manually with:
mvn liquibase:update
Run tests with:
mvn test
- Spring Boot: Application framework.
- Liquibase: Database schema management.
- MapStruct: Object mapping.
- JUnit 5: Testing framework.
- HikariCP: Connection pooling.
- Swagger/OpenAPI: API documentation.
POST /api/v1/animals
{
"name": "Alfa",
"age": 3,
"breedId": 1,
"gender": "MALE"
}
GET /api/v1/animals/{id}
GET /api/v1/animals
GET /api/v1/animals/details
PUT /api/v1/animals
{
"id": 1,
"name": "Beta",
"age": 4,
"breedId": 2,
"gender": "FEMALE"
}
DELETE /api/v1/animals/{id}
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with detailed explanations.
This project is licensed under the MIT License.