예제 #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
파일: team_test.go 프로젝트: pjherring/ggc
func TestUpdateTeamStartTime(t *T) {
	beforeTeamTest()
	startTime := time.Date(2016, 7, 2, 7, 7, 0, 0, time.UTC)
	err := table.UpdateTeamStartTime(100, startTime)
	rdtest.Assert(t, err == nil, err)
	team, err := table.FindTeam(100)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, team.StartTime.Valid)
	rdtest.Assert(t, team.StartTime.Time.Equal(startTime), team.StartTime)
}
예제 #3
0
파일: team_test.go 프로젝트: pjherring/ggc
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())
}