sync: Extract function that import flags from importer
This commit is contained in:
parent
3f55845374
commit
4039a394b5
8 changed files with 438 additions and 294 deletions
|
|
@ -4,13 +4,13 @@ import ()
|
|||
|
||||
// FlagChoice represents a choice a respond to a classic flag
|
||||
type FlagChoice struct {
|
||||
Id int64 `json:"id"`
|
||||
Id int64 `json:"id"`
|
||||
// IdFlag is the identifier of the underlying flag
|
||||
IdFlag int64 `json:"idFlag"`
|
||||
IdFlag int64 `json:"idFlag"`
|
||||
// Label is the title of the choice as displayed to players
|
||||
Label string `json:"label"`
|
||||
Label string `json:"label"`
|
||||
// Value is the raw content that'll be written as response if this choice is selected
|
||||
Value string `json:"value"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// GetChoices returns a list of choices for the given Flag.
|
||||
|
|
@ -48,13 +48,12 @@ func (f FlagKey) GetChoice(id int64) (c FlagChoice, err error) {
|
|||
}
|
||||
|
||||
// AddChoice creates and fills a new struct FlagChoice, from a label and a value.
|
||||
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 {
|
||||
return FlagChoice{}, err
|
||||
func (f FlagKey) AddChoice(c FlagChoice) (FlagChoice, error) {
|
||||
if res, err := DBExec("INSERT INTO flag_choices (id_flag, label, response) VALUES (?, ?, ?)", f.Id, c.Label, c.Value); err != nil {
|
||||
return c, err
|
||||
} else {
|
||||
return FlagChoice{cid, f.Id, label, value}, nil
|
||||
c.Id, err = res.LastInsertId()
|
||||
return c, err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue