Refactor flags

Both QCM and Key are Flag
This commit is contained in:
nemunaire 2019-01-02 21:51:09 +01:00
parent e029ec5414
commit a66d6885e7
13 changed files with 318 additions and 249 deletions

View file

@ -14,7 +14,7 @@ type FlagChoice struct {
}
// GetChoices returns a list of choices for the given Flag.
func (f Flag) GetChoices() ([]FlagChoice, error) {
func (f FlagKey) GetChoices() ([]FlagChoice, error) {
if rows, err := DBQuery("SELECT id_choice, id_flag, label, response FROM flag_choices WHERE id_flag = ?", f.Id); err != nil {
return nil, err
} else {
@ -40,7 +40,7 @@ func (f Flag) GetChoices() ([]FlagChoice, error) {
}
// GetChoice returns a choice for the given Flag.
func (f Flag) GetChoice(id int64) (c FlagChoice, err error) {
func (f FlagKey) GetChoice(id int64) (c FlagChoice, err error) {
if errr := DBQueryRow("SELECT id_choice, id_flag, label, response FROM flag_choices WHERE id_choice = ?", id).Scan(&c.Id, &c.IdFlag, &c.Label, &c.Value); errr != nil {
return c, errr
}
@ -48,7 +48,7 @@ func (f Flag) GetChoice(id int64) (c FlagChoice, err error) {
}
// AddChoice creates and fills a new struct FlagChoice, from a label and a value.
func (f Flag) AddChoice(label string, value string) (FlagChoice, error) {
func (f FlagKey) AddChoice(label string, value string) (FlagChoice, error) {
if res, err := DBExec("INSERT INTO flag_choices (id_flag, label, response) VALUES (?, ?, ?)", f.Id, label, value); err != nil {
return FlagChoice{}, err
} else if cid, err := res.LastInsertId(); err != nil {
@ -81,7 +81,7 @@ func (c FlagChoice) Delete() (int64, error) {
}
// WipeFlags deletes flags coming with the challenge.
func (f Flag) WipeChoices() (int64, error) {
func (f FlagKey) WipeChoices() (int64, error) {
if res, err := DBExec("DELETE FROM flag_choices WHERE id_flag = ?", f.Id); err != nil {
return 0, err
} else if nb, err := res.RowsAffected(); err != nil {