A Spring Boot application that fetches and stores animal images Cats, Bears, and Dogs.
# Clone the repository
git clone https://github.com/yourusername/animal-image-service.git
# cd into the project
cd animal-service
# Run with Docker
docker compose up
# Or run with Maven (requires JDK 19+)
./mvnw spring-boot:run
Access the application at http://localhost:8080
- Fetch and store images of cats, dogs, and bears
- Retrieve the latest stored image for each animal type
- Simple web UI for interaction
- Containerized application with Docker
- H2 in-memory database for storage
- Java 19
- Maven Apache Maven 3.9.9
- Spring Boot 3.2
- Docker (optional)
# clean and build the project
mvn clean install
# just compile if in a hurry
mvn compile
# skip tests
mvn clean install -DskipTests
# build nd make jar
mvn package
# run application
./mvnw spring-boot:run
# run with specific profile
./mvnw spring-boot:run -Dspring.profiles.active=dev
# Run all tests
./mvnw test
# Run specific test class
./mvnw test -Dtest=ImageServiceTest
- Application need to be be running
- Navigate to: http://localhost:8080/h2-console
- Use these settings:
- JDBC URL:
jdbc:h2:mem:animaldb
- Username:
sa
- Password:
- Driver Class:
org.h2.Driver
- JDBC URL:
# build and start services
docker compose up --build
# run in detached mode
docker compose up -d
# view logs
docker compose logs -f
# stop services
docker compose down
POST /api/images/save/{type}?count={count}
type
: Animal type (CAT, DOG, BEAR)count
: Number of images to save (default: 1, max: 10)- Returns: Array of image URLs
GET /api/images/latest/{type}
type
: Animal type (CAT, DOG, BEAR)- Returns: URL of the most recently saved image
- 200: Success
- 404: Image not found
- 500: Server error
src/
├── main/
│ ├── java/
│ │ └── com/challenge/
│ │ ├── config/
│ │ │ └── RestTemplateConfig.java
│ │ ├── controller/
│ │ │ └── ImageController.java
│ │ ├── dto/
│ │ │ ├── CatApiResponse.java
│ │ │ └── DogApiResponse.java
│ │ ├── exception/
│ │ │ ├── GlobalExceptionHandler.java
│ │ │ └── ImageNotFoundException.java
│ │ ├── model/
│ │ │ ├── Animal.java
│ │ │ └── AnimalType.java
│ │ ├── repository/
│ │ │ └── AnimalRepository.java
│ │ ├── service/
│ │ │ └── ImageService.java
│ │ └── ImageServiceApplication.java
│ └── resources/
│ ├── static/
│ │ ├── index.html
│ │ └── js/
│ │ └── main.js
│ └── application.properties
├── test/
│ └── java/
│ └── com/challenge/
│ └── service/
│ └── ImageServiceTest.java
├── Dockerfile
├── docker-compose.yml
├── mvnw
├── mvnw.cmd
└── pom.xml
shows the tree structure of project
tree -I 'target|.git|.mvn|.vscode' --dirsfirst -a