Change models, new migrations, fix front and make tests work
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -1,15 +1,39 @@
|
||||
defmodule EventosWeb.AccountView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.AccountView
|
||||
|
||||
def render("account.json", %{"account": account}) do
|
||||
%{
|
||||
def render("index.json", %{accounts: accounts}) do
|
||||
%{data: render_many(accounts, AccountView, "account_for_user.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{account: account}) do
|
||||
%{data: render_one(account, AccountView, "account.json")}
|
||||
end
|
||||
|
||||
def render("account_for_user.json", %{account: account}) do
|
||||
%{id: account.id,
|
||||
username: account.username,
|
||||
description: account.description,
|
||||
display_name: account.display_name,
|
||||
domain: account.domain,
|
||||
display_name: account.display_name,
|
||||
description: account.description,
|
||||
public_key: account.public_key,
|
||||
suspended: account.suspended,
|
||||
uri: account.uri,
|
||||
url: account.url,
|
||||
}
|
||||
end
|
||||
|
||||
def render("account.json", %{account: account}) do
|
||||
%{id: account.id,
|
||||
username: account.username,
|
||||
domain: account.domain,
|
||||
display_name: account.display_name,
|
||||
description: account.description,
|
||||
public_key: account.public_key,
|
||||
suspended: account.suspended,
|
||||
uri: account.uri,
|
||||
url: account.url,
|
||||
organized_events: account.organized_events
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
defmodule EventosWeb.AppView do
|
||||
use EventosWeb, :view
|
||||
end
|
||||
@@ -1,3 +1,19 @@
|
||||
defmodule EventosWeb.CategoryView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.CategoryView
|
||||
|
||||
def render("index.json", %{categories: categories}) do
|
||||
%{data: render_many(categories, CategoryView, "category.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{category: category}) do
|
||||
%{data: render_one(category, CategoryView, "category.json")}
|
||||
end
|
||||
|
||||
def render("category.json", %{category: category}) do
|
||||
%{id: category.id,
|
||||
title: category.title,
|
||||
description: category.description,
|
||||
picture: category.picture}
|
||||
end
|
||||
end
|
||||
|
||||
19
lib/eventos_web/views/changeset_view.ex
Normal file
19
lib/eventos_web/views/changeset_view.ex
Normal file
@@ -0,0 +1,19 @@
|
||||
defmodule EventosWeb.ChangesetView do
|
||||
use EventosWeb, :view
|
||||
|
||||
@doc """
|
||||
Traverses and translates changeset errors.
|
||||
|
||||
See `Ecto.Changeset.traverse_errors/2` and
|
||||
`EventosWeb.ErrorHelpers.translate_error/1` for more details.
|
||||
"""
|
||||
def translate_errors(changeset) do
|
||||
Ecto.Changeset.traverse_errors(changeset, &translate_error/1)
|
||||
end
|
||||
|
||||
def render("error.json", %{changeset: changeset}) do
|
||||
# When encoded, the changeset returns its errors
|
||||
# as a JSON object. So we just pass it forward.
|
||||
%{errors: translate_errors(changeset)}
|
||||
end
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
defmodule EventosWeb.EventAccountsView do
|
||||
use EventosWeb, :view
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
defmodule EventosWeb.EventRequestView do
|
||||
use EventosWeb, :view
|
||||
end
|
||||
@@ -1,3 +1,20 @@
|
||||
defmodule EventosWeb.EventView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.EventView
|
||||
|
||||
def render("index.json", %{events: events}) do
|
||||
%{data: render_many(events, EventView, "event.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{event: event}) do
|
||||
%{data: render_one(event, EventView, "event.json")}
|
||||
end
|
||||
|
||||
def render("event.json", %{event: event}) do
|
||||
%{id: event.id,
|
||||
title: event.title,
|
||||
description: event.description,
|
||||
begins_on: event.begins_on,
|
||||
ends_on: event.ends_on}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
defmodule EventosWeb.GroupAccountView do
|
||||
use EventosWeb, :view
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
defmodule EventosWeb.GroupRequestView do
|
||||
use EventosWeb, :view
|
||||
end
|
||||
@@ -1,3 +1,21 @@
|
||||
defmodule EventosWeb.GroupView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.GroupView
|
||||
|
||||
def render("index.json", %{groups: groups}) do
|
||||
%{data: render_many(groups, GroupView, "group.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{group: group}) do
|
||||
%{data: render_one(group, GroupView, "group.json")}
|
||||
end
|
||||
|
||||
def render("group.json", %{group: group}) do
|
||||
%{id: group.id,
|
||||
title: group.title,
|
||||
description: group.description,
|
||||
suspended: group.suspended,
|
||||
url: group.url,
|
||||
uri: group.uri}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
defmodule EventosWeb.LayoutView do
|
||||
use EventosWeb, :view
|
||||
end
|
||||
17
lib/eventos_web/views/member_view.ex
Normal file
17
lib/eventos_web/views/member_view.ex
Normal file
@@ -0,0 +1,17 @@
|
||||
defmodule EventosWeb.MemberView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.MemberView
|
||||
|
||||
def render("index.json", %{members: members}) do
|
||||
%{data: render_many(members, MemberView, "member.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{member: member}) do
|
||||
%{data: render_one(member, MemberView, "member.json")}
|
||||
end
|
||||
|
||||
def render("member.json", %{member: member}) do
|
||||
%{id: member.id,
|
||||
role: member.role}
|
||||
end
|
||||
end
|
||||
17
lib/eventos_web/views/participant_view.ex
Normal file
17
lib/eventos_web/views/participant_view.ex
Normal file
@@ -0,0 +1,17 @@
|
||||
defmodule EventosWeb.ParticipantView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.ParticipantView
|
||||
|
||||
def render("index.json", %{participants: participants}) do
|
||||
%{data: render_many(participants, ParticipantView, "participant.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{participant: participant}) do
|
||||
%{data: render_one(participant, ParticipantView, "participant.json")}
|
||||
end
|
||||
|
||||
def render("participant.json", %{participant: participant}) do
|
||||
%{id: participant.id,
|
||||
role: participant.role}
|
||||
end
|
||||
end
|
||||
17
lib/eventos_web/views/request_view.ex
Normal file
17
lib/eventos_web/views/request_view.ex
Normal file
@@ -0,0 +1,17 @@
|
||||
defmodule EventosWeb.RequestView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.RequestView
|
||||
|
||||
def render("index.json", %{requests: requests}) do
|
||||
%{data: render_many(requests, RequestView, "request.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{request: request}) do
|
||||
%{data: render_one(request, RequestView, "request.json")}
|
||||
end
|
||||
|
||||
def render("request.json", %{request: request}) do
|
||||
%{id: request.id,
|
||||
state: request.state}
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,24 @@
|
||||
defmodule EventosWeb.SessionView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.SessionView
|
||||
|
||||
def render("token.json", %{token: token, user: user}) do
|
||||
%{token: token, user: render_one(user, EventosWeb.UserView, "user.json")}
|
||||
def render("index.json", %{sessions: sessions}) do
|
||||
%{data: render_many(sessions, SessionView, "session.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{session: session}) do
|
||||
%{data: render_one(session, SessionView, "session.json")}
|
||||
end
|
||||
|
||||
def render("session.json", %{session: session}) do
|
||||
%{id: session.id,
|
||||
title: session.title,
|
||||
subtitle: session.subtitle,
|
||||
short_abstract: session.short_abstract,
|
||||
long_abstract: session.long_abstract,
|
||||
language: session.language,
|
||||
slides_url: session.slides_url,
|
||||
videos_urls: session.videos_urls,
|
||||
audios_urls: session.audios_urls}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
defmodule EventosWeb.TagView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.TagView
|
||||
|
||||
def render("index.json", %{tags: tags}) do
|
||||
%{data: render_many(tags, TagView, "tag.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{tag: tag}) do
|
||||
%{data: render_one(tag, TagView, "tag.json")}
|
||||
end
|
||||
|
||||
def render("tag.json", %{tag: tag}) do
|
||||
%{id: tag.id,
|
||||
title: tag.title}
|
||||
end
|
||||
end
|
||||
|
||||
19
lib/eventos_web/views/track_view.ex
Normal file
19
lib/eventos_web/views/track_view.ex
Normal file
@@ -0,0 +1,19 @@
|
||||
defmodule EventosWeb.TrackView do
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.TrackView
|
||||
|
||||
def render("index.json", %{tracks: tracks}) do
|
||||
%{data: render_many(tracks, TrackView, "track.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{track: track}) do
|
||||
%{data: render_one(track, TrackView, "track.json")}
|
||||
end
|
||||
|
||||
def render("track.json", %{track: track}) do
|
||||
%{id: track.id,
|
||||
name: track.name,
|
||||
description: track.description,
|
||||
color: track.color}
|
||||
end
|
||||
end
|
||||
7
lib/eventos_web/views/user_session_view.ex
Normal file
7
lib/eventos_web/views/user_session_view.ex
Normal file
@@ -0,0 +1,7 @@
|
||||
defmodule EventosWeb.UserSessionView do
|
||||
use EventosWeb, :view
|
||||
|
||||
def render("token.json", %{token: token, user: user}) do
|
||||
%{token: token, user: render_one(user, EventosWeb.UserView, "user_simple.json")}
|
||||
end
|
||||
end
|
||||
@@ -1,11 +1,45 @@
|
||||
defmodule EventosWeb.UserView do
|
||||
use EventosWeb, :view
|
||||
import Logger
|
||||
alias EventosWeb.UserView
|
||||
alias EventosWeb.AccountView
|
||||
|
||||
def render("user.json", %{"user": user}) do
|
||||
def render("index.json", %{users: users}) do
|
||||
%{data: render_many(users, UserView, "user_simple.json")}
|
||||
end
|
||||
|
||||
def render("show.json", %{user: user}) do
|
||||
%{data: render_one(user, UserView, "user.json")}
|
||||
end
|
||||
|
||||
def render("show_simple.json", %{user: user}) do
|
||||
%{data: render_one(user, UserView, "user_simple.json")}
|
||||
end
|
||||
|
||||
def render("show_with_token.json", %{user: user, token: token}) do
|
||||
%{
|
||||
user: render_one(user, UserView, "user_simple.json"),
|
||||
token: token
|
||||
}
|
||||
end
|
||||
|
||||
def render("user_simple.json", %{user: user}) do
|
||||
%{id: user.id,
|
||||
role: user.role,
|
||||
account: render_one(user.account, AccountView, "account_for_user.json")
|
||||
}
|
||||
end
|
||||
|
||||
def render("user.json", %{user: user}) do
|
||||
%{id: user.id,
|
||||
role: user.role,
|
||||
account: render_one(user.account, AccountView, "account.json")
|
||||
}
|
||||
end
|
||||
|
||||
def render("user_private.json", %{user: user}) do
|
||||
%{id: user.id,
|
||||
email: user.email,
|
||||
account: render_one(user.account, EventosWeb.AccountView, "account.json"),
|
||||
role: user.role,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user