bump_server/lib/bump_web/controllers/message_controller.ex
raphael 60888fd63c adds senders to database and firebase connect
- senders, which now have a firebase token
  are added as their own table in the database
- firebase token api call added, which allows
  a user to connect a sender id to a firebase token
- firebase library not yet connected to the saved
  firebase tokens
2021-12-30 16:11:53 +01:00

44 lines
1.0 KiB
Elixir

defmodule BumpWeb.MessageController do
use BumpWeb, :controller
alias Bump.Messages
alias Bump.Senders
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!(%{"messages" => list})
end
def clear(conn, %{"sender" => sender}) do
Messages.clear(sender)
text conn, Jason.encode!(%{"status" => "OK"})
end
def push(conn, %{"sender" => sender, "data" => message}) do
Messages.push(sender, message)
text conn, Jason.encode!(%{"status" => "OK"})
end
def pop(conn, %{"sender" => sender}) do
message = Messages.pop(sender)
text conn, Jason.encode!(message)
end
def peek(conn, %{"sender" => sender}) do
message = Messages.peek(sender)
text conn, Jason.encode!(message)
end
def firebase(conn, %{"sender" => sender, "token" => token}) do
Senders.push(sender, token)
text conn, Jason.encode!(%{"status" => "OK"})
end
end