Fix: save bot actions
This commit is contained in:
@ -163,6 +163,7 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) {
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
fi.Room.MimeDone = false
|
||||
fi.Room.IsRunning = true
|
||||
fi.Room.IsOver = false
|
||||
fi.Room.TeamTurn = "blue"
|
||||
@ -179,13 +180,13 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
fi.Room.ActionHistory = append(fi.Room.ActionHistory, action)
|
||||
// Use the new context with transaction
|
||||
if err := saveFullInfo(ctx, fi); err != nil {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
log.Error("failed to rollback transaction", "error", err)
|
||||
}
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
// if err := saveFullInfo(ctx, fi); err != nil {
|
||||
// if err := tx.Rollback(); err != nil {
|
||||
// log.Error("failed to rollback transaction", "error", err)
|
||||
// }
|
||||
// abortWithError(w, err.Error())
|
||||
// return
|
||||
// }
|
||||
// Save action history
|
||||
action.RoomID = fi.Room.ID
|
||||
action.CreatedAt = time.Now()
|
||||
@ -209,14 +210,18 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := repo.RoomUpdate(ctx, fi.Room); err != nil {
|
||||
log.Error("failed to update room", "error", err)
|
||||
tx.Rollback()
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
// Commit the transaction
|
||||
if err := tx.Commit(); err != nil {
|
||||
log.Error("failed to commit transaction", "error", err)
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// reveal all cards
|
||||
if fi.State.Role == "mime" {
|
||||
fi.Room.MimeView()
|
||||
|
Reference in New Issue
Block a user