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

@ -2,6 +2,7 @@ package repos
import (
"context"
"fmt"
"gralias/models"
"github.com/jmoiron/sqlx"
@ -70,12 +71,14 @@ func (p *RepoProvider) RoomGetExtended(ctx context.Context, id string) (*models.
room := &models.Room{}
err := sqlx.GetContext(ctx, p.DB, room, `SELECT * FROM rooms WHERE id = ?`, id)
if err != nil {
err = fmt.Errorf("failed to get room; %w", err)
return nil, err
}
// Get players
players := []*models.Player{}
err = sqlx.SelectContext(ctx, p.DB, &players, `SELECT * FROM players WHERE room_id = ?`, id)
if err != nil {
err = fmt.Errorf("failed to get players; %w", err)
return nil, err
}
room.RedTeam.Color = string(models.UserTeamRed)
@ -108,6 +111,7 @@ func (p *RepoProvider) RoomGetExtended(ctx context.Context, id string) (*models.
wordCards := []models.WordCard{}
err = sqlx.SelectContext(ctx, p.DB, &wordCards, `SELECT * FROM word_cards WHERE room_id = ?`, id)
if err != nil {
err = fmt.Errorf("failed to get cards; %w", err)
return nil, err
}
room.Cards = wordCards
@ -115,6 +119,7 @@ func (p *RepoProvider) RoomGetExtended(ctx context.Context, id string) (*models.
actions := []models.Action{}
err = sqlx.SelectContext(ctx, p.DB, &actions, `SELECT * FROM actions WHERE room_id = ? ORDER BY created_at ASC`, id)
if err != nil {
err = fmt.Errorf("failed to get actions; %w", err)
return nil, err
}
room.ActionHistory = actions
@ -122,6 +127,7 @@ func (p *RepoProvider) RoomGetExtended(ctx context.Context, id string) (*models.
settings := &models.GameSettings{}
err = sqlx.GetContext(ctx, p.DB, settings, `SELECT * FROM settings WHERE room_id = ?`, id)
if err != nil {
err = fmt.Errorf("failed to get settings; %w", err)
return nil, err
}
room.Settings = *settings