Skip to content

[WIP] Feature/enable bookmarking#39

Open
WanjikuMac wants to merge 17 commits intodevelopfrom
feature/enable_bookmarking
Open

[WIP] Feature/enable bookmarking#39
WanjikuMac wants to merge 17 commits intodevelopfrom
feature/enable_bookmarking

Conversation

@WanjikuMac
Copy link
Contributor

Fixes
#33

@WanjikuMac WanjikuMac requested review from r-coh and zacck-zz October 21, 2018 17:19
Copy link
Member

@zacck-zz zacck-zz left a comment

Choose a reason for hiding this comment

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

Hey @WanjikuMac good work on this PR and on building that Macro glad to see you could use it ... Just a few changes to get this to fly nice!

@moduledoc """
This module defines the schema for the bookmark section
"""
use QbBackend.Utils.Schema
Copy link
Member

Choose a reason for hiding this comment

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

ahahah I like this!

Posts.Bookmark
}

schema "bookmarks" do
Copy link
Member

Choose a reason for hiding this comment

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

@WanjikuMac could you perhaps consider giving a bookmark a name so maybe a user can have many bookmarks and the ability to choose from one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By bookmark name do you mean e.g bookmark 1? Otherwise the bookmark name is the name of the manual. Like when you book mark a post you retrieve it by the name of the manual

Copy link
Member

Choose a reason for hiding this comment

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

@WanjikuMac no I mean the bookmark should have a field for the name of the bookmark, Consider the case where one person wants many bookmarks for example. I could have a bookmark that stores all the Yoga stuff I want to read and I could name it my yoga reads and I could have a bookmark that stores all the Business stuff I want to read and this one I could call kazi does this make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zacck Aaah, I see.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zacck Aaah, I see.

Copy link
Member

Choose a reason for hiding this comment

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

@WanjikuMac no I mean the bookmark should have a field for the name of the bookmark, Consider the case where one person wants many bookmarks for example. I could have a bookmark that stores all the Yoga stuff I want to read and I could name it my yoga reads and I could have a bookmark that stores all the Business stuff I want to read and this one I could call kazi does this make sense?

def add_manual_to_bookmark(%Bookmark{id: _id, manuals: manuals} = bookmark, %Manual{} = manual) do
bookmark
|> changeset(%{})
|> put_assoc(:manuals, manuals ++ [manual])
Copy link
Member

Choose a reason for hiding this comment

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

appending to lists is very expensive since the compiler has to walk through all the items to add one perhaps consider prepending to the list like this [manual] ++ manuals see here https://elixirforum.com/t/when-would-you-need-to-append-to-an-elixir-list-over-prepending/12908

This function takes a bookmark and a manual and creates an association between them
"""
@spec add_to_bookmark(Manual.t(), Bookmark.t()) :: {:ok, Manual.t()} | {:error, Ecto.Changeset.t()}
def add_to_bookmark(%Manual{} = manual, %Bookmark{} = bookmark) do
Copy link
Member

Choose a reason for hiding this comment

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

I am not so sure that we need the functions in the Manual for adding a manual to a bookmark, I think we should only have the ones in the bookmark since the bookmark is the item that owns in this relationship

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay.

Copy link
Member

Choose a reason for hiding this comment

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

@WanjikuMac I thought about this situation and I think I changed my mind, I realized that we may need to keep these functions however we will need to convert the relationship to a many-to-many since it is very likely that down the line we will need to answer these two questions

  • How many manuals are in a bookmark
  • In how many bookmarks is a manual

These two would need us to have and maintain a bidirectional relationship I think

Copy link
Member

Choose a reason for hiding this comment

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

@WanjikuMac I thought about this situation and I think I changed my mind, I realized that we may need to keep these functions however we will need to convert the relationship to a many-to-many since it is very likely that down the line we will need to answer these two questions

  • How many manuals are in a bookmark
  • In how many bookmarks is a manual

These two would need us to have and maintain a bidirectional relationship I think

@zacck-zz
Copy link
Member

@WanjikuMac hmmmm so if I as a profile own a bookmark I will expect it to have a name like I could have a Yoga bookmark and I could put yoga manuals I am interested in that bookmark but later down the line I may want a business bookmark so I can put the business articles I am intrested in it there ... do you see

Copy link
Member

@zacck-zz zacck-zz left a comment

Choose a reason for hiding this comment

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

hey @WanjikuMac some little pushes here and there and this should be good to fly!

add :bookmark_id, references(:bookmarks, type: :binary_id)
end

create index(:manuals, [:bookmark_id])
Copy link
Member

Choose a reason for hiding this comment

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

@WanjikuMac we likely don't need this index any more since I think this is in the join table

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea the tests are passing without it.

}
@valid_bookmark %{}
describe "Bookmark" do
test "Enable a user to create a bookmark" do
Copy link
Member

Choose a reason for hiding this comment

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

@WanjikuMac this test actually just test Drives the bookmark changeset

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zacck This checks if a bookmark is actually created.

@coveralls
Copy link

coveralls commented Oct 22, 2018

Pull Request Test Coverage Report for Build 167

  • 9 of 10 (90.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.7%) to 83.654%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/qb_backend/posts/manual.ex 0 1 0.0%
Totals Coverage Status
Change from base Build 152: 0.7%
Covered Lines: 87
Relevant Lines: 104

💛 - Coveralls

Copy link
Member

@zacck-zz zacck-zz left a comment

Choose a reason for hiding this comment

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

@WanjikuMac we need to change our associations' strategy, otherwise coming along very well indeed

def remove_manual_from_bookmark(%Manual{bookmarks: _bookmark} = manual) do
manual
|> changeset(%{})
|> put_change(:bookmark_id, nil)
Copy link
Member

Choose a reason for hiding this comment

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

@WanjikuMac this line isn't relevant

manual
|> changeset(%{})
|> put_change(:bookmark_id, nil)
|> put_change(:bookmark, nil)
Copy link
Member

Choose a reason for hiding this comment

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

this line is also not relevant

manual
|> changeset(%{})
|> put_change(:bookmark_id, nil)
|> put_change(:bookmark, nil)
Copy link
Member

Choose a reason for hiding this comment

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

This line is not relevant, we are going to need to find another way of building this associations as this strategy doesn't work for many to many associations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zacck can we have this instead put_assoc(:bookmark, manuals) ?

Copy link
Member

Choose a reason for hiding this comment

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

erm can you check how the associations work on spender between an Item and a Logsection

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zacck @br4inii I think we don't need the add manual to bookmark on the manual.ex since it's already captured on the bookmark.ex file. Plus the manual.ex file can already create a manual for us... What are your thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

@WanjikuMac however way works for you and is most efficient ... remember deleting code is better than adding

Copy link
Member

@zacck-zz zacck-zz left a comment

Choose a reason for hiding this comment

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

Hey @WanjikuMac just a few changes to push this over the hill

end

@doc """
This function actually adds the manual struct to the bookmark
Copy link
Member

Choose a reason for hiding this comment

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

@WanjikuMac please document your parameters for this function


@doc """
this function delets an image struct from a manual
this function deletes an image struct from a manual
Copy link
Member

Choose a reason for hiding this comment

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

@WanjikuMac this needs parameter documentation too

Copy link
Member

@zacck-zz zacck-zz left a comment

Choose a reason for hiding this comment

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

@WanjikuMac this is looking good so far

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants