mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-12 01:52:49 +00:00
server - repo associations figured out with thread/reply/user
This commit is contained in:
@@ -5,10 +5,20 @@ defmodule MyAppWeb.CategoryController do
|
||||
|
||||
@spec get_collection(map, map) :: any
|
||||
def get_collection(conn, _params) do
|
||||
output = Data.Category.get_categories()
|
||||
output = get_categories()
|
||||
conn
|
||||
|> put_status(200)
|
||||
|> Response.json(output)
|
||||
end
|
||||
|
||||
# cache categories end point because the data won't change after server start
|
||||
defp get_categories() do
|
||||
case Cachex.get(:myapp, "categories") do
|
||||
{:ok, data} -> data
|
||||
{:missing, _} ->
|
||||
data = Data.Category.get_categories()
|
||||
Cachex.set(:myapp, "categories", data)
|
||||
data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ defmodule MyAppWeb.ReplyController do
|
||||
|
||||
{output, status} = params
|
||||
|> Map.put("user_id", user_id)
|
||||
|> Data.Reply.insert_reply
|
||||
|> Data.Reply.insert
|
||||
|> Response.put_resp
|
||||
|
||||
conn
|
||||
@@ -27,7 +27,7 @@ defmodule MyAppWeb.ReplyController do
|
||||
|
||||
{output, status} = params
|
||||
|> Map.put("user_id", user_id)
|
||||
|> Data.Reply.user_update_reply
|
||||
|> Data.Reply.user_update
|
||||
|> Response.put_resp
|
||||
|
||||
conn
|
||||
|
||||
@@ -11,7 +11,7 @@ defmodule MyAppWeb.ThreadController do
|
||||
|
||||
{output, status} = params
|
||||
|> Map.put("user_id", user_id)
|
||||
|> Data.Thread.insert_thread
|
||||
|> Data.Thread.insert
|
||||
|> Response.put_resp
|
||||
|
||||
conn
|
||||
@@ -27,7 +27,7 @@ defmodule MyAppWeb.ThreadController do
|
||||
|
||||
{output, status} = params
|
||||
|> Map.put("user_id", user_id)
|
||||
|> Data.Thread.user_update_thread
|
||||
|> Data.Thread.user_update
|
||||
|> Response.put_resp
|
||||
|
||||
conn
|
||||
@@ -35,4 +35,28 @@ defmodule MyAppWeb.ThreadController do
|
||||
|> Response.json(output)
|
||||
end
|
||||
|
||||
@spec get_collection(map, map) :: any
|
||||
def get_collection(conn, params) do
|
||||
|
||||
{output, status} = params["category_id"]
|
||||
|> Data.Thread.get_collection
|
||||
|> Response.put_resp
|
||||
|
||||
conn
|
||||
|> put_status(status)
|
||||
|> Response.json(output)
|
||||
end
|
||||
|
||||
@spec get(map, map) :: any
|
||||
def get(conn, params) do
|
||||
|
||||
{output, status} = params["id"]
|
||||
|> Data.Thread.get
|
||||
|> Response.put_resp
|
||||
|
||||
conn
|
||||
|> put_status(status)
|
||||
|> Response.json(output)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -36,6 +36,9 @@ defmodule MyAppWeb.Router do
|
||||
end
|
||||
|
||||
scope "/thread" do
|
||||
get "/", ThreadController, :get_collection
|
||||
get "/:id", ThreadController, :get
|
||||
|
||||
# authenticated routes
|
||||
pipe_through [:user_auth]
|
||||
post "/", ThreadController, :insert
|
||||
|
||||
Reference in New Issue
Block a user