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:
16
lib/myapp_web/controllers/category_controller.ex
Normal file
16
lib/myapp_web/controllers/category_controller.ex
Normal 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
|
||||
22
lib/myapp_web/controllers/reply_controller.ex
Normal file
22
lib/myapp_web/controllers/reply_controller.ex
Normal 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
|
||||
38
lib/myapp_web/controllers/thread_controller.ex
Normal file
38
lib/myapp_web/controllers/thread_controller.ex
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user