Skip to content
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

Merged
merged 31 commits into from Mar 20, 2018
Merged

Conversation

592363789
Copy link

the simple structure of rate

@592363789 592363789 added the status.in_progress Currently being worked on label Mar 12, 2018
@592363789 592363789 added this to the v1.1 milestone Mar 12, 2018
@takuyakanbr takuyakanbr removed this from the v1.1 milestone Mar 15, 2018
@592363789 592363789 added status.completed Ready to be reviewed and removed status.completed Ready to be reviewed labels Mar 16, 2018
@592363789 592363789 removed the status.in_progress Currently being worked on label Mar 17, 2018
@592363789 592363789 changed the title Ratebook Ratebook for add attribute Mar 17, 2018
Copy link

@takuyakanbr takuyakanbr left a 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 {

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;
Copy link

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) {

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 = "";

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),

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",

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",

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",

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",

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>>

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.

@takuyakanbr takuyakanbr changed the title Ratebook for add attribute Add rating field to Book Mar 17, 2018
@@ -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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change.

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change.

+
[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.

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}.

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>}

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.

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}.

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";


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;


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.";

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;

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use an int instead?

Copy link
Author

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;

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.

@takuyakanbr takuyakanbr merged commit cf155e6 into CS2103JAN2018-F14-B4:master Mar 20, 2018
@takuyakanbr takuyakanbr added type.task Something that the developer can do status.accepted Accepted and removed status.completed Ready to be reviewed labels Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status.accepted Accepted type.task Something that the developer can do
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants