A comprehensive RESTful API built with Spring Boot for managing logistics and delivery operations. This system handles user management, driver operations, order processing, and warehouse management with role-based authentication and authorization.
- User Management: Registration, authentication, and role-based access control
- Driver Management: Driver registration, profile management, and assignment
- Order Management: Order creation, tracking, status updates, and lifecycle management
- Warehouse Operations: Warehouse management and inventory tracking
- Authentication & Security: JWT-based authentication with role-based authorization
- CRUD operations for all entities
- JWT token-based authentication
- Role-based access control (Admin, Customer, Driver)
- Global exception handling
- Input validation
- CORS configuration for cross-origin requests
- MySQL database integration with JPA/Hibernate
- Java: 17+
- Spring Boot: 3.x
- Spring Security: JWT Authentication
- Spring Data JPA: Database operations
- MySQL: Primary database
- Maven: Dependency management
- Jakarta Validation: Input validation
- JDK 17 or later
- Maven 3.6+
- MySQL Server 8.0+
The application connects to a MySQL database. Update the configuration in src/main/resources/application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/your_database_name
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# JPA/Hibernate properties
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
# JWT Configuration
app.jwt.expiration-in-ms=3600000
# Server Configuration
server.port=8023-
Clone the repository
git clone <repository-url> cd LDMS_Backend
-
Build the project
./mvnw clean install
-
Run the application
./mvnw spring-boot:run
-
Build the project
mvn clean install
-
Run the application
mvn spring-boot:run
The application will start on port 8023 (http://localhost:8023).
POST /api/auth/login - User login
POST /api/auth/register - User registration
POST /api/auth/refresh - Refresh JWT token
GET /api/users - Get all users (Admin only)
GET /api/users/{id} - Get user by ID
PUT /api/users/{id} - Update user
DELETE /api/users/{id} - Delete user (Admin only)
GET /api/drivers - Get all drivers
GET /api/drivers/{id} - Get driver by ID
POST /api/drivers - Create new driver
PUT /api/drivers/{id} - Update driver
DELETE /api/drivers/{id} - Delete driver
GET /api/orders - Get all orders
GET /api/orders/{id} - Get order by ID
POST /api/orders - Create new order
PUT /api/orders/{id} - Update order
DELETE /api/orders/{id} - Delete order
PUT /api/orders/{id}/status - Update order status
GET /api/warehouses - Get all warehouses
GET /api/warehouses/{id} - Get warehouse by ID
POST /api/warehouses - Create new warehouse
PUT /api/warehouses/{id} - Update warehouse
DELETE /api/warehouses/{id} - Delete warehouse
GET /api/test/public - Public endpoint (no authentication required)
GET /api/test/protected - Protected endpoint (authentication required)
The API uses JWT (JSON Web Token) for authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
- ADMIN: Full access to all endpoints
- CUSTOMER: Access to order-related operations
- DRIVER: Access to driver-specific operations
{
"username": "[email protected]",
"password": "password123"
}{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"type": "Bearer",
"username": "[email protected]",
"roles": ["ROLE_USER"]
}{
"id": 1,
"orderNumber": "ORD-001",
"customerId": 1,
"driverId": 2,
"status": "PENDING",
"orderStage": "WAREHOUSE",
"createdDate": "2025-01-20T10:30:00",
"deliveryAddress": "123 Main St, City, State",
"totalAmount": 99.99
}The API includes comprehensive error handling:
- 400 Bad Request: Invalid input data
- 401 Unauthorized: Authentication required
- 403 Forbidden: Insufficient permissions
- 404 Not Found: Resource not found
- 500 Internal Server Error: Server-side errors
{
"timestamp": "2025-01-20T10:30:00",
"status": 404,
"error": "Not Found",
"message": "Order not found with id: 1",
"path": "/api/orders/1"
}Input validation is implemented using Jakarta Validation:
- Email format validation
- Required field validation
- String length constraints
- Numeric range validation
src/main/java/com/msd/spring_boot_rest_api/
βββ SpringBootRestApiApplication.java # Main application class
βββ config/
β βββ CorsConfig.java # CORS configuration
βββ controller/
β βββ AuthController.java # Authentication endpoints
β βββ DriverController.java # Driver management
β βββ OrderController.java # Order management
β βββ TestController.java # Test endpoints
β βββ UserController.java # User management
β βββ WarehouseController.java # Warehouse management
βββ dto/
β βββ LoginRequest.java # Login request DTO
β βββ LoginResponse.java # Login response DTO
βββ exception/
β βββ GlobalExceptionHandler.java # Global exception handling
β βββ ResourceNotFoundException.java # Custom exceptions
βββ model/
β βββ Admin.java # Admin entity
β βββ Customer.java # Customer entity
β βββ Driver.java # Driver entity
β βββ Order.java # Order entity
β βββ OrderedItems.java # Order items entity
β βββ OrderStage.java # Order stage enum
β βββ OrderStatus.java # Order status enum
β βββ Role.java # Role enum
β βββ User.java # User entity
βββ repository/
β βββ AdminRepository.java # Admin data access
β βββ DriverRepository.java # Driver data access
β βββ OrderRepository.java # Order data access
β βββ UserRepository.java # User data access
βββ security/
β βββ JwtAuthenticationFilter.java # JWT filter
β βββ JwtTokenProvider.java # JWT utility
β βββ SecurityConfig.java # Security configuration
βββ service/
βββ JwtUserDetails.java # JWT user details
βββ OrderService.java # Order business logic
Run the test suite:
./mvnw test- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Environment Variables: Use environment variables for sensitive configuration
- Database: Configure production database settings
- Security: Update JWT secret and expiration times
- Logging: Configure appropriate logging levels
- HTTPS: Enable SSL/TLS in production
Create a Dockerfile:
FROM openjdk:17-jdk-slim
VOLUME /tmp
COPY target/*.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]Build and run:
docker build -t ldms-backend .
docker run -p 8023:8023 ldms-backend