Skip to content
This repository has been archived by the owner on Feb 1, 2025. It is now read-only.

Model definition #33

Merged
merged 16 commits into from
Mar 10, 2023
Merged

Model definition #33

merged 16 commits into from
Mar 10, 2023

Conversation

MariemBaccari
Copy link
Contributor

This PR aims to suggest a basis for the model definition by:

  • Creating the user class with the methods to build the user from its mandatory features.
  • Defining the Review class, MediaType enum as well as the Media superclass which all media types (such as the implemented Movie one) will extend.

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.

@MariemBaccari MariemBaccari added the model Defining or modifying the model label Mar 8, 2023
this.media = media;
}

public Review(String username, Media media, int grade) {
Copy link

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

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.

Copy link
Contributor

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.

@MariemBaccari MariemBaccari marked this pull request as ready for review March 9, 2023 08:16
private final String title;
private final String summary;

public Media(MediaType mediaType, String title, String summary) {
Copy link
Contributor

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

@simone-kalbermatter simone-kalbermatter Mar 9, 2023

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.

Copy link
Contributor Author

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<>();
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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<>();
Copy link
Contributor

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?

Copy link
Contributor Author

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){
Copy link
Contributor

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.

Copy link
Contributor Author

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){
Copy link
Contributor

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(){
Copy link
Contributor

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.

Copy link
Contributor Author

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

MeKHell
MeKHell previously requested changes Mar 9, 2023
Comment on lines 9 to 13
private final MediaType mediaType;
private final String title;
private final String summary;

public Media(MediaType mediaType, String title, String summary) {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Comment on lines 5 to 6
public class Movie extends Media{
public Movie(MediaType mediaType, String title, String summary) {
Copy link
Contributor

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.

Copy link
Contributor Author

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

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

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.

@MariemBaccari
Copy link
Contributor Author

MariemBaccari commented Mar 10, 2023

The last two commits remove the birthdate and displayed name attribute from the user class which, after discussing with team members, is unecessary.

Copy link
Contributor

@simone-kalbermatter simone-kalbermatter left a 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!

@codeclimate
Copy link

codeclimate bot commented Mar 10, 2023

Code Climate has analyzed commit a25a809 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 2

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.

@MariemBaccari MariemBaccari dismissed MeKHell’s stale review March 10, 2023 09:49

Adressed both comments

@MariemBaccari MariemBaccari merged commit e11306a into main Mar 10, 2023
@MariemBaccari MariemBaccari deleted the model_definition branch March 20, 2023 17:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
model Defining or modifying the model
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants