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
This commit is contained in:
parent
745b0dc4f2
commit
60888fd63c
@ -1,6 +1,7 @@
|
||||
defmodule Bump.Database do
|
||||
alias Bump.Repo
|
||||
alias Bump.Messages.Message
|
||||
alias Bump.Senders.Sender
|
||||
import Ecto.Query
|
||||
|
||||
def pop(sender) do
|
||||
@ -58,5 +59,8 @@ defmodule Bump.Database do
|
||||
|
||||
end
|
||||
|
||||
def addSender(sender, %{"firebase" => firebase}) do
|
||||
Repo.insert(%Sender{sender: sender, firebase_token: firebase})
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -3,7 +3,7 @@ defmodule Bump.Messages do
|
||||
alias Bump.Firebase
|
||||
|
||||
def pop(sender) do
|
||||
Database.pop(sender)
|
||||
Database.pop(sender)
|
||||
end
|
||||
|
||||
def peek(sender) do
|
||||
|
12
lib/bump/senders.ex
Normal file
12
lib/bump/senders.ex
Normal file
@ -0,0 +1,12 @@
|
||||
defmodule Bump.Senders do
|
||||
alias Bump.Database
|
||||
|
||||
def firebase(sender, firebase) do
|
||||
Database.addSender(sender, %{"firebase" => firebase})
|
||||
end
|
||||
|
||||
def peek(sender) do
|
||||
Database.peek(sender)
|
||||
end
|
||||
|
||||
end
|
18
lib/bump/senders/sender.ex
Normal file
18
lib/bump/senders/sender.ex
Normal file
@ -0,0 +1,18 @@
|
||||
defmodule Bump.Senders.Sender do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "senders" do
|
||||
field :sender, :string
|
||||
field :firebase_token, :string, default: ""
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(sender, params) do
|
||||
sender
|
||||
|> cast(params, [:sender, :firebase_token])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@ defmodule BumpWeb.MessageController do
|
||||
use BumpWeb, :controller
|
||||
|
||||
alias Bump.Messages
|
||||
alias Bump.Senders
|
||||
|
||||
def index(conn, _params) do
|
||||
text conn, "Bump Api"
|
||||
@ -34,4 +35,9 @@ defmodule BumpWeb.MessageController 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
|
||||
|
10
lib/bump_web/controllers/sender_controller.ex
Normal file
10
lib/bump_web/controllers/sender_controller.ex
Normal file
@ -0,0 +1,10 @@
|
||||
defmodule BumpWeb.SenderController do
|
||||
use BumpWeb, :controller
|
||||
|
||||
alias Bump.Senders
|
||||
|
||||
def firebase(conn, %{"sender" => sender, "token" => token}) do
|
||||
Senders.firebase(sender, token)
|
||||
text conn, Jason.encode!(%{"status" => "OK"})
|
||||
end
|
||||
end
|
@ -12,6 +12,7 @@ defmodule BumpWeb.Router do
|
||||
post "/pop", MessageController, :pop
|
||||
post "/list", MessageController, :list
|
||||
post "/clear", MessageController, :clear
|
||||
post "/firebase", SenderController, :firebase
|
||||
end
|
||||
|
||||
|
||||
|
13
priv/repo/migrations/20211230132931_add_senders.exs
Normal file
13
priv/repo/migrations/20211230132931_add_senders.exs
Normal file
@ -0,0 +1,13 @@
|
||||
defmodule Bump.Repo.Migrations.AddSenders do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table :senders do
|
||||
|
||||
add :sender, :string, size: 255, null: false
|
||||
add :firebase_token, :string, size: 2048
|
||||
|
||||
timestamps([type: :utc_datetime])
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user