Fix front-end, allow events to be created by a group, allow to get sessions from an event

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-01-16 19:45:09 +01:00
parent 7a98674e59
commit 67ef32432e
29 changed files with 278 additions and 82 deletions

View File

@@ -18,7 +18,7 @@ defmodule Eventos.Accounts.Account do
field :uri, :string
field :url, :string
field :username, :string
has_many :organized_events, Event, [foreign_key: :organizer_id]
has_many :organized_events, Event, [foreign_key: :organizer_account_id]
many_to_many :groups, Group, join_through: Member
has_many :group_request, Request
has_one :user, User

View File

@@ -35,6 +35,7 @@ defmodule Eventos.Events.Event do
alias Eventos.Events.{Event, Participant, Request, Tag, Category, Session, Track}
alias Eventos.Events.Event.TitleSlug
alias Eventos.Accounts.Account
alias Eventos.Groups.Group
schema "events" do
field :begins_on, Timex.Ecto.DateTimeWithTimezone
@@ -49,7 +50,8 @@ defmodule Eventos.Events.Event do
field :thumbnail, :string
field :large_image, :string
field :publish_at, Timex.Ecto.DateTimeWithTimezone
belongs_to :organizer, Account, [foreign_key: :organizer_id]
belongs_to :organizer_account, Account, [foreign_key: :organizer_account_id]
belongs_to :organizer_group, Group, [foreign_key: :organizer_group_id]
many_to_many :tags, Tag, join_through: "events_tags"
belongs_to :category, Category
many_to_many :participants, Account, join_through: Participant
@@ -63,9 +65,9 @@ defmodule Eventos.Events.Event do
@doc false
def changeset(%Event{} = event, attrs) do
event
|> cast(attrs, [:title, :description, :begins_on, :ends_on, :organizer_id, :category_id, :state, :geom, :status, :public, :thumbnail, :large_image, :publish_at])
|> cast(attrs, [:title, :description, :begins_on, :ends_on, :organizer_account_id, :organizer_group_id, :category_id, :state, :geom, :status, :public, :thumbnail, :large_image, :publish_at])
|> cast_assoc(:tags)
|> validate_required([:title, :description, :begins_on, :ends_on, :organizer_id, :category_id])
|> validate_required([:title, :description, :begins_on, :ends_on, :organizer_account_id, :category_id])
|> TitleSlug.maybe_generate_slug()
|> TitleSlug.unique_constraint()
end

View File

@@ -7,6 +7,7 @@ defmodule Eventos.Events do
alias Eventos.Repo
alias Eventos.Events.Event
alias Eventos.Accounts.Account
@doc """
Returns the list of events.
@@ -37,6 +38,14 @@ defmodule Eventos.Events do
"""
def get_event!(id), do: Repo.get!(Event, id)
@doc """
Gets a single event, with all associations loaded.
"""
def get_event_full!(id) do
event = Repo.get!(Event, id)
Repo.preload(event, [:organizer_account, :organizer_group, :category, :sessions, :tracks, :tags, :participants])
end
@doc """
Creates a event.
@@ -407,6 +416,10 @@ defmodule Eventos.Events do
Repo.all(Request)
end
def list_requests_for_account(%Account{} = account) do
Repo.all(from r in Request, where: r.account_id == ^account.id)
end
@doc """
Gets a single request.
@@ -503,6 +516,20 @@ defmodule Eventos.Events do
Repo.all(Session)
end
@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
@doc """
Gets a single session.

View File

@@ -32,6 +32,7 @@ defmodule Eventos.Groups.Group do
"""
use Ecto.Schema
import Ecto.Changeset
alias Eventos.Events.Event
alias Eventos.Groups.{Group, Member, Request}
alias Eventos.Accounts.Account
alias Eventos.Groups.Group.TitleSlug
@@ -43,7 +44,8 @@ defmodule Eventos.Groups.Group do
field :slug, TitleSlug.Type
field :uri, :string
field :url, :string
many_to_many :accounts, Account, join_through: Member
many_to_many :members, Account, join_through: Member
has_many :organized_events, Event, [foreign_key: :organizer_group_id]
has_many :requests, Request
timestamps()

View File

@@ -37,6 +37,14 @@ defmodule Eventos.Groups do
"""
def get_group!(id), do: Repo.get!(Group, id)
@doc """
Gets a single group, with all associations loaded.
"""
def get_group_full!(id) do
group = Repo.get!(Group, id)
Repo.preload(group, [:members, :organized_events])
end
@doc """
Creates a group.