func (repo *MockLeagueRepository) Create(league *model.League) error { err := league.Validate(repo) if err != nil { return err } id := repo.lastId + 1 league.Id = id repo.lastId = id t := time.Now() league.Created = t league.Modified = t repo.mocks[id] = league return nil }
func (repo *PgLeagueRepository) Create(league *model.League) error { err := league.Validate(repo) if err != nil { return err } t := time.Now() var id int err = repo.manager.db.QueryRow(`INSERT INTO league(name, sport, created, modified) VALUES($1, $2, $3, $4) RETURNING id`, league.Name, league.Sport, t, t).Scan(&id) if err != nil { return err } league.Id = id league.Created = t league.Modified = t return nil }