After "mix phx.gen.json BiddingRounds BiddingRound bidding_rounds round_number:integer running:boolean --no-scope".
This commit is contained in:
104
lib/beet_round_server/bidding_rounds.ex
Normal file
104
lib/beet_round_server/bidding_rounds.ex
Normal file
@ -0,0 +1,104 @@
|
||||
defmodule BeetRoundServer.BiddingRounds do
|
||||
@moduledoc """
|
||||
The BiddingRounds context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias BeetRoundServer.Repo
|
||||
|
||||
alias BeetRoundServer.BiddingRounds.BiddingRound
|
||||
|
||||
@doc """
|
||||
Returns the list of bidding_rounds.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_bidding_rounds()
|
||||
[%BiddingRound{}, ...]
|
||||
|
||||
"""
|
||||
def list_bidding_rounds do
|
||||
Repo.all(BiddingRound)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single bidding_round.
|
||||
|
||||
Raises `Ecto.NoResultsError` if the Bidding round does not exist.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> get_bidding_round!(123)
|
||||
%BiddingRound{}
|
||||
|
||||
iex> get_bidding_round!(456)
|
||||
** (Ecto.NoResultsError)
|
||||
|
||||
"""
|
||||
def get_bidding_round!(id), do: Repo.get!(BiddingRound, id)
|
||||
|
||||
@doc """
|
||||
Creates a bidding_round.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> create_bidding_round(%{field: value})
|
||||
{:ok, %BiddingRound{}}
|
||||
|
||||
iex> create_bidding_round(%{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def create_bidding_round(attrs) do
|
||||
%BiddingRound{}
|
||||
|> BiddingRound.changeset(attrs)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a bidding_round.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> update_bidding_round(bidding_round, %{field: new_value})
|
||||
{:ok, %BiddingRound{}}
|
||||
|
||||
iex> update_bidding_round(bidding_round, %{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def update_bidding_round(%BiddingRound{} = bidding_round, attrs) do
|
||||
bidding_round
|
||||
|> BiddingRound.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a bidding_round.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_bidding_round(bidding_round)
|
||||
{:ok, %BiddingRound{}}
|
||||
|
||||
iex> delete_bidding_round(bidding_round)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def delete_bidding_round(%BiddingRound{} = bidding_round) do
|
||||
Repo.delete(bidding_round)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns an `%Ecto.Changeset{}` for tracking bidding_round changes.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> change_bidding_round(bidding_round)
|
||||
%Ecto.Changeset{data: %BiddingRound{}}
|
||||
|
||||
"""
|
||||
def change_bidding_round(%BiddingRound{} = bidding_round, attrs \\ %{}) do
|
||||
BiddingRound.changeset(bidding_round, attrs)
|
||||
end
|
||||
end
|
||||
20
lib/beet_round_server/bidding_rounds/bidding_round.ex
Normal file
20
lib/beet_round_server/bidding_rounds/bidding_round.ex
Normal file
@ -0,0 +1,20 @@
|
||||
defmodule BeetRoundServer.BiddingRounds.BiddingRound do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
@primary_key {:id, :binary_id, autogenerate: true}
|
||||
@foreign_key_type :binary_id
|
||||
schema "bidding_rounds" do
|
||||
field :round_number, :integer
|
||||
field :running, :boolean, default: false
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(bidding_round, attrs) do
|
||||
bidding_round
|
||||
|> cast(attrs, [:round_number, :running])
|
||||
|> validate_required([:round_number, :running])
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user