2021-12-10 15:34:38 +01:00
|
|
|
defmodule BumpWeb.MessageController do
|
|
|
|
use BumpWeb, :controller
|
|
|
|
|
|
|
|
alias Bump.Messages
|
2021-12-30 16:11:53 +01:00
|
|
|
alias Bump.Senders
|
2021-12-10 15:34:38 +01:00
|
|
|
|
|
|
|
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))
|
2021-12-17 16:23:48 +01:00
|
|
|
text conn, Jason.encode!(%{"messages" => list})
|
2021-12-10 15:34:38 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def clear(conn, %{"sender" => sender}) do
|
|
|
|
Messages.clear(sender)
|
2021-12-17 16:23:48 +01:00
|
|
|
text conn, Jason.encode!(%{"status" => "OK"})
|
2021-12-10 15:34:38 +01:00
|
|
|
end
|
|
|
|
|
2022-01-03 13:07:33 +01:00
|
|
|
|
|
|
|
def push(conn, %{"sender" => sender, "title"=> title, "data" => data}) do
|
|
|
|
Messages.push(sender, title, data)
|
2021-12-17 16:23:48 +01:00
|
|
|
text conn, Jason.encode!(%{"status" => "OK"})
|
2021-12-10 15:34:38 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def pop(conn, %{"sender" => sender}) do
|
|
|
|
message = Messages.pop(sender)
|
|
|
|
text conn, Jason.encode!(message)
|
|
|
|
end
|
|
|
|
|
2021-12-17 16:23:48 +01:00
|
|
|
def peek(conn, %{"sender" => sender}) do
|
|
|
|
message = Messages.peek(sender)
|
2021-12-10 15:34:38 +01:00
|
|
|
text conn, Jason.encode!(message)
|
|
|
|
end
|
2021-12-30 16:11:53 +01:00
|
|
|
|
2021-12-10 15:34:38 +01:00
|
|
|
end
|