forked from rauversion/rauversion-phx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
track comments model (rauversion#22)
* track comments model * track comments form on track show * append comments, comments component
- Loading branch information
Showing
12 changed files
with
399 additions
and
99 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
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,104 @@ | ||
defmodule Rauversion.TrackComments do | ||
@moduledoc """ | ||
The TrackComments context. | ||
""" | ||
|
||
import Ecto.Query, warn: false | ||
alias Rauversion.Repo | ||
|
||
alias Rauversion.TrackComments.TrackComment | ||
|
||
@doc """ | ||
Returns the list of track_comments. | ||
## Examples | ||
iex> list_track_comments() | ||
[%TrackComment{}, ...] | ||
""" | ||
def list_track_comments do | ||
Repo.all(TrackComment) | ||
end | ||
|
||
@doc """ | ||
Gets a single track_comment. | ||
Raises `Ecto.NoResultsError` if the Track comment does not exist. | ||
## Examples | ||
iex> get_track_comment!(123) | ||
%TrackComment{} | ||
iex> get_track_comment!(456) | ||
** (Ecto.NoResultsError) | ||
""" | ||
def get_track_comment!(id), do: Repo.get!(TrackComment, id) | ||
|
||
@doc """ | ||
Creates a track_comment. | ||
## Examples | ||
iex> create_track_comment(%{field: value}) | ||
{:ok, %TrackComment{}} | ||
iex> create_track_comment(%{field: bad_value}) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def create_track_comment(attrs \\ %{}) do | ||
%TrackComment{} | ||
|> TrackComment.changeset(attrs) | ||
|> Repo.insert() | ||
end | ||
|
||
@doc """ | ||
Updates a track_comment. | ||
## Examples | ||
iex> update_track_comment(track_comment, %{field: new_value}) | ||
{:ok, %TrackComment{}} | ||
iex> update_track_comment(track_comment, %{field: bad_value}) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def update_track_comment(%TrackComment{} = track_comment, attrs) do | ||
track_comment | ||
|> TrackComment.changeset(attrs) | ||
|> Repo.update() | ||
end | ||
|
||
@doc """ | ||
Deletes a track_comment. | ||
## Examples | ||
iex> delete_track_comment(track_comment) | ||
{:ok, %TrackComment{}} | ||
iex> delete_track_comment(track_comment) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def delete_track_comment(%TrackComment{} = track_comment) do | ||
Repo.delete(track_comment) | ||
end | ||
|
||
@doc """ | ||
Returns an `%Ecto.Changeset{}` for tracking track_comment changes. | ||
## Examples | ||
iex> change_track_comment(track_comment) | ||
%Ecto.Changeset{data: %TrackComment{}} | ||
""" | ||
def change_track_comment(%TrackComment{} = track_comment, attrs \\ %{}) do | ||
TrackComment.changeset(track_comment, attrs) | ||
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,24 @@ | ||
defmodule Rauversion.TrackComments.TrackComment do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
schema "track_comments" do | ||
field :body, :string | ||
field :state, :string | ||
field :track_minute, :integer | ||
# field :user_id, :id | ||
# field :track_id, :id | ||
|
||
belongs_to :user, Rauversion.Accounts.User | ||
belongs_to :track, Rauversion.Tracks.Track | ||
|
||
timestamps() | ||
end | ||
|
||
@doc false | ||
def changeset(track_comment, attrs) do | ||
track_comment | ||
|> cast(attrs, [:user_id, :track_id, :body, :track_minute, :state]) | ||
|> validate_required([:user_id, :track_id, :body]) | ||
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
Oops, something went wrong.