Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add stepbystep #000 #40

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions database/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@ var (
"password varchar (250), " +
"created_at timestamp, " +
"last_access timestamp, " +
"step integer, " +
"skipped_challenges text, " +
"solved_challenges text);"

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

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

UpdateCloseEvent = "UPDATE event SET tag = $2, finished_at = $3 WHERE tag = $1"
UpdateEventStatus = "UPDATE event SET status = $2 WHERE tag = $1 "

UpdateEventLastaccessedDate = "UPDATE team SET last_access = $2 WHERE tag = $1"
UpdateTeamSolvedChl = "UPDATE team SET solved_challenges = $2 WHERE tag = $1"
UpdateTeamSkippedChl = "UPDATE team SET skipped_challenges = $2 WHERE tag = $1"
UpdateTeamStep = "UPDATE team SET step = $2 WHERE tag = $1"

QuerySolvedChls = "SELECT solved_challenges FROM team WHERE tag=$1"
QueryEventTable = "SELECT * FROM event"
Expand Down
29 changes: 27 additions & 2 deletions database/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type Store interface {
GetEventStatus(*pb.GetEventStatusRequest) (int32, error)
SetEventStatus(*pb.SetEventStatusRequest) (int32, error)
UpdateTeamSolvedChallenge(*pb.UpdateTeamSolvedChallengeRequest) (string, error)
UpdateTeamSkippedChallenge(request *pb.UpdateTeamSkippedChallengeRequest) (string, error)
UpdateTeamStep(request *pb.UpdateTeamStepTrackerRequest) (string, error)
UpdateTeamLastAccess(*pb.UpdateTeamLastAccessRequest) (string, error)
UpdateCloseEvent(*pb.UpdateEventRequest) (string, error)
}
Expand Down Expand Up @@ -110,7 +112,7 @@ func (s *store) AddTeam(in *pb.AddTeamRequest) (string, error) {
return "", err
}

_, err := s.db.Exec(AddTeamQuery, in.Id, eventId, in.Email, in.Name, in.Password, now, now, "[]")
_, err := s.db.Exec(AddTeamQuery, in.Id, eventId, in.Email, in.Name, in.Password, now, now, 0, "[]", "[]")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -183,7 +185,7 @@ func (s *store) GetTeams(tag string) ([]model.Team, error) {

team := new(model.Team)
err := rows.Scan(&team.Id, &team.Tag, &team.EventId, &team.Email, &team.Name, &team.Password, &team.CreatedAt,
&team.LastAccess, &team.SolvedChallenges)
&team.LastAccess, &team.Step, &team.SkippedChallenges, &team.SolvedChallenges)
if err != nil && !strings.Contains(err.Error(), handleNullConversionError) {
return nil, err
}
Expand Down Expand Up @@ -243,6 +245,29 @@ func (s *store) UpdateTeamSolvedChallenge(in *pb.UpdateTeamSolvedChallengeReques
return OK, nil
}

func (s *store) UpdateTeamSkippedChallenge(in *pb.UpdateTeamSkippedChallengeRequest) (string, error) {
s.m.Lock()
defer s.m.Unlock()

_, err := s.db.Exec(UpdateTeamSkippedChl, in.TeamId, in.SkippedChals)
if err != nil {
return "", err
}
return OK, nil
}

func (s *store) UpdateTeamStep(in *pb.UpdateTeamStepTrackerRequest) (string, error) {
s.m.Lock()
defer s.m.Unlock()

_, err := s.db.Exec(UpdateTeamStep, in.TeamId, in.Step)
if err != nil {
return "", err
}

return OK, nil
}

func (s *store) UpdateTeamLastAccess(in *pb.UpdateTeamLastAccessRequest) (string, error) {
s.m.Lock()
defer s.m.Unlock()
Expand Down
18 changes: 18 additions & 0 deletions database/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,24 @@ func TestTeamUpdateLastAccess(t *testing.T) {
}
}

func TestTeamUpdateStep(t *testing.T) {

conn, err := createTestClientConn()
if err != nil {
t.Fatal(err)
}
defer conn.Close()
c := pb.NewStoreClient(conn)

_, err = c.UpdateTeamStepTracker(context.Background(), &pb.UpdateTeamStepTrackerRequest{
TeamId: "team1",
Step: 1,
})
if err != nil {
t.Fatalf("Error updating team step: %s", err.Error())
}
}

func TestCloseEvent(t *testing.T) {

conn, err := createTestClientConn()
Expand Down
2 changes: 1 addition & 1 deletion database/timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func setup() (*sql.DB, error) {

func insertTeamEvent(eid int, db *sql.DB) error {

_, err := db.Exec(AddTeamQuery, "", eid, "random@email.com", "randomteam", "12345", time.Now(), time.Now(), "[]")
_, err := db.Exec(AddTeamQuery, "", eid, "random@email.com", "randomteam", "12345", time.Now(), time.Now(), 0, "[]", "[]")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
ports:
- '5432:5432'
volumes:
- data:/var/lib/postgresql/data
- ${PSQL_DATA_PATH}:/var/lib/postgresql/data
networks:
- internal

Expand Down
20 changes: 11 additions & 9 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ type Event struct {
}

type Team struct {
Id uint //DB Primary key
Tag string
EventId uint //DB Primary key of the event
Email string
Name string
Password string
CreatedAt string
LastAccess string
SolvedChallenges string
Id uint //DB Primary key
Tag string
EventId uint //DB Primary key of the event
Email string
Name string
Password string
CreatedAt string
LastAccess string
SolvedChallenges string
Step uint
SkippedChallenges string
}

type Config struct {
Expand Down
Loading