38 lines
829 B
Go
38 lines
829 B
Go
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
|
|
}
|