raphael
5d50bb30e6
- routing setup with path to message_controller - messages api to database updated to function similar to a stack system (push, pop, peek, ..) - rest calls the same as database calls - setup default controller showing text message - parsing database output with Jason to client - adds curl examples
38 lines
798 B
Elixir
38 lines
798 B
Elixir
defmodule BumpWeb.MessageController do
|
|
use BumpWeb, :controller
|
|
|
|
alias Bump.Messages
|
|
|
|
def index(conn, _params) do
|
|
text conn, "Bump Api"
|
|
end
|
|
|
|
def list(conn, %{"sender" => sender, "minutes" => minutes}) do
|
|
list = Messages.list(sender, String.to_integer(minutes))
|
|
text conn, Jason.encode!(list)
|
|
|
|
end
|
|
|
|
def clear(conn, %{"sender" => sender}) do
|
|
Messages.clear(sender)
|
|
text conn, "OK"
|
|
|
|
end
|
|
|
|
def push(conn, %{"sender" => sender, "message" => message}) do
|
|
Messages.push(sender, message)
|
|
text conn, "OK"
|
|
|
|
end
|
|
|
|
def pop(conn, %{"sender" => sender}) do
|
|
message = Messages.pop(sender)
|
|
text conn, Jason.encode!(message)
|
|
end
|
|
|
|
def peak(conn, %{"sender" => sender}) do
|
|
message = Messages.peak(sender)
|
|
text conn, Jason.encode!(message)
|
|
end
|
|
end
|