https://github.com/brunoliratm/Ludus-GameStore-API
Ludus is not just a game store, it's a gateway to endless adventures and thrilling experiences. Whether you're a casual gamer or a hardcore enthusiast, Ludus has something for everyone.
https://github.com/brunoliratm/Ludus-GameStore-API
jdbc servlet spring thymeleaf
Last synced: 11 months ago
JSON representation
Ludus is not just a game store, it's a gateway to endless adventures and thrilling experiences. Whether you're a casual gamer or a hardcore enthusiast, Ludus has something for everyone.
- Host: GitHub
- URL: https://github.com/brunoliratm/Ludus-GameStore-API
- Owner: brunoliratm
- License: mit
- Created: 2024-03-29T02:19:29.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-11T18:50:02.000Z (over 1 year ago)
- Last Synced: 2024-11-30T17:55:21.821Z (over 1 year ago)
- Topics: jdbc, servlet, spring, thymeleaf
- Language: CSS
- Homepage:
- Size: 17.9 MB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Ludus Game Store API
[](https://spring.io/projects/spring-boot)
[](https://www.oracle.com/java/)
[](https://junit.org/junit5/)
[](https://site.mockito.org/)
[](https://www.docker.com/)
[](LICENSE)
[](http://localhost:8080/swagger-ui.html)
A comprehensive RESTful API for managing a modern gaming store platform with secure user authentication, robust game catalog, and seamless purchase processing.
## ๐ Table of Contents
- [๐ Overview](#-overview)
- [โจ Key Features](#-key-features)
- [๐ ๏ธ Tech Stack](#๏ธ-tech-stack)
- [๐ Getting Started](#-getting-started)
- [๐ API Endpoints](#-api-endpoints)
- [๐ Security Implementation](#-security-implementation)
- [๐ Data Models](#-data-models)
- [๐งช Testing Strategy](#-testing-strategy)
- [๐ณ Docker Support](#-docker-support)
- [๐ฅ Credits](#-credits)
- [๐ค Contributing](#-contributing)
- [๐ License](#-license)
## ๐ Overview
Ludus Game Store API is a robust Spring Boot application that provides a complete backend solution for online game stores. The API enables developers to manage game catalogs, handle user authentication and authorization, process purchases with various payment methods, and implement filtering capabilities for an enhanced user experience.
## โจ Key Features
- **Game Management**
- Create, read, update, and delete games
- Filter games by genre, platform, release year, and name
- Comprehensive validation of game attributes
- **User Authentication & Authorization**
- JWT-based authentication
- Role-based access control
- Secure password handling
- **Purchase Processing**
- Multiple payment methods (Credit Card, Debit Card, PIX, PayPal, Boleto)
- Purchase history tracking
- User-specific purchase reports
- **Robust Error Handling**
- Customized exception messages
- Internationalization support
- Validation error reporting
- **Pagination & Sorting**
- Efficient data retrieval with pagination
- Dynamic response format with metadata
## ๐ ๏ธ Tech Stack
- **Backend Framework**: Spring Boot
- **Security**: Spring Security with JWT
- **Database Access**: Spring Data JPA
- **API Documentation**: Swagger/OpenAPI
- **Validation**: Jakarta Bean Validation
- **Data Modeling**: Lombok
- **Testing**: JUnit 5, Mockito
- **Containerization**: Docker
- **Dependency Management**: Maven
## ๐ Getting Started
### Prerequisites
- Java 21 or higher
- Maven 3.6+
- Your preferred IDE (IntelliJ IDEA, Eclipse, VS Code)
- PostgreSQL Server or compatible database
- Docker (optional, for containerized deployment)
### Installation
1. Clone the repository:
```bash
git clone https://github.com/brunoliratm/Ludus-GameStore-Api.git
cd Ludus-GameStore-Api
```
2. Configure your database settings in `application.properties`
```properties
spring.datasource.url=jdbc:postgresql://localhost:5432/ludus_db
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=org.postgresql.Driver
```
3. Build the project:
```bash
mvn clean install
```
4. Run the application:
```bash
mvn spring-boot:run
```
5. Access the API at `http://localhost:8080/`
6. Explore API documentation at `http://localhost:8080/swagger-ui.html`
### Docker Deployment
1. Build the Docker image:
```bash
docker build -t ludus-gamestore-api .
```
2. Run the container with basic configuration:
```bash
docker run -p 8080:8080 -e SPRING_PROFILES_ACTIVE=prod ludus-gamestore-api
```
3. Access the API at `http://localhost:8080/` and Swagger documentation at `http://localhost:8080/swagger-ui.html`
## ๐ API Endpoints
### Games API
| Method | Endpoint | Description | Authentication Required |
|--------|----------|-------------|------------------------|
| GET | `/api/v1/games` | List all games with optional filtering by genre and name | No |
| GET | `/api/v1/games/{id}` | Get game details by ID | No |
| POST | `/api/v1/games` | Create a new game | Yes (ADMIN) |
| PUT | `/api/v1/games/{id}` | Update an existing game | Yes (ADMIN) |
| DELETE | `/api/v1/games/{id}` | Delete a game | Yes (ADMIN) |
### Users API
| Method | Endpoint | Description | Authentication Required |
|--------|----------|-------------|------------------------|
| GET | `/api/v1/users` | List all users with optional name filtering | Yes (ADMIN) |
| GET | `/api/v1/users/{id}` | Get user profile by ID | Yes (ADMIN) |
| POST | `/api/v1/users` | Create a new user | Yes (ADMIN) |
| PUT | `/api/v1/users/{id}` | Update user information | Yes (ADMIN) |
| DELETE | `/api/v1/users/{id}` | Delete user account (soft delete) | Yes (ADMIN) |
### Authentication API
| Method | Endpoint | Description | Authentication Required |
|--------|----------|-------------|------------------------|
| POST | `/api/v1/auth/login` | Authenticate user and get JWT token | No |
| POST | `/api/v1/auth/register` | Register a new user and generate JWT token | No |
### Purchases API
| Method | Endpoint | Description | Authentication Required |
|--------|----------|-------------|------------------------|
| GET | `/api/v1/purchases` | List all purchases with optional filtering | Yes (ADMIN) |
| GET | `/api/v1/purchases/{id}` | Get purchase details by ID | Yes (ADMIN) |
| POST | `/api/v1/purchases` | Create a new purchase | Yes (ADMIN) |
| GET | `/api/v1/purchases/user/{userId}` | Get purchases by user ID | Yes (ADMIN) |
## ๐ Security Implementation
The API uses JWT (JSON Web Token) for authentication. The `TokenService` generates and validates tokens, while Spring Security handles authorization based on user roles. To access protected endpoints, include a valid JWT token in the Authorization header:
```
Authorization: Bearer
```
## ๐ Data Models
```mermaid
classDiagram
class GameModel {
+Long id
+String name
+GameGenre genre
+int releaseYear
+GamePlatform platform
+BigDecimal price
}
class UserModel {
+Long id
+boolean active
+String email
+String name
+String password
+UserRole role
+Collection~GrantedAuthority~ getAuthorities()
+String getPassword()
+String getUsername()
+boolean isAccountNonExpired()
+boolean isAccountNonLocked()
+boolean isCredentialsNonExpired()
+boolean isEnabled()
}
class PurchaseModel {
+Long id
+LocalDate purchaseDate
+BigDecimal price
+PaymentMethod paymentMethod
+GameModel game
+UserModel user
}
class GameGenre {
<>
ACTION
ADVENTURE
FIGHTING
HORROR
MMORPG
RACING
RPG
SHOOTER
SIMULATION
SPORTS
STRATEGY
SURVIVAL
OTHER
}
class GamePlatform {
<>
PC
PLAYSTATION
XBOX
NINTENDO
MOBILE
OTHER
}
class PaymentMethod {
<>
CREDIT_CARD
DEBIT_CARD
PIX
PAYPAL
BOLETO
OTHER
}
class UserRole {
<>
USER
ADMIN
}
PurchaseModel "many" --> "1" GameModel : has
PurchaseModel "many" --> "1" UserModel : made by
GameModel -- GameGenre : has
GameModel -- GamePlatform : runs on
PurchaseModel -- PaymentMethod : uses
UserModel -- UserRole : has
```
## ๐งช Testing Strategy
The project uses a comprehensive testing approach to ensure code quality and reliability:
- **Unit Testing**: JUnit 5 for testing individual components in isolation
- **Mocking**: Mockito for creating mock objects to simulate dependencies
- **Test Coverage**: Extensive test coverage across all services and controllers
- **Integration Tests**: Testing the interaction between different components
Key test classes:
- `GameServiceTest`: Tests for game operations including validation and filtering
- `UserServiceTest`: Tests for user management operations
- `PurchaseServiceTest`: Tests for purchase process and order management
- `AuthServiceTest`: Tests for authentication and token generation/validation
To run the tests:
```bash
mvn test
```
## ๐ณ Docker Support
The application includes Docker support for easy deployment in any environment. The Dockerfile sets up the appropriate Java runtime environment and configures the application for production use.
### Dockerfile Features
- Multi-stage build for optimized image size
- Maven build in the first stage with Eclipse Temurin 21
- Slim JRE-based runtime image in the second stage
- Proper layer caching for faster builds
- Exposes port 8080 for the application
- Health check to verify application is running properly
### Environment Variables
The application supports configuration through environment variables, which can be passed when running the Docker container. Spring Boot will automatically map these environment variables to application properties.
Common environment variables you can configure:
- `SPRING_DATASOURCE_URL`: Database URL
- `SPRING_DATASOURCE_USERNAME`: Database username
- `SPRING_DATASOURCE_PASSWORD`: Database password
- `JWT_SECRET`: Secret key used for JWT token signing
- `API_BASEURL`: Base URL for the API (defaults to http://localhost:8080/api/v1)
- `ADMIN_DEFAULT_EMAIL`: Email for the default admin user (default: adminlgs@email.com)
- `ADMIN_DEFAULT_PASSWORD`: Password for the default admin user (default: puzzle001@)
- `SPRING_PROFILES_ACTIVE`: Set to your desired Spring profile (default, dev, prod)
- `SERVER_PORT`: The port on which the application runs (default: 8080)
When running in a Docker container, use `host.docker.internal` to connect to a database running on your host machine, for example:
```bash
--add-host=host.docker.internal:host-gateway \
-e SPRING_DATASOURCE_URL=jdbc:postgresql://host.docker.internal:5432/ludus \
```
Example of running with custom environment variables:
```bash
docker run -p 8080:8080 \
-e SPRING_DATASOURCE_URL=jdbc:postgresql://127.0.0.1:5432/ludus \
-e SPRING_DATASOURCE_USERNAME=postgres \
-e SPRING_DATASOURCE_PASSWORD=password \
-e JWT_SECRET=your_secure_jwt_secret \
-e ADMIN_DEFAULT_EMAIL=admin@ludus.com \
-e ADMIN_DEFAULT_PASSWORD=secure_admin_password \
-e SPRING_PROFILES_ACTIVE=prod \
-e API_BASEURL=http://localhost:8080/api/v1 \
ludus-gamestore-api
```
## ๐ฅ Credits
| 
BrunoMagno
| 
PauloAraujo
|
| --- | --- |
## ๐ค Contributing
We welcome contributions from the community! To contribute:
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
Please make sure your code follows the project's coding standards and includes appropriate tests.
## ๐ License
This project is licensed under the MIT License.