A Spring Boot application for a car sharing service.
- User authentication with JWT
- User registration and profile management
- Role-based access control (MANAGER and CUSTOMER roles)
- POST /register: Register a new user
- POST /login: Authenticate and get a JWT token
- GET /users/me: Get the current user's profile
- PUT /users/me: Update the current user's profile
- PATCH /users/me: Partially update the current user's profile
- PUT /users/{id}/role: Update a user's role (requires MANAGER role)
- POST /cars: Add a new car
- GET /cars: Get a list of all cars
- GET /cars/{id}: Get detailed information about a specific car
- PUT /cars/{id}: Update a car's information
- PATCH /cars/{id}: Partially update a car's information
- DELETE /cars/{id}: Delete a car
- POST /rentals: Add a new rental (decreases car inventory by 1)
- GET /rentals/?user_id=...&is_active=...: Get rentals by user ID and active status
- GET /rentals/{id}: Get detailed information about a specific rental
- POST /rentals/{id}/return: Return a rental (sets actual return date and increases car inventory by 1)
A Postman collection and environment are available in the postman directory to help you test the
API:
postman/CarSharing.postman_collection.json: Collection of API requestspostman/CarSharing.postman_environment.json: Environment variablespostman/README.md: Instructions for using the Postman collection
See the Postman README for detailed instructions on how to import and use the collection.
- Java 21
- Maven
- MySQL
- Clone the repository
- Configure the database connection in
application-dev.properties - Run the application:
mvn spring-boot:runThe API will be available at http://localhost:8080
The API uses JWT (JSON Web Token) for authentication. To access protected endpoints:
- Register a user or login to get a token
- Include the token in the Authorization header of subsequent requests:
Authorization: Bearer <your_token>
dev: Development environment (default)prod: Production environment
To run with a specific profile:
mvn spring-boot:run -Dspring.profiles.active=prod