diff --git a/cmd/server/games.go b/cmd/server/games.go index d74b0e7..f919992 100644 --- a/cmd/server/games.go +++ b/cmd/server/games.go @@ -56,8 +56,21 @@ func (games Games) GamesForUser(ctx context.Context, id string) ([]string, error return result, err } -func (games Games) GameByName(ctx context.Context, name string) (string, error) { - return "", io.EOF +func (games Games) GameByName(ctx context.Context, uid, name string) (string, error) { + var result string + err := games.db.Query(ctx, func(rows *sql.Rows) error { + return rows.Scan(&result) + }, ` + SELECT + players.games_uuid + FROM + players + JOIN games ON players.game_uuid=games.game_uuid + WHERE players.user_uuid=? AND games.name=? + ORDER BY games.timestamp DESC + LIMIT 1 + `, uid, name) + return result, err } type ( @@ -214,11 +227,11 @@ func (games Games) CreateEventAssignmentRotation(ctx context.Context, id string, // TODO assign victim's target to killer // TODO randomize everyone else so not the same as before AND not self return io.EOF - return games.createEvent(ctx, id, v) + //return games.createEvent(ctx, id, v) } func (games Games) createEvent(ctx context.Context, id string, v any) error { - payload, err := json.Marshal(any) + payload, err := json.Marshal(v) if err != nil { panic(err) }