Skip to content

Conversation

snewcomer
Copy link
Contributor

@snewcomer snewcomer commented Dec 20, 2017

Fixes #1312

@snewcomer snewcomer self-assigned this Dec 20, 2017
def status_filter(queryable, %{"status" => status}) do
queryable
|> where([c], c.status == ^status)
end
Copy link
Contributor Author

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 =
Copy link
Contributor Author

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?

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 the test on L128 still stands: returns all records by default.

In this case we just want to test filtering by that status.

Copy link
Contributor

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
Copy link
Contributor Author

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?

Copy link
Contributor

@joshsmith joshsmith left a 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)
Copy link
Contributor

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

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.
Copy link
Contributor

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 =
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 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 =
Copy link
Contributor

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.

@snewcomer snewcomer force-pushed the conv-query-active branch 2 times, most recently from 4efea63 to 5dfaf3f Compare December 21, 2017 04:34
@joshsmith joshsmith merged commit 15d84db into develop Dec 21, 2017
@joshsmith joshsmith deleted the conv-query-active branch December 21, 2017 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants