Added BiddingRoundServer "CurrentRoundServer" with a facade to control it. "Listing Biddings" page shows information which round is currently running.

This commit is contained in:
2026-02-12 12:23:21 +01:00
parent 04c79d341c
commit 6eea9d2fba
5 changed files with 240 additions and 10 deletions

View File

@ -3,22 +3,62 @@ defmodule BeetRoundServerWeb.BiddingRoundController do
alias BeetRoundServer.BiddingRounds
alias BeetRoundServer.BiddingRounds.BiddingRound
alias BeetRoundServer.BiddingRounds.BiddingRoundFacade
action_fallback BeetRoundServerWeb.FallbackController
def get_highest(conn, _params) do
BiddingRoundFacade.restart_if_necessary()
last_round = BiddingRoundFacade.get_highest_bidding_round()
conn
|> render(:show, bidding_round: last_round)
end
def start_new(conn, _params) do
BiddingRoundFacade.start_new_round()
current_round = BiddingRounds.get_highest_bidding_round!()
conn
|> put_status(:created)
|> render(:show, bidding_round: current_round)
end
def restart(conn, _params) do
BiddingRoundFacade.restart_hightest_round()
current_round = BiddingRounds.get_highest_bidding_round!()
conn
|> put_status(:created)
|> render(:show, bidding_round: current_round)
end
def stop(conn, _params) do
BiddingRoundFacade.stop_current_round()
stopped_round = BiddingRounds.get_highest_bidding_round!()
conn
|> render(:show, bidding_round: stopped_round)
end
def index(conn, _params) do
bidding_rounds = BiddingRounds.list_bidding_rounds()
render(conn, :index, bidding_rounds: bidding_rounds)
end
def create(conn, %{"bidding_round" => bidding_round_params}) do
with {:ok, %BiddingRound{} = bidding_round} <- BiddingRounds.create_bidding_round(bidding_round_params) do
conn
|> put_status(:created)
|> put_resp_header("location", ~p"/api/bidding_rounds/#{bidding_round}")
|> render(:show, bidding_round: bidding_round)
end
end
# def create(conn, %{"bidding_round" => bidding_round_params}) do
# with {:ok, %BiddingRound{} = bidding_round} <-
# BiddingRounds.create_bidding_round(bidding_round_params) do
# conn
# |> put_status(:created)
# |> put_resp_header("location", ~p"/api/bidding_rounds/#{bidding_round}")
# |> render(:show, bidding_round: bidding_round)
# end
# end
def show(conn, %{"id" => id}) do
bidding_round = BiddingRounds.get_bidding_round!(id)
@ -28,7 +68,8 @@ defmodule BeetRoundServerWeb.BiddingRoundController do
def update(conn, %{"id" => id, "bidding_round" => bidding_round_params}) do
bidding_round = BiddingRounds.get_bidding_round!(id)
with {:ok, %BiddingRound{} = bidding_round} <- BiddingRounds.update_bidding_round(bidding_round, bidding_round_params) do
with {:ok, %BiddingRound{} = bidding_round} <-
BiddingRounds.update_bidding_round(bidding_round, bidding_round_params) do
render(conn, :show, bidding_round: bidding_round)
end
end

View File

@ -2,6 +2,7 @@ defmodule BeetRoundServerWeb.BiddingLive.Index do
use BeetRoundServerWeb, :live_view
alias BeetRoundServer.Biddings
alias BeetRoundServer.BiddingRounds.BiddingRoundFacade
@impl true
def render(assigns) do
@ -16,6 +17,12 @@ defmodule BeetRoundServerWeb.BiddingLive.Index do
</:actions>
</.header>
<%= if @bidding_round == 0 do %>
<p>Keine Bietrunde aktiv.</p>
<% else %>
<p>Aktive Bietrunde: {@bidding_round}</p>
<% end %>
<.table
id="biddings"
rows={@streams.biddings}
@ -50,9 +57,12 @@ defmodule BeetRoundServerWeb.BiddingLive.Index do
Biddings.subscribe_biddings(socket.assigns.current_scope)
end
current_round = BiddingRoundFacade.get_current_round()
{:ok,
socket
|> assign(:page_title, "Listing Biddings")
|> assign(bidding_round: current_round)
|> stream(:biddings, list_biddings(socket.assigns.current_scope))}
end
@ -67,7 +77,8 @@ defmodule BeetRoundServerWeb.BiddingLive.Index do
@impl true
def handle_info({type, %BeetRoundServer.Biddings.Bidding{}}, socket)
when type in [:created, :updated, :deleted] do
{:noreply, stream(socket, :biddings, list_biddings(socket.assigns.current_scope), reset: true)}
{:noreply,
stream(socket, :biddings, list_biddings(socket.assigns.current_scope), reset: true)}
end
defp list_biddings(current_scope) do