Deployed project Swagger URL:
The Car Sharing Service is a web-based platform designed to manage car sharing inventory, rentals, customers, notifications, and payments. This project includes functionalities for user authentication, car inventory management, rental operations, and payment processing using Stripe. Additionally, it features a notification service through Telegram to keep administrators informed about important events such as new rentals, overdue rentals, and successful payments.
This project utilizes a variety of technologies and tools to ensure a robust, scalable, and maintainable car sharing service. Below is an overview of the main technologies and tools used:
- Java: The primary programming language used for the backend services.
- Spring Boot: A powerful framework for building production-ready applications quickly, providing features such as dependency injection, web frameworks, data access, and security.
- Spring Security: Used to handle authentication and authorization.
- Spring Data JPA: Simplifies data access and management using Java Persistence Api.
- Liquibase: An open-source library for tracking, managing, and applying database schema changes.
- Stripe Api: User for handling payment processing securely.
- MySql: A widely-used open-source relational database system, chosen for its reliability, ease of use, and support for complex queries and transactions.
- JUnit: A widely used testing framework for Java applications.
- Mockito: A mocking framework for unit test in Java.
- Spring Boot Test: Provide utilities for testing Spring Boot applications.
- GitHub Actions: Provides CI capabilities to automate building and testing the application.
- Docker: Used to create, deploy, and run application in containers.
- Docker Compose: Used for defining and running multi-container Docker application.
- Swagger/OpenApi: Tools for generating and visualizing API documentation, making it easier to understand and use the API endpoints.
- Checkstyle: A development tool to help ensure that Java code adheres a coding standard.
- Maven: A build automation tool used primary for Java projects. It simplifies the build process and dependency management.
- Telegram API: Used for sending notification about rentals and payments to administrator via a Telegram bot.
- Trello: A task management tool used for tracking project progress and managing tasks.
- IntelliJIdea: An integrated development environment for Java development.
- Postman: A tool for testing APIs by sending request and receiving response.
- dotenv (.env): A module that loads environment variables from a '.env' file into the application, ensuring sensitive information is kept secure and not pushed to version control.
-
Registration: Users can register on the platform by providing their email, first name, last name, and password.
POST: /auth/register
-
Authentication: Secure login functionality using JWT tokens to manage sessions.Users can log in using their credentials (email and password).
POST: /auth/login
-
User Profiles: Users can view and updated their profile information.
GET: /user/me
PUT: /users/me
-
Role Management: Admins can assign roles (ADMIN or USER) to users, controlling access to certain features.
- Add Cars: Admins can add new cars to the inventory, specifying details such as model, brand, type, inventory count, and daily fee.
POST: /cars
- Update Cars: Admins can update car details and manage the inventory count.
PUT: /cars/{carId}
- Delete Cars: Admins can remove cars from the inventory.
DELETE: /cars/{carId}
- View Cars: All users, including unauthenticated users, can view the list of available cars and detailed information about each car.
GET: /cars
GET: /cars/{carId}
- Create Rental: Users can rent cars, decreasing the inventory count by 1.
POST: /rentals
- View Rental: Users can view their active and past rentals. Admins can view rentals for all users.
GET: /rentals
- Return Rental: Users can return rented cars, which increase the inventory count by 1.
POST: /return/{rentalId}
- Return Filtering: Users can filter rentals by status (active or returned) and admins can filter rentals by user ID.
GET: /rentals/?user_id=...&is_active=...
- Create Payment Sessions: Users can create payment sessions for their rentals using the Stripe API. The system calculates the total price based on the rental duration.
POST: /payments
- Payment Status: Users can check the status of their payments (PENDING or PAID).
GET: /payments/{user_id}
- Payment Types: Supports different payment types, including regular payments for rentals and fines for overdue returns.
- Payment Confirmation: Users are redirected to appropriate endpoints upon successful or canceled payments.
GET: /payments/success
GET: /payments/cancel
- Rental Notifications: Notifications about new rentals are sent to administrators via Telegram.
- Overdue Rentals: Daily notifications are sent to administrators for overdue rentals.
- Payment Notifications: Notifications for successful payments are sent to administrators.
- Health Check: A health check endpoint to monitor the status of the application.
- API Documentation: Integrated Swagger/OpenAPI documentation for easy exploration and testing of API endpoints.
- Security: Secure handling of sensitive data using environment variables and best practices in security.
- Java Development Kit (JDK 21): Ensure that JDK is installed and the JAVA_HOME environment variable is set.
- Maven: Install Maven for building the project.
- MySQL: Install MySQL and create a database for the project.
- Docker: Ensure Docker and Docker Compose are installed for containerization
-
Clone the Repository
git clone https://github.com/jv-feb24-team3/car-sharing-service.git cd car-sharing-service
-
Set up Environments Variables
- Create a .env file in the root directory of the project.
- Add the necessary environment variables. Use the provided .env.sample as a template.
Example .env file:
#MySQL Database Configuration: MYSQLDB_DATABASE=test MYSQLDB_USERNAME=your_user_name MYSQLDB_PASSWORD=_your_password MYSQLDB_ROOT_PASSWORD=your_password MYSQLDB_LOCAL_PORT=3308 MYSQLDB_PORT=3306 # Spring Boot Configuration SPRING_LOCAL_PORT=8082 SPRING_DOCKER_PORT=8080 # Debug Port DEBUG_PORT=5006 # Telegram Bot Configuration BOT_USERNAME=your_telegram_user_name BOT_TOKEN=your_telegram_bot_token TELEGRAM_ADMIN_CHAT_ID=your_chatId # Stripe API Configuration STRIPE_API_KEY=your_key STRIPE_WEBHOOK_SECRET=your_webhook_secret # JWT Configuration JWT_SECRET=your_secret JWT_EXPIRATION=your_expiration # Swagger Configuration OPENAPI_MODULE_NAME=your_api_module_name OPENAPI_API_VERSION=your_api_version
-
Build the Project
mvn clean install
-
Run the Application
- Using Docker Compose
docker-compose up --build
- Using Maven
mvn spring-boot:run
-
Access the Application
- The application should now be running on http://localhost:8082.
- You can access the Swagger API documentation at http://localhost:8082/swagger-ui.html.
To run the tests, use the following Maven command:
mvn test
During the development of the Car Sharing Service, several challenges were encountered. Here are some of the key challenges and the solutions implemented to overcome them:
-
Challenge: Implementing a secure authentication system that handles user registration, login, and role-based access control while ensuring sensitive user data is protected.
Solution:
- JWT Tokens: We used JWT (JSON Web Tokens) for secure authentication and session management. JWT allows for stateless authentication, making it scalable and efficient.
- Spring Security: Integrated Spring Security to handle authentication and authorization, ensuring that only authorized users can access certain endpoints.
- Password Encryption: Utilized strong hashing algorithms (e.g., BCrypt) to store passwords securely, ensuring user credentials are protected.
-
Challenge: Managing and applying database schema changes consistently across different environments.
Solution:
- Liquibase: Integrated Liquibase for database migrations, allowing us to track, version, and deploy database schema changes systematically. This ensures that all environments (development, testing, production) are in sync with the latest database structure.
-
Challenge: Integrating with Stripe API to handle payments securely and efficiently.
Solution:
- Stripe API: Used Stripe API for creating payment sessions, handling transactions, and managing payment statuses.
- Payment Status Handling: Implemented endpoints to handle payment success and cancellation, ensuring users are informed of the payment status and can take appropriate actions.
-
Challenge: Implementing a real-time notification system to inform administrators about new rentals, overdue rentals, and successful payments.
Solution:
- Telegram API: Integrated with Telegram API to send real-time notifications to administrators. A Telegram bot was set up to handle the notifications.
-
Challenge: Ensuring the application is easy to deploy and run in different environments.
Solution:
- Docker: Containerized the application using Docker, allowing it to run consistently across different environments.
- Docker Compose: Used Docker Compose to manage multi-container setups, making it easy to set up the application along with its dependencies (e.g., MySQL) with a single command.
-
Challenge: Providing clear and comprehensive API documentation for developers and users to interact with the service.
Solution: Swagger/OpenAPI: Integrated Swagger for API documentation, providing an interactive interface for exploring and testing API endpoints. This improves developer experience and ensures clarity in how the API can be used.