init commit

This commit is contained in:
2024-07-13 15:12:19 -04:00
commit 8668405143
61 changed files with 3123 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
defmodule HereIAm.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 = [
HereIAmWeb.Telemetry,
HereIAm.Repo,
{DNSCluster, query: Application.get_env(:here_i_am, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: HereIAm.PubSub},
# Start the Finch HTTP client for sending emails
{Finch, name: HereIAm.Finch},
# Start a worker by calling: HereIAm.Worker.start_link(arg)
# {HereIAm.Worker, arg},
# Start to serve requests, typically the last entry
HereIAmWeb.Endpoint
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: HereIAm.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
HereIAmWeb.Endpoint.config_change(changed, removed)
:ok
end
end

104
lib/here_i_am/devices.ex Normal file
View File

@@ -0,0 +1,104 @@
defmodule HereIAm.Devices do
@moduledoc """
The Devices context.
"""
import Ecto.Query, warn: false
alias HereIAm.Repo
alias HereIAm.Devices.Device
@doc """
Returns the list of devices.
## Examples
iex> list_devices()
[%Device{}, ...]
"""
def list_devices do
Repo.all(Device)
end
@doc """
Gets a single device.
Raises `Ecto.NoResultsError` if the Device does not exist.
## Examples
iex> get_device!(123)
%Device{}
iex> get_device!(456)
** (Ecto.NoResultsError)
"""
def get_device!(id), do: Repo.get!(Device, id)
@doc """
Creates a device.
## Examples
iex> create_device(%{field: value})
{:ok, %Device{}}
iex> create_device(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_device(attrs \\ %{}) do
%Device{}
|> Device.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a device.
## Examples
iex> update_device(device, %{field: new_value})
{:ok, %Device{}}
iex> update_device(device, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_device(%Device{} = device, attrs) do
device
|> Device.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a device.
## Examples
iex> delete_device(device)
{:ok, %Device{}}
iex> delete_device(device)
{:error, %Ecto.Changeset{}}
"""
def delete_device(%Device{} = device) do
Repo.delete(device)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking device changes.
## Examples
iex> change_device(device)
%Ecto.Changeset{data: %Device{}}
"""
def change_device(%Device{} = device, attrs \\ %{}) do
Device.changeset(device, attrs)
end
end

View File

@@ -0,0 +1,18 @@
defmodule HereIAm.Devices.Device do
use Ecto.Schema
import Ecto.Changeset
schema "devices" do
field :ip_address, :string
field :audio, :string
timestamps(type: :utc_datetime)
end
@doc false
def changeset(device, attrs) do
device
|> cast(attrs, [:ip_address, :audio])
|> validate_required([:ip_address, :audio])
end
end

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

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

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

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