mobilizon.chapril.org-mobil.../lib/mobilizon/todos/todo.ex
Thomas Citharel 4144e9ffd0
Introduce group basic federation, event new page and notifications
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2020-06-03 16:01:26 +02:00

48 lines
1.2 KiB
Elixir

defmodule Mobilizon.Todos.Todo do
@moduledoc """
Represents a todo, or task
"""
use Ecto.Schema
import Ecto.Changeset
import Mobilizon.Storage.Ecto, only: [ensure_url: 2]
alias Mobilizon.Actors.Actor
alias Mobilizon.Todos.TodoList
@type t :: %__MODULE__{
status: boolean(),
title: String.t(),
due_date: DateTime.t(),
todo_list: TodoList.t(),
creator: Actor.t(),
assigned_to: Actor.t(),
local: boolean
}
@primary_key {:id, :binary_id, autogenerate: true}
schema "todos" do
field(:status, :boolean, default: false)
field(:title, :string)
field(:url, :string)
field(:due_date, :utc_datetime)
field(:local, :boolean, default: true)
belongs_to(:todo_list, TodoList, type: :binary_id)
belongs_to(:creator, Actor)
belongs_to(:assigned_to, Actor)
timestamps()
end
@required_attrs [:title, :creator_id, :url, :todo_list_id]
@optional_attrs [:status, :due_date, :assigned_to_id, :local]
@attrs @required_attrs ++ @optional_attrs
@doc false
def changeset(todo, attrs) do
todo
|> cast(attrs, @attrs)
|> ensure_url(:todo)
|> validate_required(@required_attrs)
end
end