VirtualPetsApp is a backend application built with Spring Boot and MySQL that provides the necessary APIs for the VirtualPetsApp platform. It supports user authentication, role-based authorization, and CRUD operations for managing virtual pets.
- User Authentication: Register, login, and token-based authentication using JWT.
- Role-Based Authorization:
- ROLE_USER: Users can manage their own virtual pets.
- ROLE_ADMIN: Admins have full access to all pets and user data.
- Pet Management: Create, read, update, and delete virtual pets.
- Interactive Environment: Provides endpoints to interact with and customize pets.
- API Documentation: Includes Swagger UI for easy API exploration and testing.
- Java 17
- MySQL
- Maven
- Spring Boot
git clone https://github.com/arnaufata/VirtualPetsApp-Backend.gitModify the application.properties file to match your database and JWT settings:
# Database configuration
spring.datasource.url=jdbc:mysql://localhost:3306/virtual_pets
spring.datasource.username=<your_database_username>
spring.datasource.password=<your_database_password>
# JWT configuration
jwt.secret=<your_jwt_secret>
jwt.validity=86400000- Install dependencies and build the project Navigate to the project folder and build the application:
mvn clean install- Run the application Start the backend application:
mvn spring-boot:runThe application will run on http://localhost:8080.
The application exposes RESTful API endpoints for the following functionalities:
- POST /auth/register: Register a new user.
- POST /auth/login: Login and receive a JWT token.
- POST /pets/create: Create a new pet for the authenticated user.
- GET /pets: Retrieve all pets associated with the authenticated user.
- PUT /pets/update/{id}: Update the details of a specific pet owned by the authenticated user.
- POST /pets/interact/{id}: Perform an action (feed, play, rest) on a pet owned by the authenticated user.
- DELETE /pets/delete/{id}: Delete a pet owned by the authenticated user.
Access the API documentation at:
http://localhost:8080/swagger-ui.htmlVirtualPetsApp-Backend/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com.virtualpets.app/
│ │ │ ├── controller/
│ │ │ ├── model/
│ │ │ ├── repository/
│ │ │ ├── service/
│ │ │ └── config/
│ │ └── resources/
│ │ ├── application.properties
│ │ └── static/
├── pom.xml
└── README.mdcontroller/: Contains the REST controllers for handling HTTP requests.model/: Defines the entities and domain objects.repository/: Interfaces for database operations.service/: Contains the business logic.config/: Configuration classes, including security and JWT setup.
The backend implements role-based authorization:
- User Role (ROLE_USER):
- Access to their own pets for reading, updating, and deleting.
- Admin Role (ROLE_ADMIN):
- Full access to all pets and system data.
You can customize the application by modifying:
- Database configuration in
application.properties. - JWT settings for token validity and secret keys.
- Swagger settings for API documentation.
The project uses the following dependencies:
- Spring Boot: Core framework for the backend.
- Spring Security: For authentication and authorization.
- Spring Data JPA: To interact with the MySQL database.
- JWT: For token-based authentication.
- Swagger: For API documentation.
If you'd like to contribute:
- Fork the repository.
- Create a new branch:
git checkout -b feature/new-feature- Commit your changes:
git commit -m "Description of changes"- Push your branch:
git push origin feature/new-feature- Open a pull request.
This project is licensed under the MIT License.