adds phoenix boilerplate and database api

- message communication added
- database migration added
- initial commit
This commit is contained in:
2021-12-05 00:36:13 +01:00
commit 4e607a7e45
50 changed files with 1817 additions and 0 deletions

36
lib/bump/application.ex Normal file
View File

@ -0,0 +1,36 @@
defmodule Bump.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
@impl true
def start(_type, _args) do
children = [
# Start the Ecto repository
Bump.Repo,
# Start the Telemetry supervisor
BumpWeb.Telemetry,
# Start the PubSub system
{Phoenix.PubSub, name: Bump.PubSub},
# Start the Endpoint (http/https)
BumpWeb.Endpoint
# Start a worker by calling: Bump.Worker.start_link(arg)
# {Bump.Worker, arg}
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Bump.Supervisor]
Supervisor.start_link(children, opts)
end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
@impl true
def config_change(changed, _new, removed) do
BumpWeb.Endpoint.config_change(changed, removed)
:ok
end
end

3
lib/bump/mailer.ex Normal file
View File

@ -0,0 +1,3 @@
defmodule Bump.Mailer do
use Swoosh.Mailer, otp_app: :bump
end

27
lib/bump/messages.ex Normal file
View File

@ -0,0 +1,27 @@
defmodule Bump.Messages do
alias Bump.Repo
import Ecto.Query
def get_newest_message(_sender) do
end
def get_all_messages_since(sender, minutes) do
ago = DateTime.utc_now
|> Timex.shift(minutes: -minutes)
|> DateTime.truncate(:second)
query = from m in "messages",
where: m.sender == ^sender and
m.timestamp >= ^ago,
select: m.data
Repo.all(query)
end
def remove_sender(_sender) do
end
def add_message(_sender, _message) do
end
end

View File

@ -0,0 +1,20 @@
defmodule Bump.Messages.Message do
use Ecto.Schema
import Ecto.Changeset
schema "messages" do
field :sender, :string
field :data, :string, default: ""
field :timestamp, :utc_datetime, default: DateTime.utc_now |> DateTime.truncate(:second)
timestamps()
end
def changeset(message, params) do
message
|> cast(params, [:sender, :data, :timestamp])
end
end

5
lib/bump/repo.ex Normal file
View File

@ -0,0 +1,5 @@
defmodule Bump.Repo do
use Ecto.Repo,
otp_app: :bump,
adapter: Ecto.Adapters.Postgres
end