Fix: test; limit changes on player update

This commit is contained in:
Grail Finder
2025-07-04 10:02:39 +03:00
parent 6ca8afd13d
commit 83215f5c14
9 changed files with 40 additions and 92 deletions

View File

@ -159,7 +159,6 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) {
abortWithError(w, err.Error())
return
}
// Initialize transaction
ctx, tx, err := repo.InitTx(r.Context())
if err != nil {
@ -173,7 +172,6 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) {
panic(r)
}
}()
fi.Room.IsRunning = true
fi.Room.IsOver = false
fi.Room.TeamTurn = "blue"
@ -189,24 +187,21 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) {
Action: models.ActionTypeGameStarted,
}
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
// Use the new context with transaction
if err := saveFullInfo(ctx, fi); err != nil {
tx.Rollback()
abortWithError(w, err.Error())
return
}
// Save action history
action.RoomID = fi.Room.ID
action.CreatedAtUnix = time.Now().Unix()
action.CreatedAt = time.Now()
if err := repo.CreateAction(ctx, fi.Room.ID, &action); err != nil {
tx.Rollback()
log.Error("failed to save action", "error", err)
abortWithError(w, err.Error())
return
}
// Save word cards
for _, card := range fi.Room.Cards {
card.RoomID = fi.Room.ID // Ensure RoomID is set for each card
@ -273,7 +268,8 @@ func HandleJoinRoom(w http.ResponseWriter, r *http.Request) {
fi.State.RoomID = &room.ID
fi.Room = room
fi.List = nil
if err := saveFullInfo(r.Context(), fi); err != nil {
if err := repo.PlayerSetRoomID(r.Context(), room.ID, fi.State.Username); err != nil {
log.Error("failed to set room_id for player", "error", err, "username", fi.State.Username, "room_id", room.ID)
abortWithError(w, err.Error())
return
}