-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cf7c82
commit 5ab9017
Showing
16 changed files
with
131 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
defmodule ChatService do | ||
@moduledoc """ | ||
ChatService keeps the contexts that define your domain | ||
and business logic. | ||
The ChatService supervision tree is in chatservice/application.ex | ||
Contexts are also responsible for managing your data, regardless | ||
if it comes from the database, an external API or others. | ||
""" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule ChatService.ChatContext do | ||
@moduledoc """ | ||
The database/persistence context | ||
""" | ||
|
||
import Ecto.Query, warn: false | ||
alias ChatService.Repo | ||
|
||
alias ChatService.ChatContext.Message | ||
|
||
def list_messages(topic) do | ||
Message | ||
|> where(topic: ^topic) | ||
|> Repo.all() | ||
end | ||
|
||
def create_message(attrs \\ %{}) do | ||
%Message{} | ||
|> Message.changeset(attrs) | ||
|> Repo.insert() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule ChatService.ChatContext.Message do | ||
@derive {Jason.Encoder, only: [:name, :message, :inserted_at, :topic]} | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
schema "messages" do | ||
field :topic, :string | ||
field :name, :string | ||
field :message, :string | ||
|
||
timestamps(type: :utc_datetime) | ||
end | ||
|
||
@doc false | ||
def changeset(message, attrs) do | ||
message | ||
|> cast(attrs, [:topic, :name, :message]) | ||
|> validate_required([:topic, :name, :message]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.