mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-07 23:06:42 +01:00
Somewhat damaged patch 1 (#20)
* Add new route Adding route for `/api/v1/json/posts/:id` * Adding route controller Adding route for `/api/v1/json/posts/:id`
This commit is contained in:
parent
e918375c83
commit
035b887f53
2 changed files with 32 additions and 1 deletions
31
lib/philomena_web/controllers/api/json/post_controller.ex
Normal file
31
lib/philomena_web/controllers/api/json/post_controller.ex
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
defmodule PhilomenaWeb.Api.Json.PostController do
|
||||||
|
use PhilomenaWeb, :controller
|
||||||
|
|
||||||
|
alias PhilomenaWeb.PostJson
|
||||||
|
alias Philomena.Posts.Post
|
||||||
|
alias Philomena.Repo
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
def show(conn, %{"id" => post_id}) do
|
||||||
|
post =
|
||||||
|
Post
|
||||||
|
|> join(:inner, [p], _ in assoc(p, :topic))
|
||||||
|
|> join(:inner, [_p, t], _ in assoc(t, :forum))
|
||||||
|
|> where(id: ^post_id)
|
||||||
|
|> where(destroyed_content: false)
|
||||||
|
|> where([_p, t], t.hidden_from_users == false)
|
||||||
|
|> where([_p, _t, f], f.access_level == "normal")
|
||||||
|
|> preload([:user, :topic])
|
||||||
|
|> Repo.one()
|
||||||
|
|
||||||
|
cond do
|
||||||
|
is_nil(post) ->
|
||||||
|
conn
|
||||||
|
|> put_status(:not_found)
|
||||||
|
|> text("")
|
||||||
|
|
||||||
|
true ->
|
||||||
|
json(conn, %{post: PostJson.as_json(post)})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -115,12 +115,12 @@ defmodule PhilomenaWeb.Router do
|
||||||
resources "/oembed", OembedController, only: [:index]
|
resources "/oembed", OembedController, only: [:index]
|
||||||
resources "/tags", TagController, only: [:show]
|
resources "/tags", TagController, only: [:show]
|
||||||
resources "/comments", CommentController, only: [:show]
|
resources "/comments", CommentController, only: [:show]
|
||||||
|
resources "/posts", PostController, only: [:show]
|
||||||
resources "/forums", ForumController, only: [:show, :index] do
|
resources "/forums", ForumController, only: [:show, :index] do
|
||||||
resources "/topics", Forum.TopicController, only: [:show, :index] do
|
resources "/topics", Forum.TopicController, only: [:show, :index] do
|
||||||
resources "/posts", Forum.Topic.PostController, only: [:show, :index]
|
resources "/posts", Forum.Topic.PostController, only: [:show, :index]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/", PhilomenaWeb do
|
scope "/", PhilomenaWeb do
|
||||||
|
|
Loading…
Reference in a new issue