generated from VLADIMIR/template
add command and volume
This commit is contained in:
@@ -19,6 +19,8 @@ type ScreenSession struct {
|
||||
Mode int32
|
||||
Version int64
|
||||
Position int64
|
||||
Command int32
|
||||
Volume int32
|
||||
}
|
||||
|
||||
type ScreenSessionsRepo struct {
|
||||
@@ -41,10 +43,10 @@ func (r *ScreenSessionsRepo) Create(ctx context.Context, tokenHash string) (int,
|
||||
func (r *ScreenSessionsRepo) Get(ctx context.Context, id int, tokenHash string) (*ScreenSession, error) {
|
||||
session := &ScreenSession{ID: id}
|
||||
err := r.pool.QueryRow(ctx, `
|
||||
SELECT game_id, sound_enabled, last_seen_at, mode, state_version, position_ms
|
||||
SELECT game_id, sound_enabled, last_seen_at, mode, state_version, position_ms, command, volume
|
||||
FROM screen_sessions
|
||||
WHERE id = $1 AND access_token_hash = $2`, id, tokenHash).
|
||||
Scan(&session.GameID, &session.Sound, &session.LastSeen, &session.Mode, &session.Version, &session.Position)
|
||||
Scan(&session.GameID, &session.Sound, &session.LastSeen, &session.Mode, &session.Version, &session.Position, &session.Command, &session.Volume)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrScreenNotFound
|
||||
}
|
||||
@@ -61,7 +63,7 @@ func (r *ScreenSessionsRepo) Get(ctx context.Context, id int, tokenHash string)
|
||||
|
||||
func (r *ScreenSessionsRepo) ListByGame(ctx context.Context, gameID int) ([]*ScreenSession, error) {
|
||||
rows, err := r.pool.Query(ctx, `
|
||||
SELECT id, game_id, sound_enabled, last_seen_at, mode, state_version, position_ms
|
||||
SELECT id, game_id, sound_enabled, last_seen_at, mode, state_version, position_ms, command, volume
|
||||
FROM screen_sessions
|
||||
WHERE game_id = $1
|
||||
ORDER BY id`, gameID)
|
||||
@@ -73,7 +75,7 @@ func (r *ScreenSessionsRepo) ListByGame(ctx context.Context, gameID int) ([]*Scr
|
||||
var sessions []*ScreenSession
|
||||
for rows.Next() {
|
||||
session := &ScreenSession{}
|
||||
if err := rows.Scan(&session.ID, &session.GameID, &session.Sound, &session.LastSeen, &session.Mode, &session.Version, &session.Position); err != nil {
|
||||
if err := rows.Scan(&session.ID, &session.GameID, &session.Sound, &session.LastSeen, &session.Mode, &session.Version, &session.Position, &session.Command, &session.Volume); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sessions = append(sessions, session)
|
||||
@@ -91,6 +93,11 @@ func (r *ScreenSessionsRepo) SetPosition(ctx context.Context, gameID int, positi
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *ScreenSessionsRepo) SetCommand(ctx context.Context, gameID int, command int32, position int64, volume int32) error {
|
||||
_, err := r.pool.Exec(ctx, `UPDATE screen_sessions SET command = $2, position_ms = $3, volume = $4, state_version = state_version + 1, updated_at = NOW() WHERE game_id = $1`, gameID, command, position, volume)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *ScreenSessionsRepo) Bind(ctx context.Context, id, gameID int, tokenHash string) error {
|
||||
result, err := r.pool.Exec(ctx, `
|
||||
UPDATE screen_sessions
|
||||
|
||||
Reference in New Issue
Block a user