Exemplo n.º 1
0
func StandingWithTeams(row MultiScanner) (*model.Standing, error) {
	var standing model.Standing
	var season model.Season
	var team model.Team
	var league model.League

	err := row.Scan(
		&standing.ID, &season.ID, &standing.Wins, &standing.Losses, &standing.Ties, &standing.Created, &standing.Modified,
		&team.ID, &league.ID, &team.Name, &team.Created, &team.Modified)

	if err != nil {
		return nil, err
	}

	standing.Season = &season
	standing.Team = &team
	standing.Team.League = &league

	return &standing, nil
}
Exemplo n.º 2
0
func (repo *PgRepository) CreateStanding(standing *model.Standing) error {
	err := standing.Validate(repo)
	if err != nil {
		return err
	}

	t := time.Now()

	var id int
	err = repo.manager.db.QueryRow(`INSERT INTO standing(season_id, team_id, wins, losses, ties, created, modified)
	    VALUES($1, $2, $3, $4, $5, $6, $7) RETURNING id`,
		standing.Season.ID, standing.Team.ID, standing.Wins, standing.Losses, standing.Ties, t, t).Scan(&id)

	if err != nil {
		return err
	}

	standing.ID = id
	standing.Created = t
	standing.Modified = t

	return nil
}