Review Create Design
In this lesson, we'll design the core components needed for creating restaurant reviews in our application.
We'll build a foundation that allows users to submit reviews with text content, ratings, and photo references.
The Review Create Request Domain Object
Let's start by creating a class that represents the data structure for incoming review requests.
The ReviewCreateUpdateRequest class captures all the information needed when a user submits a new review, or wants to update their review.
package com.devtiro.restaurant.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReviewCreateUpdateRequest {
private String content; // The text content of the review
private Integer rating; // Rating from 1-5
private List<String> photoIds;// References to uploaded photos
}The Review Service Interface
The service layer will handle the business logic for creating reviews.
We'll define a ReviewService interface that specifies the contract for review creation:
package com.devtiro.restaurant.services;
import com.devtiro.restaurant.domain.ReviewCreateUpdateRequest;
import com.devtiro.restaurant.domain.entities.Review;
import com.devtiro.restaurant.domain.entities.User;
public interface ReviewService {
Review createReview(User author, String restaurantId, ReviewCreateUpdateRequest review);
}The createReview method takes three parameters:
- The
authorrepresenting the user creating the review - The
restaurantIdidentifying the restaurant being reviewed - The
reviewcontaining the review content and details
Summary
- Created
ReviewCreateUpdateRequestclass to capture review submission data - Used Lombok annotations to reduce boilerplate code in domain objects
- Defined
ReviewServiceinterface withcreateReviewmethod