1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-12 01:52:49 +00:00

lots of things done: thread - reply - category - seeds

This commit is contained in:
2018-01-02 23:38:17 -06:00
parent 3a61151191
commit 115dacdd12
15 changed files with 291 additions and 27 deletions

View File

@@ -0,0 +1,16 @@
defmodule MyAppWeb.CategoryController do
use MyAppWeb, :controller
alias MyAppWeb.Response
alias MyApp.Data
@spec get_collection(map, map) :: any
def get_collection(conn, _params) do
output = Data.Category.get_categories()
conn
|> put_status(200)
|> Response.json(output)
end
end

View File

@@ -0,0 +1,22 @@
defmodule MyAppWeb.ReplyController do
use MyAppWeb, :controller
alias MyAppWeb.Response
alias MyApp.Data
@spec insert(map, map) :: any
def insert(conn, params) do
user_id = conn
|> MyApp.Guardian.Plug.current_claims
|> Map.get("id")
{output, status} = params
|> Map.put("user_id", user_id)
|> Data.Reply.insert_reply
|> Response.put_resp
conn
|> put_status(status)
|> Response.json(output)
end
end

View File

@@ -0,0 +1,38 @@
defmodule MyAppWeb.ThreadController do
use MyAppWeb, :controller
alias MyAppWeb.Response
alias MyApp.Data
@spec insert(map, map) :: any
def insert(conn, params) do
user_id = conn
|> MyApp.Guardian.Plug.current_claims
|> Map.get("id")
{output, status} = params
|> Map.put("user_id", user_id)
|> Data.Thread.insert_thread
|> Response.put_resp
conn
|> put_status(status)
|> Response.json(output)
end
@spec update(map, map) :: any
def update(conn, params) do
user_id = conn
|> MyApp.Guardian.Plug.current_claims
|> Map.get("id")
{output, status} = params
|> Map.put("user_id", user_id)
|> Data.Thread.update_thread
|> Response.put_resp
conn
|> put_status(status)
|> Response.json(output)
end
end

View File

@@ -26,6 +26,23 @@ defmodule MyAppWeb.Router do
pipe_through [:api_auth]
get "/", UserController, :index
end
scope "/thread" do
# authenticated routes
pipe_through [:api_auth]
post "/", ThreadController, :insert
put "/", ThreadController, :update
end
scope "reply" do
# authenticated routes
pipe_through [:api_auth]
post "/", ReplyController, :insert
end
scope "/category" do
get "/", CategoryController, :get_collection
end
end
end