A beginner-friendly project featuring a simple 'Guess The Number' game for practice. The application is built using Spring Boot, with Spring Data JPA and MySQL for data persistence. It also includes Spring Security with Basic Authentication, Swagger for API documentation.
This project includes Swagger UI for easy API testing and documentation. Once the application is running, you can access the Swagger UI at:
http://localhost:8080/swagger-ui/
Clone the repository:
git clone https://github.com/poshankumarsahu/Guess-The-Number-Game-with-JPA.git
Open the project in Spring Tool Suite (STS):
Launch STS.
Go to File -> Import -> Maven -> Existing Maven Projects.
Select the cloned project directory and click Finish.
Configure MySQL Database:
Ensure MySQL is running.
Create a new database:
CREATE DATABASE your_database_name;
In the src/main/resources/application.properties file, update the following database properties with your own values:
spring.datasource.url=jdbc:mysql://localhost:3306/your_database_name
spring.datasource.username=your_mysql_username
spring.datasource.password=your_mysql_password
Build and Run the Project:
Right-click the project in STS and select Run As -> Spring Boot App.
Access the Application:
Open a browser and go to http://localhost:8080/ to access the application.
API Documentation with Swagger:
The Swagger UI is available at:
http://localhost:8080/swagger-ui.html
The API documentation can be accessed at:
http://localhost:8080/v3/api-docs
Returns a welcome message.
GET /
Parameter | Type | Description |
---|---|---|
None |
NA |
NA |
GET /game/{num}
Submit a guess for the game. Requires authentication.
Parameter | Type | Description |
---|---|---|
num |
integer |
Required. The guessed number (0 to 100) |
GET /my-scores
Retrieve the authenticated user's game history. Requires authentication.
Parameter | Type | Description |
---|---|---|
None |
NA |
NA |
GET /user
Returns a welcome message for authenticated users.
Parameter | Type | Description |
---|---|---|
None |
NA |
NA |
POST /admin/add
Add a new user to the system. Requires admin authentication.
Parameter | Type | Description |
---|---|---|
User |
object |
Required. User details in JSON format |
GET /admin
Returns a welcome message for Admin.
Parameter | Type | Description |
---|---|---|
None |
NA |
NA |
This project uses Spring Boot, Spring Data JPA, MySQL, Spring Security, Swagger, and Exception Handling.
It includes Controllers, Services, DTOs, Repositories, Exception, Configuration and Entities
It's for beginners looking to strengthen their skills in Spring Boot with database integration and security.