**This ReadMe file contain all information regardnig this project.
- Java 21 i have used
- Maven
- MySQL database
By default, all new users are created with the USER role. To create an admin user, you need to update the user's role in the database.
- User Authentication: Secure registration and login with JWT tokens
- Movie Management: manage movies (Admin only)
- Review System: Submit, update, and delete movie reviews
- Rating System: Rate movies from 1-5 stars
- Role-Based Access: USER and ADMIN roles with different permissions
- RESTful API: Complete REST API with OpenAPI/Swagger documentation
- Transaction Management: Ensures data integrity with proper rollback on failures
- Backend: Java 21 with Spring Boot 3.5.3
- Persistence: Hibernate (JPA)
- Security: Spring Security with JWT authentication
- API Documentation: Swagger/OpenAPI 3
- Build Tool: Maven
-
Find the User ID:
SELECT id, username, email, role FROM users;
-
Update the Role to ADMIN:
-- Update by user ID UPDATE users SET role = 'ADMIN'
USER {
Long id
String username
String email
String password
Role role
LocalDateTime createdAt
LocalDateTime updatedAt
}
MOVIE {
Long id
String title
String description
String genre
LocalDate releaseDate
Double averageRating
LocalDateTime createdAt
LocalDateTime updatedAt
}
REVIEW {
Long id
String reviewText
Integer rating
LocalDateTime createdAt
LocalDateTime updatedAt
}
ROLE {
Enum name
Set<Permission> permissions
}
PERMISSION {
Enum name
String permission
}
USER writes REVIEW
MOVIE receives REVIEW
USER has ROLE
ROLE grants PERMISSION
### Entity Relationships
- **User** → **Review**: One-to-Many (one user can write multiple reviews)
- **Movie** → **Review**: One-to-Many (one movie can have multiple reviews)
- **User** → **Role**: Many-to-One (many users can have the same role)
- **Role** → **Permission**: Many-to-Many (roles have multiple permissions)
### Design Justification
- **Cascade Rules**: Movie deletion cascades to reviews (orphanRemoval = true)
- **Audit Fields**: All entities have createdAt/updatedAt for tracking
- **Validation**: Review ratings are constrained to 1-5 range
- **Performance**: Movie averageRating is calculated and stored for efficient querying
### 4. Access the Application
- **Swagger UI**: http://localhost:8080/swagger-ui.html
- **API Base URL**: http://localhost:8080/api/
## 📚 API Documentation
### Authentication Endpoints
#### Register User
```http
POST /api/auth/register
Content-Type: application/json
{
"username": "john_doe",
"email": "john@example.com",
"password": "password123"
}
``**Response:**
```json
{
"accessToken": "eyJhbGciOiJIUzI1NiJ9..."
}`
#### Login User
http
POST /api/auth/login
Content-Type: application/json
{
"username": "john_doe",
"password": "password123"
}
Response:
{
"accessToken": "eyJhbGciOiJIUzI1NiJ9..."
}GET /api/movies?page=0&size=10GET /api/movies/{id}POST /api/movies
Authorization: Bearer {jwt_token}
Content-Type: application/json
{
"title": "soley",
"description": "comedy",
"genre": "comedy",
"releaseDate": "2001-03-31"
}PUT /api/movies/{id}
Authorization: Bearer {jwt_token}
Content-Type: application/json
{
"title": "The Matrix Reloaded",
"description": "Updated description",
"genre": "Sci-Fi",
"releaseDate": "2003-05-15"
}
#### Delete Movie (Admin Only)
```http
DELETE /api/movies/{id}
Authorization: Bearer {jwt_token}POST /api/reviews
Authorization: Bearer {jwt_token}
Content-Type: application/json
{
"movieId": 1,
"reviewText": "Amazing movie with groundbreaking special effects!",
"rating": 5
}GET /api/reviews/movie/{movieId}PUT /api/reviews/{reviewId}
Authorization: Bearer {jwt_token}
Content-Type: application/json
{
"movieId": 1,
"reviewText": "Updated review text",
"rating": 4
}DELETE /api/reviews/{reviewId}
Authorization: Bearer {jwt_token}- Include in Headers:
Authorization: Bearer {jwt_token} - Token Expiration: 24 hours (configurable)
- Automatic Validation: All protected endpoints validate tokens
The application supports:
- MySQL:
jdbc:mysql://localhost:3306/moviedb
ResourceNotFoundException: When requested resource doesn't existUserNotFoundException: When user is not foundInvalidCredentialsException: When login credentials are invalidAccessDeniedException: When user lacks required permissionsUserExistsWithUsernameException: When username/email already exists
For questions or support:
- Contact:ankitdhakariya@gmail.com
- contact no-7770833453