Remove credo and use mix format, and lint everything
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -6,11 +6,10 @@ defmodule Eventos.Events.Category do
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Events.Category
|
||||
|
||||
|
||||
schema "categories" do
|
||||
field :description, :string
|
||||
field :picture, :string
|
||||
field :title, :string, null: false
|
||||
field(:description, :string)
|
||||
field(:picture, :string)
|
||||
field(:title, :string, null: false)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@@ -11,15 +11,15 @@ defmodule Eventos.Events.Comment do
|
||||
alias Eventos.Actors.Comment
|
||||
|
||||
schema "comments" do
|
||||
field :text, :string
|
||||
field :url, :string
|
||||
field :local, :boolean, default: true
|
||||
field :uuid, Ecto.UUID
|
||||
belongs_to :actor, Actor, [foreign_key: :actor_id]
|
||||
belongs_to :attributed_to, Actor, [foreign_key: :attributed_to_id]
|
||||
belongs_to :event, Event, [foreign_key: :event_id]
|
||||
belongs_to :in_reply_to_comment, Comment, [foreign_key: :in_reply_to_comment_id]
|
||||
belongs_to :origin_comment, Comment, [foreign_key: :origin_comment_id]
|
||||
field(:text, :string)
|
||||
field(:url, :string)
|
||||
field(:local, :boolean, default: true)
|
||||
field(:uuid, Ecto.UUID)
|
||||
belongs_to(:actor, Actor, foreign_key: :actor_id)
|
||||
belongs_to(:attributed_to, Actor, foreign_key: :attributed_to_id)
|
||||
belongs_to(:event, Event, foreign_key: :event_id)
|
||||
belongs_to(:in_reply_to_comment, Comment, foreign_key: :in_reply_to_comment_id)
|
||||
belongs_to(:origin_comment, Comment, foreign_key: :origin_comment_id)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
@@ -27,6 +27,7 @@ defmodule Eventos.Events.Comment do
|
||||
@doc false
|
||||
def changeset(comment, attrs) do
|
||||
uuid = Ecto.UUID.generate()
|
||||
|
||||
comment
|
||||
|> cast(attrs, [:url, :text, :actor_id, :event_id, :in_reply_to_comment_id, :attributed_to_id])
|
||||
|> validate_required([:text, :actor_id])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import EctoEnum
|
||||
defenum AddressTypeEnum, :address_type, [:physical, :url, :phone, :other]
|
||||
defenum(AddressTypeEnum, :address_type, [:physical, :url, :phone, :other])
|
||||
|
||||
defmodule Eventos.Events.Event do
|
||||
@moduledoc """
|
||||
@@ -12,30 +12,30 @@ defmodule Eventos.Events.Event do
|
||||
alias Eventos.Addresses.Address
|
||||
|
||||
schema "events" do
|
||||
field :url, :string
|
||||
field :local, :boolean, default: true
|
||||
field :begins_on, Timex.Ecto.DateTimeWithTimezone
|
||||
field :description, :string
|
||||
field :ends_on, Timex.Ecto.DateTimeWithTimezone
|
||||
field :title, :string
|
||||
field :state, :integer, default: 0
|
||||
field :status, :integer, default: 0
|
||||
field :public, :boolean, default: true
|
||||
field :thumbnail, :string
|
||||
field :large_image, :string
|
||||
field :publish_at, Timex.Ecto.DateTimeWithTimezone
|
||||
field :uuid, Ecto.UUID, default: Ecto.UUID.generate()
|
||||
field :address_type, AddressTypeEnum, default: :physical
|
||||
field :online_address, :string
|
||||
field :phone, :string
|
||||
belongs_to :organizer_actor, Actor, [foreign_key: :organizer_actor_id]
|
||||
belongs_to :attributed_to, Actor, [foreign_key: :attributed_to_id]
|
||||
many_to_many :tags, Tag, join_through: "events_tags"
|
||||
belongs_to :category, Category
|
||||
many_to_many :participants, Actor, join_through: Participant
|
||||
has_many :tracks, Track
|
||||
has_many :sessions, Session
|
||||
belongs_to :physical_address, Address
|
||||
field(:url, :string)
|
||||
field(:local, :boolean, default: true)
|
||||
field(:begins_on, Timex.Ecto.DateTimeWithTimezone)
|
||||
field(:description, :string)
|
||||
field(:ends_on, Timex.Ecto.DateTimeWithTimezone)
|
||||
field(:title, :string)
|
||||
field(:state, :integer, default: 0)
|
||||
field(:status, :integer, default: 0)
|
||||
field(:public, :boolean, default: true)
|
||||
field(:thumbnail, :string)
|
||||
field(:large_image, :string)
|
||||
field(:publish_at, Timex.Ecto.DateTimeWithTimezone)
|
||||
field(:uuid, Ecto.UUID, default: Ecto.UUID.generate())
|
||||
field(:address_type, AddressTypeEnum, default: :physical)
|
||||
field(:online_address, :string)
|
||||
field(:phone, :string)
|
||||
belongs_to(:organizer_actor, Actor, foreign_key: :organizer_actor_id)
|
||||
belongs_to(:attributed_to, Actor, foreign_key: :attributed_to_id)
|
||||
many_to_many(:tags, Tag, join_through: "events_tags")
|
||||
belongs_to(:category, Category)
|
||||
many_to_many(:participants, Actor, join_through: Participant)
|
||||
has_many(:tracks, Track)
|
||||
has_many(:sessions, Session)
|
||||
belongs_to(:physical_address, Address)
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
@@ -45,11 +45,13 @@ defmodule Eventos.Events.Event do
|
||||
uuid = Ecto.UUID.generate()
|
||||
|
||||
# TODO : check what's the use here. Tests ?
|
||||
actor_url = if Map.has_key?(attrs, :organizer_actor) do
|
||||
attrs.organizer_actor.preferred_username
|
||||
else
|
||||
""
|
||||
end
|
||||
actor_url =
|
||||
if Map.has_key?(attrs, :organizer_actor) do
|
||||
attrs.organizer_actor.preferred_username
|
||||
else
|
||||
""
|
||||
end
|
||||
|
||||
event
|
||||
|> Ecto.Changeset.cast(attrs, [
|
||||
:title,
|
||||
@@ -67,12 +69,21 @@ defmodule Eventos.Events.Event do
|
||||
:publish_at,
|
||||
:address_type,
|
||||
:online_address,
|
||||
:phone,
|
||||
])
|
||||
:phone
|
||||
])
|
||||
|> cast_assoc(:tags)
|
||||
|> cast_assoc(:physical_address)
|
||||
|> put_change(:uuid, uuid)
|
||||
|> put_change(:url, "#{EventosWeb.Endpoint.url()}/@#{actor_url}/#{uuid}")
|
||||
|> validate_required([:title, :begins_on, :ends_on, :organizer_actor_id, :category_id, :url, :uuid, :address_type])
|
||||
|> validate_required([
|
||||
:title,
|
||||
:begins_on,
|
||||
:ends_on,
|
||||
:organizer_actor_id,
|
||||
:category_id,
|
||||
:url,
|
||||
:uuid,
|
||||
:address_type
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,43 +28,66 @@ defmodule Eventos.Events do
|
||||
def get_events_for_actor(%Actor{id: actor_id} = _actor, page \\ 1, limit \\ 10) do
|
||||
start = (page - 1) * limit
|
||||
|
||||
query = from e in Event,
|
||||
where: e.organizer_actor_id == ^actor_id,
|
||||
limit: ^limit,
|
||||
order_by: [desc: :id],
|
||||
offset: ^start,
|
||||
preload: [:organizer_actor, :category, :sessions, :tracks, :tags, :participants, :physical_address]
|
||||
query =
|
||||
from(
|
||||
e in Event,
|
||||
where: e.organizer_actor_id == ^actor_id,
|
||||
limit: ^limit,
|
||||
order_by: [desc: :id],
|
||||
offset: ^start,
|
||||
preload: [
|
||||
:organizer_actor,
|
||||
:category,
|
||||
:sessions,
|
||||
:tracks,
|
||||
:tags,
|
||||
:participants,
|
||||
:physical_address
|
||||
]
|
||||
)
|
||||
|
||||
events = Repo.all(query)
|
||||
count_events = Repo.one(from e in Event, select: count(e.id), where: e.organizer_actor_id == ^actor_id)
|
||||
|
||||
count_events =
|
||||
Repo.one(from(e in Event, select: count(e.id), where: e.organizer_actor_id == ^actor_id))
|
||||
|
||||
{:ok, events, count_events}
|
||||
end
|
||||
|
||||
def count_local_events do
|
||||
Repo.one(
|
||||
from e in Event,
|
||||
select: count(e.id),
|
||||
where: e.local == ^true
|
||||
from(
|
||||
e in Event,
|
||||
select: count(e.id),
|
||||
where: e.local == ^true
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
def count_local_comments do
|
||||
Repo.one(
|
||||
from c in Comment,
|
||||
select: count(c.id),
|
||||
where: c.local == ^true
|
||||
from(
|
||||
c in Comment,
|
||||
select: count(c.id),
|
||||
where: c.local == ^true
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
import Geo.PostGIS
|
||||
|
||||
def find_close_events(lon, lat, radius \\ 50_000) do # 50 000 meters -> 50 kms
|
||||
# 50 000 meters -> 50 kms
|
||||
def find_close_events(lon, lat, radius \\ 50_000) do
|
||||
ip_point = Geo.WKT.decode("SRID=4326;POINT(#{lon} #{lat})")
|
||||
|
||||
Repo.all(
|
||||
from e in Event,
|
||||
join: a in Address,
|
||||
on: a.id == e.physical_address_id,
|
||||
where: st_dwithin_in_meters(^ip_point, a.geom, ^radius),
|
||||
preload: :organizer_actor
|
||||
from(
|
||||
e in Event,
|
||||
join: a in Address,
|
||||
on: a.id == e.physical_address_id,
|
||||
where: st_dwithin_in_meters(^ip_point, a.geom, ^radius),
|
||||
preload: :organizer_actor
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
@@ -103,7 +126,16 @@ defmodule Eventos.Events do
|
||||
"""
|
||||
def get_event_full!(id) do
|
||||
event = Repo.get!(Event, id)
|
||||
Repo.preload(event, [:organizer_actor, :category, :sessions, :tracks, :tags, :participants, :physical_address])
|
||||
|
||||
Repo.preload(event, [
|
||||
:organizer_actor,
|
||||
:category,
|
||||
:sessions,
|
||||
:tracks,
|
||||
:tags,
|
||||
:participants,
|
||||
:physical_address
|
||||
])
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -111,7 +143,16 @@ defmodule Eventos.Events do
|
||||
"""
|
||||
def get_event_full_by_url!(url) do
|
||||
event = Repo.get_by(Event, url: url)
|
||||
Repo.preload(event, [:organizer_actor, :category, :sessions, :tracks, :tags, :participants, :physical_address])
|
||||
|
||||
Repo.preload(event, [
|
||||
:organizer_actor,
|
||||
:category,
|
||||
:sessions,
|
||||
:tracks,
|
||||
:tags,
|
||||
:participants,
|
||||
:physical_address
|
||||
])
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -119,14 +160,23 @@ defmodule Eventos.Events do
|
||||
"""
|
||||
def get_event_full_by_uuid(uuid) do
|
||||
event = Repo.get_by(Event, uuid: uuid)
|
||||
Repo.preload(event, [:organizer_actor, :category, :sessions, :tracks, :tags, :participants, :physical_address])
|
||||
|
||||
Repo.preload(event, [
|
||||
:organizer_actor,
|
||||
:category,
|
||||
:sessions,
|
||||
:tracks,
|
||||
:tags,
|
||||
:participants,
|
||||
:physical_address
|
||||
])
|
||||
end
|
||||
|
||||
@doc """
|
||||
Find events by name
|
||||
"""
|
||||
def find_events_by_name(name) do
|
||||
events = Repo.all from a in Event, where: ilike(a.title, ^like_sanitize(name))
|
||||
events = Repo.all(from(a in Event, where: ilike(a.title, ^like_sanitize(name))))
|
||||
Repo.preload(events, [:organizer_actor])
|
||||
end
|
||||
|
||||
@@ -154,7 +204,6 @@ defmodule Eventos.Events do
|
||||
{:ok, %Event{} = event} -> {:ok, Repo.preload(event, [:organizer_actor])}
|
||||
err -> err
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -235,7 +284,7 @@ defmodule Eventos.Events do
|
||||
"""
|
||||
def get_category!(id), do: Repo.get!(Category, id)
|
||||
|
||||
@spec get_category_by_title(String.t) :: tuple()
|
||||
@spec get_category_by_title(String.t()) :: tuple()
|
||||
def get_category_by_title(title) when is_binary(title) do
|
||||
Repo.get_by(Category, title: title)
|
||||
end
|
||||
@@ -431,7 +480,7 @@ defmodule Eventos.Events do
|
||||
|
||||
"""
|
||||
def get_participant!(event_id, actor_id) do
|
||||
Repo.get_by!(Participant, [event_id: event_id, actor_id: actor_id])
|
||||
Repo.get_by!(Participant, event_id: event_id, actor_id: actor_id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -500,7 +549,7 @@ defmodule Eventos.Events do
|
||||
end
|
||||
|
||||
def list_requests_for_actor(%Actor{} = actor) do
|
||||
Repo.all(from p in Participant, where: p.actor_id == ^actor.id and p.approved == false)
|
||||
Repo.all(from(p in Participant, where: p.actor_id == ^actor.id and p.approved == false))
|
||||
end
|
||||
|
||||
alias Eventos.Events.Session
|
||||
@@ -523,10 +572,12 @@ defmodule Eventos.Events do
|
||||
"""
|
||||
def list_sessions_for_event(event_uuid) do
|
||||
Repo.all(
|
||||
from s in Session,
|
||||
join: e in Event,
|
||||
on: s.event_id == e.id,
|
||||
where: e.uuid == ^event_uuid
|
||||
from(
|
||||
s in Session,
|
||||
join: e in Event,
|
||||
on: s.event_id == e.id,
|
||||
where: e.uuid == ^event_uuid
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
@@ -534,7 +585,7 @@ defmodule Eventos.Events do
|
||||
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)
|
||||
Repo.all(from(s in Session, where: s.track_id == ^track_id))
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
@@ -9,9 +9,10 @@ defmodule Eventos.Events.Participant do
|
||||
|
||||
@primary_key false
|
||||
schema "participants" do
|
||||
field :role, :integer, default: 0 # 0 : not_approved, 1 : participant, 2 : moderator, 3 : administrator, 4 : creator
|
||||
belongs_to :event, Event, primary_key: true
|
||||
belongs_to :actor, Actor, primary_key: true
|
||||
# 0 : not_approved, 1 : participant, 2 : moderator, 3 : administrator, 4 : creator
|
||||
field(:role, :integer, default: 0)
|
||||
belongs_to(:event, Event, primary_key: true)
|
||||
belongs_to(:actor, Actor, primary_key: true)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@@ -6,20 +6,19 @@ defmodule Eventos.Events.Session do
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Events.{Session, Event, Track}
|
||||
|
||||
|
||||
schema "sessions" do
|
||||
field :audios_urls, :string
|
||||
field :language, :string
|
||||
field :long_abstract, :string
|
||||
field :short_abstract, :string
|
||||
field :slides_url, :string
|
||||
field :subtitle, :string
|
||||
field :title, :string
|
||||
field :videos_urls, :string
|
||||
field :begins_on, Timex.Ecto.DateTimeWithTimezone
|
||||
field :ends_on, Timex.Ecto.DateTimeWithTimezone
|
||||
belongs_to :event, Event
|
||||
belongs_to :track, Track
|
||||
field(:audios_urls, :string)
|
||||
field(:language, :string)
|
||||
field(:long_abstract, :string)
|
||||
field(:short_abstract, :string)
|
||||
field(:slides_url, :string)
|
||||
field(:subtitle, :string)
|
||||
field(:title, :string)
|
||||
field(:videos_urls, :string)
|
||||
field(:begins_on, Timex.Ecto.DateTimeWithTimezone)
|
||||
field(:ends_on, Timex.Ecto.DateTimeWithTimezone)
|
||||
belongs_to(:event, Event)
|
||||
belongs_to(:track, Track)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
@@ -27,7 +26,27 @@ defmodule Eventos.Events.Session do
|
||||
@doc false
|
||||
def changeset(%Session{} = session, attrs) do
|
||||
session
|
||||
|> cast(attrs, [:title, :subtitle, :short_abstract, :long_abstract, :language, :slides_url, :videos_urls, :audios_urls, :event_id, :track_id])
|
||||
|> validate_required([:title, :subtitle, :short_abstract, :long_abstract, :language, :slides_url, :videos_urls, :audios_urls])
|
||||
|> cast(attrs, [
|
||||
:title,
|
||||
:subtitle,
|
||||
:short_abstract,
|
||||
:long_abstract,
|
||||
:language,
|
||||
:slides_url,
|
||||
:videos_urls,
|
||||
:audios_urls,
|
||||
:event_id,
|
||||
:track_id
|
||||
])
|
||||
|> validate_required([
|
||||
:title,
|
||||
:subtitle,
|
||||
:short_abstract,
|
||||
:long_abstract,
|
||||
:language,
|
||||
:slides_url,
|
||||
:videos_urls,
|
||||
:audios_urls
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,11 +13,16 @@ defmodule Eventos.Events.Tag.TitleSlug do
|
||||
end
|
||||
|
||||
defp build_unique_slug(slug, changeset) do
|
||||
query = from t in Tag,
|
||||
where: t.slug == ^slug
|
||||
query =
|
||||
from(
|
||||
t in Tag,
|
||||
where: t.slug == ^slug
|
||||
)
|
||||
|
||||
case Repo.one(query) do
|
||||
nil -> slug
|
||||
nil ->
|
||||
slug
|
||||
|
||||
_story ->
|
||||
slug
|
||||
|> Eventos.Slug.increment_slug()
|
||||
@@ -36,8 +41,8 @@ defmodule Eventos.Events.Tag do
|
||||
alias Eventos.Events.Tag.TitleSlug
|
||||
|
||||
schema "tags" do
|
||||
field :title, :string
|
||||
field :slug, TitleSlug.Type
|
||||
field(:title, :string)
|
||||
field(:slug, TitleSlug.Type)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@@ -6,13 +6,12 @@ defmodule Eventos.Events.Track do
|
||||
import Ecto.Changeset
|
||||
alias Eventos.Events.{Track, Event, Session}
|
||||
|
||||
|
||||
schema "tracks" do
|
||||
field :color, :string
|
||||
field :description, :string
|
||||
field :name, :string
|
||||
belongs_to :event, Event
|
||||
has_many :sessions, Session
|
||||
field(:color, :string)
|
||||
field(:description, :string)
|
||||
field(:name, :string)
|
||||
belongs_to(:event, Event)
|
||||
has_many(:sessions, Session)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user