2017-12-08 09:58:14 +01:00
|
|
|
defmodule Eventos.Events do
|
|
|
|
@moduledoc """
|
|
|
|
The Events context.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import Ecto.Query, warn: false
|
|
|
|
alias Eventos.Repo
|
|
|
|
|
|
|
|
alias Eventos.Events.Event
|
2018-01-16 19:45:09 +01:00
|
|
|
alias Eventos.Accounts.Account
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
@doc """
|
|
|
|
Returns the list of events.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> list_events()
|
|
|
|
[%Event{}, ...]
|
|
|
|
|
|
|
|
"""
|
|
|
|
def list_events do
|
|
|
|
Repo.all(Event)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Gets a single event.
|
|
|
|
|
|
|
|
Raises `Ecto.NoResultsError` if the Event does not exist.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> get_event!(123)
|
|
|
|
%Event{}
|
|
|
|
|
|
|
|
iex> get_event!(456)
|
|
|
|
** (Ecto.NoResultsError)
|
|
|
|
|
|
|
|
"""
|
|
|
|
def get_event!(id), do: Repo.get!(Event, id)
|
|
|
|
|
2018-01-16 19:45:09 +01:00
|
|
|
@doc """
|
|
|
|
Gets a single event, with all associations loaded.
|
|
|
|
"""
|
|
|
|
def get_event_full!(id) do
|
|
|
|
event = Repo.get!(Event, id)
|
2018-01-17 11:39:01 +01:00
|
|
|
Repo.preload(event, [:organizer_account, :organizer_group, :category, :sessions, :tracks, :tags, :participants, :address])
|
2018-01-16 19:45:09 +01:00
|
|
|
end
|
|
|
|
|
2017-12-08 09:58:14 +01:00
|
|
|
@doc """
|
|
|
|
Creates a event.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> create_event(%{field: value})
|
|
|
|
{:ok, %Event{}}
|
|
|
|
|
|
|
|
iex> create_event(%{field: bad_value})
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def create_event(attrs \\ %{}) do
|
|
|
|
%Event{}
|
|
|
|
|> Event.changeset(attrs)
|
|
|
|
|> Repo.insert()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Updates a event.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> update_event(event, %{field: new_value})
|
|
|
|
{:ok, %Event{}}
|
|
|
|
|
|
|
|
iex> update_event(event, %{field: bad_value})
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def update_event(%Event{} = event, attrs) do
|
|
|
|
event
|
|
|
|
|> Event.changeset(attrs)
|
|
|
|
|> Repo.update()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Deletes a Event.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> delete_event(event)
|
|
|
|
{:ok, %Event{}}
|
|
|
|
|
|
|
|
iex> delete_event(event)
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def delete_event(%Event{} = event) do
|
|
|
|
Repo.delete(event)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Returns an `%Ecto.Changeset{}` for tracking event changes.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> change_event(event)
|
|
|
|
%Ecto.Changeset{source: %Event{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def change_event(%Event{} = event) do
|
|
|
|
Event.changeset(event, %{})
|
|
|
|
end
|
|
|
|
|
|
|
|
alias Eventos.Events.Category
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Returns the list of categories.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> list_categories()
|
|
|
|
[%Category{}, ...]
|
|
|
|
|
|
|
|
"""
|
|
|
|
def list_categories do
|
|
|
|
Repo.all(Category)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Gets a single category.
|
|
|
|
|
|
|
|
Raises `Ecto.NoResultsError` if the Category does not exist.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> get_category!(123)
|
|
|
|
%Category{}
|
|
|
|
|
|
|
|
iex> get_category!(456)
|
|
|
|
** (Ecto.NoResultsError)
|
|
|
|
|
|
|
|
"""
|
|
|
|
def get_category!(id), do: Repo.get!(Category, id)
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Creates a category.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> create_category(%{field: value})
|
|
|
|
{:ok, %Category{}}
|
|
|
|
|
|
|
|
iex> create_category(%{field: bad_value})
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def create_category(attrs \\ %{}) do
|
|
|
|
%Category{}
|
|
|
|
|> Category.changeset(attrs)
|
|
|
|
|> Repo.insert()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Updates a category.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> update_category(category, %{field: new_value})
|
|
|
|
{:ok, %Category{}}
|
|
|
|
|
|
|
|
iex> update_category(category, %{field: bad_value})
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def update_category(%Category{} = category, attrs) do
|
|
|
|
category
|
|
|
|
|> Category.changeset(attrs)
|
|
|
|
|> Repo.update()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Deletes a Category.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> delete_category(category)
|
|
|
|
{:ok, %Category{}}
|
|
|
|
|
|
|
|
iex> delete_category(category)
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def delete_category(%Category{} = category) do
|
|
|
|
Repo.delete(category)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Returns an `%Ecto.Changeset{}` for tracking category changes.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> change_category(category)
|
|
|
|
%Ecto.Changeset{source: %Category{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def change_category(%Category{} = category) do
|
|
|
|
Category.changeset(category, %{})
|
|
|
|
end
|
|
|
|
|
|
|
|
alias Eventos.Events.Tag
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Returns the list of tags.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> list_tags()
|
|
|
|
[%Tag{}, ...]
|
|
|
|
|
|
|
|
"""
|
|
|
|
def list_tags do
|
|
|
|
Repo.all(Tag)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Gets a single tag.
|
|
|
|
|
|
|
|
Raises `Ecto.NoResultsError` if the Tag does not exist.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> get_tag!(123)
|
|
|
|
%Tag{}
|
|
|
|
|
|
|
|
iex> get_tag!(456)
|
|
|
|
** (Ecto.NoResultsError)
|
|
|
|
|
|
|
|
"""
|
|
|
|
def get_tag!(id), do: Repo.get!(Tag, id)
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Creates a tag.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> create_tag(%{field: value})
|
|
|
|
{:ok, %Tag{}}
|
|
|
|
|
|
|
|
iex> create_tag(%{field: bad_value})
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def create_tag(attrs \\ %{}) do
|
|
|
|
%Tag{}
|
|
|
|
|> Tag.changeset(attrs)
|
|
|
|
|> Repo.insert()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Updates a tag.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> update_tag(tag, %{field: new_value})
|
|
|
|
{:ok, %Tag{}}
|
|
|
|
|
|
|
|
iex> update_tag(tag, %{field: bad_value})
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def update_tag(%Tag{} = tag, attrs) do
|
|
|
|
tag
|
|
|
|
|> Tag.changeset(attrs)
|
|
|
|
|> Repo.update()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Deletes a Tag.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> delete_tag(tag)
|
|
|
|
{:ok, %Tag{}}
|
|
|
|
|
|
|
|
iex> delete_tag(tag)
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def delete_tag(%Tag{} = tag) do
|
|
|
|
Repo.delete(tag)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Returns an `%Ecto.Changeset{}` for tracking tag changes.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> change_tag(tag)
|
|
|
|
%Ecto.Changeset{source: %Tag{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def change_tag(%Tag{} = tag) do
|
|
|
|
Tag.changeset(tag, %{})
|
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
alias Eventos.Events.Participant
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
@doc """
|
2018-01-13 23:33:03 +01:00
|
|
|
Returns the list of participants.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> list_participants()
|
|
|
|
[%Participant{}, ...]
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
def list_participants do
|
|
|
|
Repo.all(Participant)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
2018-01-13 23:33:03 +01:00
|
|
|
Gets a single participant.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
Raises `Ecto.NoResultsError` if the Participant does not exist.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> get_participant!(123)
|
|
|
|
%Participant{}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> get_participant!(456)
|
2017-12-08 09:58:14 +01:00
|
|
|
** (Ecto.NoResultsError)
|
|
|
|
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
def get_participant!(event_id, account_id) do
|
|
|
|
Repo.get_by!(Participant, [event_id: event_id, account_id: account_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Creates a participant.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> create_participant(%{field: value})
|
|
|
|
{:ok, %Participant{}}
|
|
|
|
|
|
|
|
iex> create_participant(%{field: bad_value})
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def create_participant(attrs \\ %{}) do
|
|
|
|
%Participant{}
|
|
|
|
|> Participant.changeset(attrs)
|
|
|
|
|> Repo.insert()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Updates a participant.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> update_participant(participant, %{field: new_value})
|
|
|
|
{:ok, %Participant{}}
|
|
|
|
|
|
|
|
iex> update_participant(participant, %{field: bad_value})
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def update_participant(%Participant{} = participant, attrs) do
|
|
|
|
participant
|
|
|
|
|> Participant.changeset(attrs)
|
|
|
|
|> Repo.update()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Deletes a Participant.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> delete_participant(participant)
|
|
|
|
{:ok, %Participant{}}
|
|
|
|
|
|
|
|
iex> delete_participant(participant)
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def delete_participant(%Participant{} = participant) do
|
|
|
|
Repo.delete(participant)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Returns an `%Ecto.Changeset{}` for tracking participant changes.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> change_participant(participant)
|
|
|
|
%Ecto.Changeset{source: %Participant{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def change_participant(%Participant{} = participant) do
|
|
|
|
Participant.changeset(participant, %{})
|
|
|
|
end
|
|
|
|
|
|
|
|
alias Eventos.Events.Request
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Returns the list of requests.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> list_requests()
|
|
|
|
[%Request{}, ...]
|
|
|
|
|
|
|
|
"""
|
|
|
|
def list_requests do
|
|
|
|
Repo.all(Request)
|
|
|
|
end
|
|
|
|
|
2018-01-16 19:45:09 +01:00
|
|
|
def list_requests_for_account(%Account{} = account) do
|
|
|
|
Repo.all(from r in Request, where: r.account_id == ^account.id)
|
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
@doc """
|
|
|
|
Gets a single request.
|
|
|
|
|
|
|
|
Raises `Ecto.NoResultsError` if the Request does not exist.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> get_request!(123)
|
|
|
|
%Request{}
|
|
|
|
|
|
|
|
iex> get_request!(456)
|
|
|
|
** (Ecto.NoResultsError)
|
|
|
|
|
|
|
|
"""
|
|
|
|
def get_request!(id), do: Repo.get!(Request, id)
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Creates a request.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> create_request(%{field: value})
|
|
|
|
{:ok, %Request{}}
|
|
|
|
|
|
|
|
iex> create_request(%{field: bad_value})
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def create_request(attrs \\ %{}) do
|
|
|
|
%Request{}
|
|
|
|
|> Request.changeset(attrs)
|
|
|
|
|> Repo.insert()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Updates a request.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> update_request(request, %{field: new_value})
|
|
|
|
{:ok, %Request{}}
|
|
|
|
|
|
|
|
iex> update_request(request, %{field: bad_value})
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def update_request(%Request{} = request, attrs) do
|
|
|
|
request
|
|
|
|
|> Request.changeset(attrs)
|
|
|
|
|> Repo.update()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Deletes a Request.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> delete_request(request)
|
|
|
|
{:ok, %Request{}}
|
|
|
|
|
|
|
|
iex> delete_request(request)
|
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def delete_request(%Request{} = request) do
|
|
|
|
Repo.delete(request)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Returns an `%Ecto.Changeset{}` for tracking request changes.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> change_request(request)
|
|
|
|
%Ecto.Changeset{source: %Request{}}
|
|
|
|
|
|
|
|
"""
|
|
|
|
def change_request(%Request{} = request) do
|
|
|
|
Request.changeset(request, %{})
|
|
|
|
end
|
|
|
|
|
|
|
|
alias Eventos.Events.Session
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Returns the list of sessions.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> list_sessions()
|
|
|
|
[%Session{}, ...]
|
|
|
|
|
|
|
|
"""
|
|
|
|
def list_sessions do
|
|
|
|
Repo.all(Session)
|
|
|
|
end
|
|
|
|
|
2018-01-16 19:45:09 +01:00
|
|
|
@doc """
|
|
|
|
Returns the list of sessions for an event
|
|
|
|
"""
|
|
|
|
def list_sessions_for_event(event_id) do
|
|
|
|
Repo.all(from s in Session, where: s.event_id == ^event_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Returns the list of sessions for a track
|
|
|
|
"""
|
|
|
|
def list_sessions_for_track(track_id) do
|
|
|
|
Repo.all(from s in Session, where: s.track_id == ^track_id)
|
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
@doc """
|
|
|
|
Gets a single session.
|
|
|
|
|
|
|
|
Raises `Ecto.NoResultsError` if the Session does not exist.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> get_session!(123)
|
|
|
|
%Session{}
|
|
|
|
|
|
|
|
iex> get_session!(456)
|
|
|
|
** (Ecto.NoResultsError)
|
|
|
|
|
|
|
|
"""
|
|
|
|
def get_session!(id), do: Repo.get!(Session, id)
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
@doc """
|
2018-01-13 23:33:03 +01:00
|
|
|
Creates a session.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> create_session(%{field: value})
|
|
|
|
{:ok, %Session{}}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> create_session(%{field: bad_value})
|
2017-12-08 09:58:14 +01:00
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
def create_session(attrs \\ %{}) do
|
|
|
|
%Session{}
|
|
|
|
|> Session.changeset(attrs)
|
2017-12-08 09:58:14 +01:00
|
|
|
|> Repo.insert()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
2018-01-13 23:33:03 +01:00
|
|
|
Updates a session.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> update_session(session, %{field: new_value})
|
|
|
|
{:ok, %Session{}}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> update_session(session, %{field: bad_value})
|
2017-12-08 09:58:14 +01:00
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
def update_session(%Session{} = session, attrs) do
|
|
|
|
session
|
|
|
|
|> Session.changeset(attrs)
|
2017-12-08 09:58:14 +01:00
|
|
|
|> Repo.update()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
2018-01-13 23:33:03 +01:00
|
|
|
Deletes a Session.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> delete_session(session)
|
|
|
|
{:ok, %Session{}}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> delete_session(session)
|
2017-12-08 09:58:14 +01:00
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
def delete_session(%Session{} = session) do
|
|
|
|
Repo.delete(session)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
2018-01-13 23:33:03 +01:00
|
|
|
Returns an `%Ecto.Changeset{}` for tracking session changes.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> change_session(session)
|
|
|
|
%Ecto.Changeset{source: %Session{}}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
def change_session(%Session{} = session) do
|
|
|
|
Session.changeset(session, %{})
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
alias Eventos.Events.Track
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
@doc """
|
2018-01-13 23:33:03 +01:00
|
|
|
Returns the list of tracks.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> list_tracks()
|
|
|
|
[%Track{}, ...]
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
def list_tracks do
|
|
|
|
Repo.all(Track)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
2018-01-13 23:33:03 +01:00
|
|
|
Gets a single track.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
Raises `Ecto.NoResultsError` if the Track does not exist.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> get_track!(123)
|
|
|
|
%Track{}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> get_track!(456)
|
2017-12-08 09:58:14 +01:00
|
|
|
** (Ecto.NoResultsError)
|
|
|
|
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
def get_track!(id), do: Repo.get!(Track, id)
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
@doc """
|
2018-01-13 23:33:03 +01:00
|
|
|
Creates a track.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> create_track(%{field: value})
|
|
|
|
{:ok, %Track{}}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> create_track(%{field: bad_value})
|
2017-12-08 09:58:14 +01:00
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
def create_track(attrs \\ %{}) do
|
|
|
|
%Track{}
|
|
|
|
|> Track.changeset(attrs)
|
2017-12-08 09:58:14 +01:00
|
|
|
|> Repo.insert()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
2018-01-13 23:33:03 +01:00
|
|
|
Updates a track.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> update_track(track, %{field: new_value})
|
|
|
|
{:ok, %Track{}}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> update_track(track, %{field: bad_value})
|
2017-12-08 09:58:14 +01:00
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
def update_track(%Track{} = track, attrs) do
|
|
|
|
track
|
|
|
|
|> Track.changeset(attrs)
|
2017-12-08 09:58:14 +01:00
|
|
|
|> Repo.update()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
2018-01-13 23:33:03 +01:00
|
|
|
Deletes a Track.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> delete_track(track)
|
|
|
|
{:ok, %Track{}}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> delete_track(track)
|
2017-12-08 09:58:14 +01:00
|
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
def delete_track(%Track{} = track) do
|
|
|
|
Repo.delete(track)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
2018-01-13 23:33:03 +01:00
|
|
|
Returns an `%Ecto.Changeset{}` for tracking track changes.
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
iex> change_track(track)
|
|
|
|
%Ecto.Changeset{source: %Track{}}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
def change_track(%Track{} = track) do
|
|
|
|
Track.changeset(track, %{})
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
end
|