Skip to content

Commit

Permalink
Merge pull request #52 from aau-network-security/feature/delete-team-…
Browse files Browse the repository at this point in the history
…#000

Feature/delete team #000
  • Loading branch information
mrtrkmn authored May 13, 2021
2 parents 043d423 + e56082e commit 9fb9c66
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 102 deletions.
2 changes: 2 additions & 0 deletions database/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var (
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)"

DelTeamQuery = "DELETE FROM team WHERE tag=$1 and event_id = $2;"

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

Expand Down
19 changes: 18 additions & 1 deletion database/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Store interface {
UpdateTeamPassword(in *pb.UpdateTeamPassRequest) error
GetEventID(in *pb.GetEventIDReq) (int32, error)
UpdateCloseEvent(*pb.UpdateEventRequest) (string, error)
DelTeam(request *pb.DelTeamRequest) (string, error)
}

func NewStore(conf *model.Config) (Store, error) {
Expand Down Expand Up @@ -117,7 +118,23 @@ func (s *store) AddTeam(in *pb.AddTeamRequest) (string, error) {
if err != nil {
return "", err
}
return "Team correctly added!", nil
return fmt.Sprintf("Team [ %s ] correctly added to event [ %s ]", in.Name, in.EventTag), nil
}

func (s *store) DelTeam(req *pb.DelTeamRequest) (string, error) {
s.m.Lock()
defer s.m.Unlock()

var eventId int
if err := s.db.QueryRow(QueryEventId, req.EvTag).Scan(&eventId); err != nil {
return "", err
}
_, err := s.db.Exec(DelTeamQuery, req.TeamId, eventId)
if err != nil {
return "", err
}
return fmt.Sprintf("Team [ %s ] is deleted from event tag [ %s ]", req.TeamId, req.EvTag), nil

}

func (s *store) GetEvents(in *pb.GetEventRequest) ([]model.Event, error) {
Expand Down
Loading

0 comments on commit 9fb9c66

Please sign in to comment.