...

/

Solution: Book Review System

Solution: Book Review System

Here’s the solution to the book review system challenge.

Solution

Let’s discuss the solution for implementing a book review system.

Create the User class

First, we create the User class in the com.smartdiscover.model package.

Press + to interact
package com.smartdiscover.model;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.core.mapping.id.GeneratedValue;
import org.springframework.data.couchbase.core.mapping.id.GenerationStrategy;
@Data
@Document
public class User {
@Id
@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
private String id;
private String firstName;
private String lastName;
}

Code explanation:

  • Lines 9–11: We add annotations like @Data and @Document to transform a class into a Couchbase document.

  • Lines 13 and 14: We add the id identifier with a unique generation strategy.

  • Lines 17 and 19: We added the firstName and lastName properties.

Create the BookReview class

Then, we create the BookReview class in the com.smartdiscover.model package.

Press + to interact
package com.smartdiscover.model;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.core.mapping.id.GeneratedValue;
import org.springframework.data.couchbase.core.mapping.id.GenerationStrategy;
@Data
@Document
public class BookReview {
@Id
@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
private String id;
private User user;
private Book book;
private int rating;
private String review;
}

Code explanation:

  • Lines 9–11: ...