-
Notifications
You must be signed in to change notification settings - Fork 86
Add active filter #1323
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 active filter #1323
Conversation
def status_filter(queryable, %{"status" => status}) do | ||
queryable | ||
|> where([c], c.status == ^status) | ||
end |
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 still needs a test
Conversation | ||
|> Messages.list_conversations(%{"status" => "any"}) | ||
|> get_and_sort_ids() | ||
# result_ids = |
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 the default be Repo.all()
....do we want to get all conversations?
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 the test on L128 still stands: returns all records by default
.
In this case we just want to test filtering by that status.
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.
And to expand on this, the client really should be responsible for passing the "defaults" in cases where it's not about authorization to see records.
@spec status_filter(Queryable.t, map) :: Queryable.t | ||
def status_filter(queryable, %{"status" => "active"}) do | ||
@spec active_filter(Queryable.t, map) :: Queryable.t | ||
def active_filter(queryable, %{"active" => true}) do |
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.
@joshsmith is this how active filter should work? What specifically filters out inactive records?
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.
A few things I'd recommend changing, along with some answers to your questions.
|> join(:left, [c, _m], cp in ConversationPart, c.id == cp.conversation_id) | ||
|> group_by([c, m, _cp], [c.id, m.initiated_by]) | ||
|> having([_c, m, _cp], m.initiated_by == "user") | ||
|> or_having([c, m, cp], m.initiated_by == "admin" and count(cp.id) > 0) |
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.
In response to your question above, this is the query that does it (specifically the having
and or_having
), and the documentation above expands on that.
The status of `active` means that only those records are included which either | ||
- belong to a `CodeCorps.Message` initiated by user | ||
- belong to a `CodeCorps.Message` initiated by admin, with at least a single |
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.
We need to update this documentation.
Filters
CodeCorps.Conversation
record queries to return only those considered to be active.Active conversations belong either:
And then update the bullets to remove "belong".
|
||
@doc ~S""" | ||
Narrows down a `CodeCorps.Conversation` query to return only those records | ||
considered to have a specific status. |
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.
Would change this to:
Filters
CodeCorps.Conversation
record queries by their status.
Conversation | ||
|> Messages.list_conversations(%{"status" => "any"}) | ||
|> get_and_sort_ids() | ||
# result_ids = |
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 the test on L128 still stands: returns all records by default
.
In this case we just want to test filtering by that status.
Conversation | ||
|> Messages.list_conversations(%{"status" => "any"}) | ||
|> get_and_sort_ids() | ||
# result_ids = |
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.
And to expand on this, the client really should be responsible for passing the "defaults" in cases where it's not about authorization to see records.
4efea63
to
5dfaf3f
Compare
5dfaf3f
to
6b2e8fc
Compare
414a345
to
21e5aa6
Compare
Fixes #1312