-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
this.media = media; | ||
} | ||
|
||
public Review(String username, Media media, int grade) { |
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.
Similar blocks of code found in 2 locations. Consider refactoring.
private final String title; | ||
private final String summary; | ||
|
||
public Media(MediaType mediaType, String title, String summary) { |
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.
Similar blocks of code found in 2 locations. Consider refactoring.
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 class should probably be abstract. No Media object should be instanciated, only subclasses of it.
private final String title; | ||
private final String summary; | ||
|
||
public Media(MediaType mediaType, String title, String summary) { |
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 class should probably be abstract. No Media object should be instanciated, only subclasses of it.
|
||
public class User { | ||
public static final int LIMIT_LOCATION_SIZE = 2; | ||
public static final String FAVOURITES_COLLECTION = "Favourites"; |
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.
Just an idea: It could be good to have a class Collections and an an enum Collection type (such as Favourites, Recently Watched, Custom etc.). Then the user would have a List<Collection>
. Like this we could still change the internal representation of a collection to being a List, Set etc... and define methods used on collections. I think it would also make it easier to later add more Collections. And in general it would be more clean to have the logic of what a collection is seperated from the User class.
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.
I just committed changes where I suggest a similar implementation in [8b153b2]. I created the Collection class and CollectionType enum but left the Map<String, Collection> associated to the user since I think it can be useful for searching a collection by its name.
private String birthDate = ""; | ||
private String registerDate = ""; | ||
|
||
private List<Double> location = new ArrayList<>(); |
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.
Is there a DB reason to define a location as a List<Double
?
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.
I initially wanted to use an array with fixed size but those are not accepted by Firebase. We could create a Location class but that sounds a bit overkill.
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.
I think a Location class would be a useful abstraction to define such methods as getX()
because from a list of double it is not obvious how to extract the coordinates for example.
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.
Good point, adressed in commit [22e38d9].
|
||
private List<Double> location = new ArrayList<>(); | ||
private List<User> friends = new ArrayList<>(); | ||
private Map<String, List<Review>> reviews = new HashMap<>(); |
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.
What would the String key value be here?
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.
It would be the name of your collection "favourites", "highlights" ...
private List<User> friends = new ArrayList<>(); | ||
private Map<String, List<Review>> reviews = new HashMap<>(); | ||
|
||
public UserBuilder(String id){ |
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.
Does this mean that only the String id is a required field to build a user? I think there should be more such as username and email.
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.
All the fields except friends and reviews are "mandatory" (checked before the build() completes). I chose this model since it allows us to set the different fields from different fragments if we need to.
private List<User> friends = new ArrayList<>(); | ||
private Map<String, List<Review>> reviews = new HashMap<>(); | ||
private User(){} | ||
public User(UserBuilder builder){ |
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.
I think this constructor should be private if we are using the Builder design pattern.
} | ||
|
||
@Test | ||
public void user_builder_fails_with_invalid_strings(){ |
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.
Could you add a comment explaining what this test does? I'm not sure if this test is supposed to fail because there are missing attributes or because some strings are invalid.
We should also add tests that check that Preconditions fail on invalid strings but I guess that can wait for now as we haven't defined the formats yet.
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.
Thanks for pointing that out :) I clarified its name in commit [2d89969].
Yes the rest of the tests should be added when we clearly define the necessary formats (that's valid for all the model classes and their attributes, this is just a "draft" so that the methods can be used by the rest of the team during the sprints).
private final MediaType mediaType; | ||
private final String title; | ||
private final String summary; | ||
|
||
public Media(MediaType mediaType, String title, String summary) { |
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.
Should not the Media also have a String property being the link to the displayed image?
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.
Thanks for specifying that! Comment adressed in commit [53d58fc].
public class Movie extends Media{ | ||
public Movie(MediaType mediaType, String title, String summary) { |
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.
Same comment : Movies will be displayed with a picture that is linked through an url.
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.
Thanks ! Comment adressed in commit [53d58fc].
this.grade = grade; | ||
} | ||
|
||
public Review(String username, Media media, int grade, String comment) { |
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.
Similar blocks of code found in 2 locations. Consider refactoring.
private final String imageUrl; | ||
|
||
|
||
public Media(MediaType mediaType, String title, String summary, String imageUrl) { |
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.
Similar blocks of code found in 2 locations. Consider refactoring.
The last two commits remove the birthdate and displayed name attribute from the user class which, after discussing with team members, is unecessary. |
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.
Looks good to me, the structure seems clean!
Code Climate has analyzed commit a25a809 and detected 2 issues on this pull request. Here's the issue category breakdown:
The test coverage on the diff in this pull request is 39.2% (80% is the threshold). This pull request will bring the total coverage in the repository to 40.7% (-3.5% change). View more on Code Climate. |
This PR aims to suggest a basis for the model definition by:
An errorCheck package was also added to allow external handling of errors. A Preconditions class was added inside it and provides methods to check the validity of attributes. Many of them are commented with @todo and have to be completed during a later stage when the conditions are discussed.
Finally, some tests were added to test the User builder.