server/services/action/
start_next_round.rs1use crate::{
2 domain::{GameCommand, GameId, UserId},
3 error::{ServerError, bug},
4 server_state::ServerState,
5 services::queries::get_game,
6};
7
8pub async fn start_next_round(
23 server_state: ServerState,
24 user_id: UserId,
25 game_id: GameId,
26) -> Result<(), ServerError> {
27 let game = get_game(server_state.clone(), game_id).await?;
28
29 if let Some(game) = game {
30 let player = game
31 .validate_user(user_id)
32 .ok_or(ServerError::Forbidden("start next round".into()))?;
33
34 let aggregate_id = game_id.value().to_string();
35
36 let command = GameCommand::StartNextRound { player };
37
38 server_state
39 .cqrs
40 .execute(&aggregate_id, command)
41 .await
42 .map_err(bug!())?;
43
44 Ok(())
45 } else {
46 Err(ServerError::NotFound)
47 }
48}