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