Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

**This ReadMe file contain all information regardnig this project.

🚀 Setup Instruction

Prerequisites

  • Java 21 i have used
  • Maven
  • MySQL database

Admin User Creation

Creating an Admin User

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.

Movie Review System

  • 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

🛠️ Technology Stack

  • 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

Method 1: Direct Database Update (Recommended)

  1. Find the User ID:

    SELECT id, username, email, role FROM users;
  2. Update the Role to ADMIN:

    -- Update by user ID
    UPDATE users 
    SET role = 'ADMIN' 
    
    
    

Entity-Relationship Diagram

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..."
}

Movie Endpoints

Get All Movies (Public)

GET /api/movies?page=0&size=10

Get Movie by ID (Public)

GET /api/movies/{id}

Create Movie (Admin Only)

POST /api/movies
Authorization: Bearer {jwt_token}
Content-Type: application/json

{
  "title": "soley",
  "description": "comedy",
  "genre": "comedy",
  "releaseDate": "2001-03-31"
}

Update Movie (Admin Only)

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}

Review Endpoints

Create Review (Authenticated Users)

POST /api/reviews
Authorization: Bearer {jwt_token}
Content-Type: application/json

{
  "movieId": 1,
  "reviewText": "Amazing movie with groundbreaking special effects!",
  "rating": 5
}

Get Reviews for Movie (Public)

GET /api/reviews/movie/{movieId}

Update Review (Owner Only)

PUT /api/reviews/{reviewId}
Authorization: Bearer {jwt_token}
Content-Type: application/json

{
  "movieId": 1,
  "reviewText": "Updated review text",
  "rating": 4
}

Delete Review (Owner or Admin)

DELETE /api/reviews/{reviewId}
Authorization: Bearer {jwt_token}

JWT Token Usage

  1. Include in Headers: Authorization: Bearer {jwt_token}
  2. Token Expiration: 24 hours (configurable)
  3. Automatic Validation: All protected endpoints validate tokens

Database Configuration

The application supports:

  • MySQL: jdbc:mysql://localhost:3306/moviedb

Custom Exceptions

  • ResourceNotFoundException: When requested resource doesn't exist
  • UserNotFoundException: When user is not found
  • InvalidCredentialsException: When login credentials are invalid
  • AccessDeniedException: When user lacks required permissions
  • UserExistsWithUsernameException: When username/email already exists

📞 Support

For questions or support:

About

movie review system

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages