This project is the final assignment for the Create REST APIs with Spring and Java course from Codecademy.
The Dining Review API is a RESTful web service that enables users to submit reviews for restaurants based on allergy-friendly criteria. Users can rate restaurants on a scale from 1 to 5 for peanut, egg, and dairy safety. Admins review and approve or reject these dining reviews. Additionally, the API recalculates and updates restaurant scores based on approved reviews.
- User Reviews: Users submit dining reviews with scores for peanut, egg, and dairy allergies, plus optional commentary.
- Score Aggregation: Restaurants store average scores for each allergy category as well as an overall score, calculated from approved reviews.
- Admin Actions: Admins can view pending reviews and update a review's status (approve or reject).
- Flexible Endpoints: Routes accept optional parameters (e.g., filtering dining reviews by status).
- DTO-based Communication: Both request and response data are managed through DTOs to decouple internal models from the API contract.
- Global Exception Handling: Errors and validation issues are managed centrally for clean and consistent API responses.
id
(Long) - Unique identifiername
(String) - Restaurant nameaddress
(String) - LocationcuisineType
(String) - Type of cuisinepeanutScore
(Double) - Average peanut allergy scoreeggScore
(Double) - Average egg allergy scoredairyScore
(Double) - Average dairy allergy scoreoverallScore
(Double) - Overall average score
id
(Long) - Unique identifierdisplayName
(String) - Unique usernamecity
(String) - City of residencestate
(String) - State of residencezipCode
(Long) - Zip codeinterestedInPeanut
(Boolean) - Interest in peanut allergy ratingsinterestedInEgg
(Boolean) - Interest in egg allergy ratingsinterestedInDairy
(Boolean) - Interest in dairy allergy ratings
id
(Long) - Unique identifiersubmittedBy
(User) - User who submitted the reviewrestaurant
(Restaurant) - Reviewed restaurantpeanutScore
(Double) - Score (1-5) for peanut allergy safetyeggScore
(Double) - Score (1-5) for egg allergy safetydairyScore
(Double) - Score (1-5) for dairy allergy safetycommentary
(String) - Optional commentsstatus
(ReviewStatus): Indicates whether the review is pending, approved or rejected.
- PENDING
- APPROVED
- REJECTED
- POST /users: Create a new user profile.
- GET /users: List of users.
- GET /users/{displayName}: Retrieve user profile(s).
- PUT /users/{displayName}: Update user data (displayName remains immutable).
- POST /restaurants: Creates a new restaurant.
- GET /restaurants: List of restaurants.
- GET /restaurants/{restaurantId}: Details of the given restaurant.
- GET /restaurants/search?zipCode=12345678&peanut=true&egg=true&dairy=true: Search for restaurants by zip code and filter by allergy, if has scores calculated (one or more).
- PUT /restaurants/{restaurantId}/update-scores: Recalculate and update a restaurant’s scores based on approved dining reviews.
- POST /dining-reviews/{userDisplayName}/{restaurantId}: Submit a new dining review.
- PUT /dining-reviews/{id}/update-status/{newStatus}: Update the status of a dining review.
- GET /dining-reviews/{?status}: Retrieve dining reviews, optionally filtered by status (PENDING, APPROVED, REJECTED).
- Java
- Spring Boot
- Spring Data JPA
- H2 Database (for local persistence)
- Lombok (for reducing boilerplate code)
- Global Exception Handling with
@RestControllerAdvice
for consistent error responses
- Clone the repository:
git clone https://github.com/Robson16/diningreview.git
- Navigate to the project directory:
cd diningreview
- Build and run the application:
mvn spring-boot:run
This project is licensed under the MIT License.
Feel free to contribute and enhance this project!