Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/code_corps/model/task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ defmodule CodeCorps.Task do
import EctoOrdered

alias CodeCorps.Services.MarkdownRendererService
alias Ecto.Changeset

@type t :: %__MODULE__{}

schema "tasks" do
field :closed_at, :utc_datetime
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I've seen utc_datetime before. Is this new in ecto?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The old :datetime field now shows deprecation warning on migration. We need to use either naive_datetime or utc_datetime.

field :body, :string
field :markdown, :string
field :number, :integer, read_after_writes: true
Expand Down Expand Up @@ -58,6 +60,7 @@ defmodule CodeCorps.Task do
|> changeset(params)
|> cast(params, [:status])
|> validate_inclusion(:status, statuses())
|> set_closed_at()
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand why you placed this in update but I do think since it's possible we'll need to write another issue to address this with GitHub sync. Can you open such an issue? We'd need to handle the closed event on GitHub and propagate that close to here. This could happen on create so I want to be sure we're not using the create changeset here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure raised an issue. But I am unaware of GithubSync feel free to edit the issue -#992

end

def apply_position(changeset) do
Expand All @@ -71,4 +74,15 @@ defmodule CodeCorps.Task do
defp statuses do
~w{ open closed }
end

defp set_closed_at(changeset) do
case changeset do
%Changeset{valid?: true, changes: %{status: "closed"}} ->
put_change(changeset, :closed_at, DateTime.utc_now)
%Changeset{valid?: true, changes: %{status: "open"}} ->
put_change(changeset, :closed_at, nil)
_ ->
changeset
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule CodeCorps.Repo.Migrations.AddClosedAtToTasks do
use Ecto.Migration

def change do
alter table(:tasks) do
add :closed_at, :utc_datetime
end
end
end
Loading