示例#1
0
文件: team.go 项目: pjherring/ggc
func setTeamFinish(ctx *_Context) error {
	teamId := ctx.urlParams["team_id"].(int64)

	team, err := table.FindTeam(teamId)
	if err != nil {
		return err
	}

	if ctx.r.Method == "DELETE" {
		ctx.resp = &_TeamFinishResp{}
		return table.UpdateTeamFinishTime(teamId, nil)
	}

	now := time.Now()
	if err := table.UpdateTeamFinishTime(teamId, &now); err != nil {
		return err
	}

	hintsTaken, err := table.FindHintsTakenForTeam(teamId)
	if err != nil {
		return err
	}

	ctx.resp = newFinishTimeResp(team.StartTime, now, hintsTaken)
	return nil
}
示例#2
0
func TestUpdateTeamFinsihTime(t *T) {
	beforeTeamTest()
	now := time.Date(2016, 1, 1, 12, 0, 0, 0, time.UTC)
	err := table.UpdateTeamFinishTime(100, &now)
	rdtest.Assert(t, err == nil, err)
	team, err := table.FindTeam(100)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, team.FinishTime.Valid)
	rdtest.Assert(
		t,
		now.Unix() == team.FinishTime.Time.Unix(),
		"%d != %d", now.Unix(), team.FinishTime.Time.Unix(),
	)

	err = table.UpdateTeamFinishTime(100, nil)
	rdtest.Assert(t, err == nil, err)
	team, err = table.FindTeam(100)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, !team.FinishTime.Valid)
	rdtest.Assert(t, team.FinishTime.Time.IsZero())
}