backend - adding room service and wiring

preparing to create a better auth module that uses room service
This commit is contained in:
efim
2023-04-25 09:55:45 +04:00
parent dfff814079
commit 64267a5f67
5 changed files with 148 additions and 39 deletions

View File

@@ -6,10 +6,14 @@ import io.circe._
object Models {
/** view of the single planning poker round
* @param players - people who are currently playing
* @param allowedCards- the cards values that can be used by players
* @param round - state of the selected cards of the players
* @param canCloseRound - whether current player has access to button to finish the round
* @param players
* \- people who are currently playing
* @param allowedCards-
* the cards values that can be used by players
* @param round
* \- state of the selected cards of the players
* @param canCloseRound
* \- whether current player has access to button to finish the round
*/
final case class RoomStateView(
players: List[Player],
@@ -23,30 +27,72 @@ object Models {
object RoomStateView {
val empty = RoomStateView(
List.empty, PlayerID(0), List.empty, RoundState.Voting(None, List.empty), false
List.empty,
PlayerID(0),
List.empty,
RoundState.Voting(None, List.empty),
false
)
}
enum RoundState derives Codec.AsObject:
/** view state for round before votes are open player can know their vote and
* who of the other players have voted
*/
/** view state for round before votes are open player can know their vote
* and who of the other players have voted
*/
case Voting(
myCard: Option[String],
alreadyVoted: List[Player]
)
myCard: Option[String],
alreadyVoted: List[Player]
)
/** view state for round after opening the votes
*/
/** view state for round after opening the votes
*/
case Viewing(
votes: List[(PlayerID, String)]
)
votes: List[(PlayerID, String)]
)
final case class PlayerID(id: Long) derives Codec.AsObject
final case class Player(name: String, id: PlayerID) derives Codec.AsObject
final case class RoomID(id: Long) derives Codec.AsObject
final case class RoomID(name: String) derives Codec.AsObject
final case class Room(
id: RoomID,
players: List[Player],
owner: PlayerID,
password: String,
allowedCards: List[String],
round: RoundState
) {
def toViewFor(playerId: PlayerID): RoomStateView = {
players
.find(_.id == playerId)
.fold(ifEmpty = RoomStateView.empty)((me: Player) =>
RoomStateView(
players,
me.id,
allowedCards,
round,
playerId == owner
)
)
}
}
object Room {
val testRoom = Room(
id = RoomID("testroom"),
players = List(
Player("me", PlayerID(1L)),
Player("horsey", PlayerID(444L)),
Player("froggy", PlayerID(555L)),
Player("owley", PlayerID(777L))
),
owner = PlayerID(1L),
password = "password",
allowedCards = List("S", "M", "L"),
// TODO - this needs to be a different hting
round = RoundState.Voting(None, List.empty)
)
}
}