Skip to content

mgrellet/dino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dinosaurs Application

Spring Boot Logo

Overview

This is a Spring Boot application that provides a CRUD implementation of Dinosaurs The application is built with the following stack:

  • Spring Boot for the backend
  • JPA/Hibernate for ORM and database interaction
  • H2DB for the database on memory
  • Lombok to reduce boilerplate code
  • Spring Data JPA for repository management
  • RabbitMQ for messaging

Features

  • Create, read, update and retrieve dinosaurs
  • Scheduler to update dinasour status
  • Messaging with RabbitMQ
  • Unit tests

Table of Contents

Getting Started

To get started with the application, follow these steps:

Prerequisites

Make sure you have the following installed:

  • Java 17
  • Maven 3.x
  • Git
  • Docker
  • Docker Compose

Clone the Repository

git clone https://github.com/mgrellet/dino.git
cd dino

Build the Application

mvn clean package

Running the Application

You can run the application by executing:

docker compose up

This command will start the sprinboot application and the RabbitMQ container.

API Endpoints

Below are the available API endpoints for managing dinosaurs:

HTTP Method Endpoint Description
POST /dinosaur Create a new dinosaur
GET /dinosaur Gets all dinosaurs
GET /dinosaur/{id} Gets dinosaur by id
PUT /dinosaur/{id} Update dinosaur
DELETE /dinosaur/{id} Delete dinosaur

Sample API Request

Create a new Dinosaur

POST /dinosaur
Content-Type: application/json

{
    "name": "Tyrannosaurus Rex",
    "species": "Theropod",
    "discoveryDate": "1902-01-01T23:59:59",
    "extinctionDate": "2023-12-31T23:59:59",
    "status": "ALIVE"
}

Response:

{
  "message": "success",
  "status": 201,
  "data": {
    "id": 1,
    "name": "Tyrannosaurus Rex",
    "species": "Theropod",
    "discoveryDate": "1902-01-01T23:59:59",
    "extinctionDate": "2023-12-31T23:59:59",
    "status": "ALIVE"
  }
}

Update a Dinosaur

UPDATE /dinosaur/{id}
Content-Type: application/json

{
    "name": "T-Rex",
    "species": "Theropod",
    "discoveryDate": "1902-01-01T23:59:59",
    "extinctionDate": "2023-12-31T23:59:59",
    "status": "ALIVE"
}

Response:

{
  "message": "success",
  "status": 200,
  "data": {
    "id": 1,
    "name": "T-Rex",
    "species": "Theropod",
    "discoveryDate": "1902-01-01T23:59:59",
    "extinctionDate": "2023-12-31T23:59:59",
    "status": "ALIVE"
  }
}

Swagger documentation

You can access the Swagger documentation at: http://localhost:8080/swagger-ui.html

Technologies

  • Java 17
  • Spring Boot
  • Spring Data JPA
  • Hibernate
  • H2DB
  • Lombok
  • RabbitMQ

Scheduler

The application has a scheduler that updates the status of dinosaurs every 10 minutes checking the extintion date.

  @Scheduled(fixedRate = 600000)

Messaging

Each time that a dinosaur is updated, the application sends a message to a RabbitMQ queue with the new status and the timestamp of the update to be logged.

{
  "dinosaurId": 1,
  "newStatus": "ENDANGERED",
  "timestamp": "2023-10-01T09:00:00"
}

NOTE: The producer and consumer was built in the same springboot application

Running Tests

To run the unit and integration tests:

mvn test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published