Conversation
zacck-zz
left a comment
There was a problem hiding this comment.
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 |
| Posts.Bookmark | ||
| } | ||
|
|
||
| schema "bookmarks" do |
There was a problem hiding this comment.
@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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
@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?
lib/qb_backend/posts/bookmark.ex
Outdated
| def add_manual_to_bookmark(%Bookmark{id: _id, manuals: manuals} = bookmark, %Manual{} = manual) do | ||
| bookmark | ||
| |> changeset(%{}) | ||
| |> put_assoc(:manuals, manuals ++ [manual]) |
There was a problem hiding this comment.
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
lib/qb_backend/posts/manual.ex
Outdated
| 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
@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
There was a problem hiding this comment.
@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
|
@WanjikuMac hmmmm so if I as a profile own a bookmark I will expect it to have a name like I could have a |
zacck-zz
left a comment
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
@WanjikuMac we likely don't need this index any more since I think this is in the join table
There was a problem hiding this comment.
Yea the tests are passing without it.
| } | ||
| @valid_bookmark %{} | ||
| describe "Bookmark" do | ||
| test "Enable a user to create a bookmark" do |
There was a problem hiding this comment.
@WanjikuMac this test actually just test Drives the bookmark changeset
There was a problem hiding this comment.
@zacck This checks if a bookmark is actually created.
Pull Request Test Coverage Report for Build 167
💛 - Coveralls |
zacck-zz
left a comment
There was a problem hiding this comment.
@WanjikuMac we need to change our associations' strategy, otherwise coming along very well indeed
lib/qb_backend/posts/manual.ex
Outdated
| def remove_manual_from_bookmark(%Manual{bookmarks: _bookmark} = manual) do | ||
| manual | ||
| |> changeset(%{}) | ||
| |> put_change(:bookmark_id, nil) |
lib/qb_backend/posts/manual.ex
Outdated
| manual | ||
| |> changeset(%{}) | ||
| |> put_change(:bookmark_id, nil) | ||
| |> put_change(:bookmark, nil) |
There was a problem hiding this comment.
this line is also not relevant
lib/qb_backend/posts/manual.ex
Outdated
| manual | ||
| |> changeset(%{}) | ||
| |> put_change(:bookmark_id, nil) | ||
| |> put_change(:bookmark, nil) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
@zacck can we have this instead put_assoc(:bookmark, manuals) ?
There was a problem hiding this comment.
erm can you check how the associations work on spender between an Item and a Logsection
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
@WanjikuMac however way works for you and is most efficient ... remember deleting code is better than adding
zacck-zz
left a comment
There was a problem hiding this comment.
Hey @WanjikuMac just a few changes to push this over the hill
| end | ||
|
|
||
| @doc """ | ||
| This function actually adds the manual struct to the bookmark |
There was a problem hiding this comment.
@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 |
zacck-zz
left a comment
There was a problem hiding this comment.
@WanjikuMac this is looking good so far
Fixes
#33