sorarebuddy/db/game_player.go

38 lines
829 B
Go
Raw Permalink Normal View History

2024-05-23 04:18:54 +00:00
package db
import (
"context"
"github.com/uptrace/bun"
"git.lehouerou.net/laurent/sorarebuddy/model"
)
type GamePlayerRepository struct {
*Repository[model.GamePlayer]
}
func NewGamePlayerRepository(db *bun.DB) *GamePlayerRepository {
return &GamePlayerRepository{
Repository: NewRepository[model.GamePlayer](db, []string{"game_id", "player_slug"}),
}
}
func (r *GamePlayerRepository) GetByPlayer(ctx context.Context, playerSlug string) ([]model.GamePlayer, error) {
var res []model.GamePlayer
err := r.db.NewSelect().
Model(&res).
Relation("Game").
Relation("Game.HomeTeam").
Relation("Game.AwayTeam").
Relation("Game.WinnerTeam").
Relation("Game.Fixture").
Relation("Score").
Where("game_player.player_slug = ?", playerSlug).
Scan(ctx)
if err != nil {
return nil, err
}
return res, nil
}