2017-12-08 08:58:14 +00:00
|
|
|
defmodule EventosWeb.EventView do
|
2018-01-14 16:56:50 +00:00
|
|
|
@moduledoc """
|
|
|
|
View for Events
|
|
|
|
"""
|
2017-12-08 08:58:14 +00:00
|
|
|
use EventosWeb, :view
|
2018-01-16 18:45:09 +00:00
|
|
|
alias EventosWeb.{EventView, AccountView, GroupView}
|
2018-01-13 22:33:03 +00:00
|
|
|
|
|
|
|
def render("index.json", %{events: events}) do
|
2018-01-16 18:45:09 +00:00
|
|
|
%{data: render_many(events, EventView, "event_simple.json")}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("show_simple.json", %{event: event}) do
|
|
|
|
%{data: render_one(event, EventView, "event_simple.json")}
|
2018-01-13 22:33:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def render("show.json", %{event: event}) do
|
|
|
|
%{data: render_one(event, EventView, "event.json")}
|
|
|
|
end
|
|
|
|
|
2018-01-16 18:45:09 +00:00
|
|
|
def render("event_simple.json", %{event: event}) do
|
|
|
|
%{id: event.id,
|
|
|
|
title: event.title,
|
|
|
|
description: event.description,
|
|
|
|
begins_on: event.begins_on,
|
|
|
|
ends_on: event.ends_on,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-13 22:33:03 +00:00
|
|
|
def render("event.json", %{event: event}) do
|
|
|
|
%{id: event.id,
|
|
|
|
title: event.title,
|
|
|
|
description: event.description,
|
|
|
|
begins_on: event.begins_on,
|
2018-01-16 18:45:09 +00:00
|
|
|
ends_on: event.ends_on,
|
|
|
|
organizer: render_one(event.organizer_account, AccountView, "acccount_basic.json"),
|
|
|
|
group: render_one(event.organizer_group, GroupView, "group_basic.json"),
|
|
|
|
participants: render_many(event.participants, AccountView, "show_basic.json"),
|
|
|
|
}
|
2018-01-13 22:33:03 +00:00
|
|
|
end
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|