コード例 #1
0
ファイル: team.go プロジェクト: englandr/recleague
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
}
コード例 #2
0
ファイル: team.go プロジェクト: englandr/recleague
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
}