126 lines
2.6 KiB
Elixir
126 lines
2.6 KiB
Elixir
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)
|
|
|
|
def get_highest_bidding_round!() do
|
|
query =
|
|
Ecto.Query.from(bidding_round in BiddingRound,
|
|
order_by: [desc: bidding_round.round_number],
|
|
limit: 1
|
|
)
|
|
|
|
Repo.one(query)
|
|
end
|
|
|
|
def get_bidding_round_by_number!(round_number) do
|
|
query =
|
|
Ecto.Query.from(bidding_round in BiddingRound,
|
|
where: bidding_round.round_number == ^round_number,
|
|
order_by: [desc: bidding_round.inserted_at],
|
|
limit: 1
|
|
)
|
|
|
|
Repo.one(query)
|
|
end
|
|
|
|
@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
|