This project is a RESTful API that implements a basic fleet management system. This API enables fleet management of shipments according to their delivery points.
This project is designed to manage shipments within a logistics system. It includes functionality to handle different types of shipments, such as packages and sacks, and provides features for unloading these shipments at various delivery points. Below are the key concepts used in the project:
- Package: Refers to a single item or good that is being shipped.
- Sack: Refers to a shipment type that consists of more than one item or good. A sack can contain multiple packages.
There are three different delivery points in the system:
- Branch: At branches, only packages can be unloaded. Sacks and packages in sacks cannot be unloaded.
- Distribution Center: At distribution centers, sacks, packages in sacks, and packages that are not assigned to a sack can be unloaded.
- Transfer Center: At transfer centers, only sacks and packages in sacks can be unloaded.
These concepts form the basis of the fleet management system implemented in this project.
- Java 17 : Main programming language
- Spring Boot : Framework for creating RESTful APIs
- Maven : Dependency management
- JUnit 5 : Testing framework
- Mockito : Mocking framework
- PostgreSQL : Database
- Docker : Containerization
- Swagger : API documentation
- GitHub Actions : CI/CD
Field | Type | Description |
---|---|---|
id | Long | Primary Key |
barcode | String | Barcode |
deliveryPoint | Enum (String) | Delivery Point |
state | Enum (String) | Shipment State |
desi | Integer | Desi |
sack | Sack | Sack |
Field | Type | Description |
---|---|---|
id | Long | Primary Key |
barcode | String | Barcode |
deliveryPoint | Enum (String) | Delivery Point |
state | Enum (String) | Shipment State |
packages | List<Package> | Packages |
This project uses GitHub Actions for its continuous integration and continuous delivery (CI/CD) pipeline. The workflow is defined in the .github/workflows/app.yml
file.
The pipeline includes two main jobs:
- Triggered on pushes or pull requests to the main branch.
- Sets up a PostgreSQL database for testing.
- Builds the project using Maven and caches dependencies.
- Archives the resulting JAR artifact if the build is successful.
- Runs only after the build job completes successfully.
- Also sets up a PostgreSQL database for integration testing.
- Executes all tests using Maven.
- Archives the test reports for review.
This project can be easily run using Docker Compose. Follow the steps below:
-
Install Docker and Docker Compose: Make sure Docker and Docker Compose are installed on your system.
-
Starting with Docker Compose: Run the following command in the project's root directory:
docker-compose up
-
Accessing the API: To access the API with a tool like Postman, you can use:
http://localhost:8080/v1/vehicles/{vehiclePlate}/distribute
. -
Stopping Docker Compose: To stop the containers, run the following command:
docker-compose down
If you prefer to run the project without Docker, follow the steps below:
-
Install PostgreSQL: Make sure PostgreSQL is installed on your system.
-
Create a Database: Create a database named
fleet_management_system
. -
Update Database Configuration: Update the database configuration in the
application.properties
file. -
Run the Application: Run the application using the following command:
mvn spring-boot:run
-
Accessing the API: The API will be available at
http://localhost:8080/swagger-ui/index.html#/
. -
Running Tests: Run the tests using the following command:
mvn test
-
Stopping the Application: Stop the application by pressing
Ctrl + C
. -
Stopping PostgreSQL: Stop the PostgreSQL service on your system.
-
Deleting the Database: Delete the
fleet_management_system
database.
- URL:
/api/v1/vehicles/{vehiclePlate}/distribute
- Method: POST
- Description: Distributes a distribution request to a vehicle.
-
Request Body: JSON
{ "route": [ { "deliveryPoint": "BRANCH", "deliveries": [ {"barcode": "P7988000121"}, {"barcode": "P7988000122"}, {"barcode": "P7988000123"}, {"barcode": "P8988000121"}, {"barcode": "C725799"} ] } ] }
-
Response Body: JSON
{ "vehicle": "vehiclePlate", "route": [ { "deliveryPoint": "BRANCH", "deliveries": [ {"barcode": "P7988000121", "state": "UNLOADED"}, {"barcode": "P7988000122", "state": "UNLOADED"}, {"barcode": "P7988000123", "state": "UNLOADED"}, {"barcode": "P8988000121", "state": "LOADED"}, {"barcode": "C725799", "state": "LOADED"} ] } ] }
-
The API documentation is available at http://localhost:8080/swagger-ui/index.html
.