2020-02-18 08:57:00 +01:00
|
|
|
defmodule Mobilizon.Todos.TodoList do
|
|
|
|
@moduledoc """
|
|
|
|
Represents a todo list, or task list
|
|
|
|
"""
|
|
|
|
|
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
2020-08-14 11:32:23 +02:00
|
|
|
import Mobilizon.Storage.Ecto, only: [ensure_url: 2, maybe_add_published_at: 1]
|
2020-02-18 08:57:00 +01:00
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Todos.Todo
|
|
|
|
|
|
|
|
@type t :: %__MODULE__{
|
2021-09-28 19:40:37 +02:00
|
|
|
id: String.t(),
|
|
|
|
url: String.t(),
|
2020-02-18 08:57:00 +01:00
|
|
|
title: String.t(),
|
|
|
|
todos: [Todo.t()],
|
|
|
|
actor: Actor.t(),
|
2020-08-14 11:32:23 +02:00
|
|
|
local: boolean,
|
|
|
|
published_at: DateTime.t()
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@primary_key {:id, :binary_id, autogenerate: true}
|
|
|
|
schema "todo_lists" do
|
|
|
|
field(:title, :string)
|
|
|
|
field(:url, :string)
|
|
|
|
field(:local, :boolean, default: true)
|
2020-08-14 11:32:23 +02:00
|
|
|
field(:published_at, :utc_datetime)
|
2020-02-18 08:57:00 +01:00
|
|
|
belongs_to(:actor, Actor)
|
|
|
|
has_many(:todos, Todo)
|
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
2020-08-14 11:32:23 +02:00
|
|
|
@required_attrs [:title, :url, :actor_id, :published_at]
|
2020-02-18 08:57:00 +01:00
|
|
|
@optional_attrs [:local]
|
|
|
|
@attrs @required_attrs ++ @optional_attrs
|
|
|
|
|
|
|
|
@doc false
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec changeset(t | Ecto.Schema.t(), map) :: Ecto.Changeset.t()
|
2020-02-18 08:57:00 +01:00
|
|
|
def changeset(todo_list, attrs) do
|
|
|
|
todo_list
|
|
|
|
|> cast(attrs, @attrs)
|
|
|
|
|> ensure_url(:todo_list)
|
2020-08-14 11:32:23 +02:00
|
|
|
|> maybe_add_published_at()
|
2020-02-18 08:57:00 +01:00
|
|
|
|> validate_required(@required_attrs)
|
|
|
|
end
|
|
|
|
end
|