Skip to content

Commit 492bbb5

Browse files
added rpc message to change step tracker
1 parent 68604d7 commit 492bbb5

File tree

6 files changed

+203
-70
lines changed

6 files changed

+203
-70
lines changed

database/query.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ var (
2828
"step integer, " +
2929
"solved_challenges text);"
3030

31-
AddTeamQuery = "INSERT INTO team (tag, event_id, email, name, password, created_at, last_access, solved_challenges)" +
32-
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8)"
31+
AddTeamQuery = "INSERT INTO team (tag, event_id, email, name, password, created_at, last_access, step, solved_challenges)" +
32+
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)"
3333

3434
AddEventQuery = "INSERT INTO event (tag, name, available, capacity, frontends, status, exercises, started_at, finish_expected, finished_at, createdby, onlyvpn)" +
3535
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,$11,$12)"
@@ -39,6 +39,7 @@ var (
3939

4040
UpdateEventLastaccessedDate = "UPDATE team SET last_access = $2 WHERE tag = $1"
4141
UpdateTeamSolvedChl = "UPDATE team SET solved_challenges = $2 WHERE tag = $1"
42+
UpdateTeamStep = "UPDATE team SET step = $2 WHERE tag = $1"
4243

4344
QuerySolvedChls = "SELECT solved_challenges FROM team WHERE tag=$1"
4445
QueryEventTable = "SELECT * FROM event"

database/store.go

+13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Store interface {
4646
GetEventStatus(*pb.GetEventStatusRequest) (int32, error)
4747
SetEventStatus(*pb.SetEventStatusRequest) (int32, error)
4848
UpdateTeamSolvedChallenge(*pb.UpdateTeamSolvedChallengeRequest) (string, error)
49+
UpdateTeamStep(request *pb.UpdateTeamStepTrackerRequest) (string, error)
4950
UpdateTeamLastAccess(*pb.UpdateTeamLastAccessRequest) (string, error)
5051
UpdateCloseEvent(*pb.UpdateEventRequest) (string, error)
5152
}
@@ -243,6 +244,18 @@ func (s *store) UpdateTeamSolvedChallenge(in *pb.UpdateTeamSolvedChallengeReques
243244
return OK, nil
244245
}
245246

247+
func (s *store) UpdateTeamStep(in *pb.UpdateTeamStepTrackerRequest) (string, error) {
248+
s.m.Lock()
249+
defer s.m.Unlock()
250+
251+
_, err := s.db.Exec(UpdateEventLastaccessedDate, in.TeamId, in.Step)
252+
if err != nil {
253+
return "", err
254+
}
255+
256+
return OK, nil
257+
}
258+
246259
func (s *store) UpdateTeamLastAccess(in *pb.UpdateTeamLastAccessRequest) (string, error) {
247260
s.m.Lock()
248261
defer s.m.Unlock()

database/store_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,24 @@ func TestTeamUpdateLastAccess(t *testing.T) {
301301
}
302302
}
303303

304+
func TestTeamUpdateStep(t *testing.T) {
305+
306+
conn, err := createTestClientConn()
307+
if err != nil {
308+
t.Fatal(err)
309+
}
310+
defer conn.Close()
311+
c := pb.NewStoreClient(conn)
312+
313+
_, err = c.UpdateTeamStepTracker(context.Background(), &pb.UpdateTeamStepTrackerRequest{
314+
TeamId: "team1",
315+
Step: 1,
316+
})
317+
if err != nil {
318+
t.Fatalf("Error updating team step: %s", err.Error())
319+
}
320+
}
321+
304322
func TestCloseEvent(t *testing.T) {
305323

306324
conn, err := createTestClientConn()

0 commit comments

Comments
 (0)