API can serve bidding_of_highest_round and biddings_of_round/:round_number route.
This commit is contained in:
@ -66,6 +66,26 @@ defmodule BeetRoundServer.Biddings do
|
||||
Repo.get_by!(Bidding, id: id, user_id: scope.user.id)
|
||||
end
|
||||
|
||||
def biddings_of_round(round_number) do
|
||||
Repo.all(
|
||||
from(bidding in Bidding,
|
||||
where: bidding.bidding_round == ^round_number,
|
||||
order_by: [asc: bidding.inserted_at]
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
def get_most_recent_bidding(%Scope{} = scope) do
|
||||
query =
|
||||
Ecto.Query.from(bidding in Bidding,
|
||||
where: bidding.user_id == ^scope.user.id,
|
||||
order_by: [desc: bidding.inserted_at],
|
||||
limit: 1
|
||||
)
|
||||
|
||||
Repo.one(query)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a bidding.
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ defmodule BeetRoundServerWeb.BiddingController do
|
||||
use BeetRoundServerWeb, :controller
|
||||
|
||||
alias BeetRoundServer.Biddings
|
||||
alias BeetRoundServer.BiddingRounds.BiddingRoundFacade
|
||||
# alias BeetRoundServer.Biddings.Bidding
|
||||
|
||||
action_fallback BeetRoundServerWeb.FallbackController
|
||||
@ -13,6 +14,19 @@ defmodule BeetRoundServerWeb.BiddingController do
|
||||
render(conn, :index, biddings: biddings)
|
||||
end
|
||||
|
||||
def biddings_of_round(conn, %{"round_number" => round_number}) do
|
||||
biddings = Biddings.biddings_of_round(round_number)
|
||||
render(conn, :index, biddings: biddings)
|
||||
end
|
||||
|
||||
def biddings_of_highest_round(conn, _params) do
|
||||
round = BiddingRoundFacade.get_highest_bidding_round()
|
||||
IO.puts("Highest round number:")
|
||||
IO.puts(round.round_number)
|
||||
biddings = Biddings.biddings_of_round(round.round_number)
|
||||
render(conn, :index, biddings: biddings)
|
||||
end
|
||||
|
||||
# def create(conn, %{"bidding" => bidding_params}) do
|
||||
# with {:ok, %Bidding{} = bidding} <- Biddings.create_bidding(bidding_params) do
|
||||
# conn
|
||||
|
||||
@ -33,8 +33,11 @@ defmodule BeetRoundServerWeb.Router do
|
||||
get "/bidding_rounds/start_new", BiddingRoundController, :start_new
|
||||
get "/bidding_rounds/restart", BiddingRoundController, :restart
|
||||
get "/bidding_rounds/stop", BiddingRoundController, :stop
|
||||
|
||||
get "/biddings_of_round/:round_number", BiddingController, :biddings_of_round
|
||||
get "/biddings_of_highest_round", BiddingController, :biddings_of_highest_round
|
||||
|
||||
resources "/users", UserController, except: [:new, :edit]
|
||||
resources "/biddings", BiddingController, except: [:new, :edit]
|
||||
end
|
||||
|
||||
# Enable LiveDashboard and Swoosh mailbox preview in development
|
||||
|
||||
Reference in New Issue
Block a user