Solution: Book Review System
Here’s the solution to the book review system challenge.
We'll cover the following...
We'll cover the following...
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.
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@Documentpublic 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
@Dataand@Documentto transform a class into a Couchbase document. -
Lines 13 and 14: We add the
ididentifier with a unique generation strategy. -
Lines 17 and 19: We added the
firstNameandlastNameproperties.
Create the BookReview class
Then, we create the BookReview class in the com.smartdiscover.model package.
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@Documentpublic 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: We add annotations like
@Dataand@Documentto transform a class into ...