New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rating field to Book #66
Conversation
…kTest, BookBuilder, AddCommandSystemTst.java
…struction of book
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename Rate
to Rating
and update all instances of rate
to rating
. It doesn't make sense to say "the book's rate".
Rating
should store an integer between -1
and 5
(both inclusive). Make sure to check its validity in the constructor.
You also should not be adding fields to BookDeserializer
and BookShelfDeserializer
.
* Represents a book's rate. | ||
* Guarantees: immutable. | ||
*/ | ||
public class Rate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this class to Rating
. (Shift+F6 or Refactor -> Rename)
Don't forget to change variables and descriptions to rating
.
*/ | ||
public class Rate { | ||
|
||
public final String rate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an int
between -1
to 5
(both inclusive).
* | ||
* @param rate A book rate. | ||
*/ | ||
public Rate(String rate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should take in an int
rating
.
Check the validity of the input using AppUtil.checkArgument
, in a similar way to this.
@@ -100,6 +101,7 @@ public void setVolumeInfo(JsonVolumeInfo volumeInfo) { | |||
private String publisher = ""; | |||
private String publishedDate = ""; | |||
private String description = ""; | |||
private String rate = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this field.
@@ -46,7 +46,8 @@ public Book deserialize(JsonParser jp, DeserializationContext ctxt) throws IOExc | |||
return new Book(new Gid(root.id), isbn, | |||
BookDataUtil.getAuthorSet(volumeInfo.authors), new Title(volumeInfo.title), | |||
getCategorySet(volumeInfo.categories), getDescription(volumeInfo.description), | |||
new Publisher(volumeInfo.publisher), new PublicationDate(volumeInfo.publishedDate)); | |||
new Rate(volumeInfo.rate), new Publisher(volumeInfo.publisher), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the default rating instead.
@@ -56,6 +57,7 @@ | |||
"publisher": "ABC Publishing House", | |||
"publishedDate": "2018-03-10", | |||
"description": "This is a valid description.", | |||
"rate": "-1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line.
@@ -97,6 +99,7 @@ | |||
"publisher": "ABC Publishing House", | |||
"publishedDate": "2018-03-10", | |||
"description": "This is a valid description.", | |||
"rate": "-1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line.
@@ -14,6 +14,7 @@ | |||
], | |||
"publisher": "ABC Publishing House", | |||
"publishedDate": "2018-03-10", | |||
"rate": "-1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line.
@@ -54,6 +55,7 @@ | |||
], | |||
"publisher": "ABC Publishing House", | |||
"publishedDate": "2018-04-10", | |||
"rate": "-1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line.
@@ -4,6 +4,7 @@ | |||
<books> | |||
<title>Artemis</title> | |||
<description>This is Artemis.</description> | |||
<rate>Rate</rate>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the extra >
at the end of the line. Do the same for the other .xml
files you modified.
docs/DeveloperGuide.adoc
Outdated
@@ -978,18 +978,18 @@ Use case ends. | |||
|
|||
1. User obtains a list of books by listing (<<Use case: UC1 - View my reading list, *UC1*>>) | |||
or searching (<<Use case: UC2 - Search for books,*UC2*>>). | |||
2. User requests to give a rating to a specific book in the list. | |||
2. User requests to give a rate to a specific book in the list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this change.
docs/DeveloperGuide.adoc
Outdated
3. Bibliotek shows a success message. | ||
+ | ||
Use case ends. | ||
|
||
*Extensions* | ||
|
||
[none] | ||
* 2a. The given rating is out of range. | ||
* 2a. The given rate is out of range. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this change.
docs/DeveloperGuide.adoc
Outdated
+ | ||
[none] | ||
** 2a1. Bibliotek says that the rating is invalid and asks user to try again. | ||
** 2a1. Bibliotek says that the rate is invalid and asks user to try again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this change.
@@ -125,4 +126,23 @@ public static Description parseDescription(String description) { | |||
return description.isPresent() ? Optional.of(parseDescription(description.get())) : Optional.empty(); | |||
} | |||
|
|||
/** | |||
* Parses a {@code String rate} into a {@code Rating}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parses a {@code String rating} into a {@code Rating}.
} | ||
|
||
/** | ||
* Parses a {@code Optional<String> rate} into an {@code Optional<Rating>} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rate -> rating
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Represents a book's rate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rate -> rating
public final Integer rating; | ||
|
||
/** | ||
* Constructs a {@code Description}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
-> Rating
public static final String VALID_ISBN_ARTEMIS = "234910247"; | ||
public static final String VALID_ISBN_BABYLON = "907161513"; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this extra newline.
public static final String ISBN_DESC_ARTEMIS = " " + PREFIX_ISBN + VALID_ISBN_ARTEMIS; | ||
public static final String ISBN_DESC_BABYLON = " " + PREFIX_ISBN + VALID_ISBN_BABYLON; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this extra newline.
@@ -34,6 +35,8 @@ | |||
public static final String VALID_CATEGORY_BABYLON = "Fiction"; | |||
public static final String VALID_DESCRIPTION_ARTEMIS = "This is Artemis."; | |||
public static final String VALID_DESCRIPTION_BABYLON = "This is Babylon's Ashes."; | |||
public static final String VALID_RATING_ARTEMIS = "This is Artemis."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static final int VALID_RATING_ARTEMIS = 5;
public static final int VALID_RATING_BABYLON = 4;
*/ | ||
public class Rating { | ||
|
||
public final Integer rating; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an int
instead?
* | ||
* @param rating A book rating. | ||
*/ | ||
public Rating(Integer rating) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an int
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using int will cause some error in the following override methods, so I changed to Integer
@@ -34,6 +35,8 @@ | |||
@XmlElement(required = true) | |||
private String description; | |||
@XmlElement(required = true) | |||
private Integer rating; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an int
instead, if possible.
the simple structure of rate