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
|
|
|
|
|
2021-12-17 16:23:48 +01:00
|
|
|
def push(conn, %{"sender" => sender, "data" => message}) do
|
2021-12-10 15:34:38 +01:00
|
|
|
Messages.push(sender, message)
|
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
|
|
|
|
|
|
|
def firebase(conn, %{"sender" => sender, "token" => token}) do
|
|
|
|
Senders.push(sender, token)
|
|
|
|
text conn, Jason.encode!(%{"status" => "OK"})
|
|
|
|
end
|
2021-12-10 15:34:38 +01:00
|
|
|
end
|