mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
Somewhat damaged patch 1 (#19)
* Fix for module placement Correcting my own mistake when I first made these routes * Correcting module location * Correcting module location * Fix Fixes a potential crash when no posts are returned.
This commit is contained in:
parent
0c5e0d7fa7
commit
e918375c83
3 changed files with 11 additions and 5 deletions
|
@ -1,4 +1,4 @@
|
||||||
defmodule PhilomenaWeb.Api.Json.PostController do
|
defmodule PhilomenaWeb.Api.Json.Forum.Topic.PostController do
|
||||||
use PhilomenaWeb, :controller
|
use PhilomenaWeb, :controller
|
||||||
|
|
||||||
alias PhilomenaWeb.PostJson
|
alias PhilomenaWeb.PostJson
|
||||||
|
@ -43,7 +43,13 @@ defmodule PhilomenaWeb.Api.Json.PostController do
|
||||||
|> preload([:user, :topic])
|
|> preload([:user, :topic])
|
||||||
|> preload([_p, t, _f], topic: t)
|
|> preload([_p, t, _f], topic: t)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|
|
||||||
|
case posts do
|
||||||
|
[] ->
|
||||||
|
json(conn, %{posts: Enum.map(posts, &PostJson.as_json/1), page: page})
|
||||||
|
|
||||||
json(conn, %{posts: Enum.map(posts, &PostJson.as_json/1), page: page, total: hd(posts).topic.post_count})
|
_ ->
|
||||||
|
json(conn, %{posts: Enum.map(posts, &PostJson.as_json/1), page: page, total: hd(posts).topic.post_count})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule PhilomenaWeb.Api.Json.TopicController do
|
defmodule PhilomenaWeb.Api.Json.Forum.TopicController do
|
||||||
use PhilomenaWeb, :controller
|
use PhilomenaWeb, :controller
|
||||||
|
|
||||||
alias PhilomenaWeb.TopicJson
|
alias PhilomenaWeb.TopicJson
|
|
@ -116,8 +116,8 @@ defmodule PhilomenaWeb.Router do
|
||||||
resources "/tags", TagController, only: [:show]
|
resources "/tags", TagController, only: [:show]
|
||||||
resources "/comments", CommentController, only: [:show]
|
resources "/comments", CommentController, only: [:show]
|
||||||
resources "/forums", ForumController, only: [:show, :index] do
|
resources "/forums", ForumController, only: [:show, :index] do
|
||||||
resources "/topics", TopicController, only: [:show, :index] do
|
resources "/topics", Forum.TopicController, only: [:show, :index] do
|
||||||
resources "/posts", PostController, only: [:show, :index]
|
resources "/posts", Forum.Topic.PostController, only: [:show, :index]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue