Skip to content

Commit

Permalink
add function clauses to handle adding closed and reopned conversation…
Browse files Browse the repository at this point in the history
…_parts
  • Loading branch information
zacck committed Feb 15, 2018
1 parent 67b7337 commit 4dc1ab7
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/code_corps/messages/messages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ defmodule CodeCorps.Messages do
Repo
}
alias Ecto.{Changeset, Queryable}

@reopened "reopened"
@closed "closed"

@doc ~S"""
Lists pre-scoped `CodeCorps.Message` records filtered by parameters.
Expand Down Expand Up @@ -55,19 +58,22 @@ defmodule CodeCorps.Messages do
@doc ~S"""
Updates a `CodeCorps.Conversation` record
"""
def update_conversation(conversation, %{status: @reopened} = params) do
add_part(%{"conversation_id" => conversation.id, "body" => "reopened", "author_id"
=> conversation.user_id, "part_type" => "reopened"})
conversation |> Conversation.update_changeset(params) |> Repo.update
end

def update_conversation(conversation, %{status: @closed} = params) do
add_part(%{"conversation_id" => conversation.id, "body" => "closed", "author_id"
=> conversation.user_id, "part_type" => "closed"})
conversation |> Conversation.update_changeset(params) |> Repo.update
end

def update_conversation(conversation, params) do
%{status: status} = params
case status do
"reopened" ->
add_part(%{"conversation_id" => conversation.id, "body" => "reopened", "author_id"
=> conversation.user_id, "part_type" => "reopened"})
"closed" ->
add_part(%{"conversation_id" => conversation.id, "body" => "closed", "author_id"
=> conversation.user_id, "part_type" => "closed"})

end
conversation |> Conversation.update_changeset(params) |> Repo.update
end


@doc ~S"""
Gets a `CodeCorps.ConversationPart` record
Expand Down

0 comments on commit 4dc1ab7

Please sign in to comment.