sync: Extract function that import flags from importer

This commit is contained in:
nemunaire 2019-07-05 22:28:56 +02:00
parent 3f55845374
commit 4039a394b5
8 changed files with 454 additions and 310 deletions

View file

@ -103,8 +103,8 @@ func exportResolutionMovies(_ httprouter.Params, body []byte) (interface{}, erro
} else {
export = append(export, map[string]string{
"videoURI": exercice.VideoURI,
"theme": theme.Name,
"title": exercice.Title,
"theme": theme.Name,
"title": exercice.Title,
})
}
}
@ -141,7 +141,7 @@ func getExerciceHistory(exercice fic.Exercice, body []byte) (interface{}, error)
}
type uploadedExerciceHistory struct {
IdTeam int64 `json:"team_id"`
IdTeam int64 `json:"team_id"`
Kind string
Time time.Time
Secondary *int64
@ -407,13 +407,8 @@ func deleteExerciceFlag(flag fic.FlagKey, _ fic.Exercice, _ []byte) (interface{}
return flag.Delete()
}
type uploadedChoice struct {
Label string
Value string
}
func createFlagChoice(flag fic.FlagKey, exercice fic.Exercice, body []byte) (interface{}, error) {
var uc uploadedChoice
var uc fic.FlagChoice
if err := json.Unmarshal(body, &uc); err != nil {
return nil, err
}
@ -422,7 +417,7 @@ func createFlagChoice(flag fic.FlagKey, exercice fic.Exercice, body []byte) (int
uc.Label = uc.Value
}
return flag.AddChoice(uc.Label, uc.Value)
return flag.AddChoice(uc)
}
func showFlagChoice(choice fic.FlagChoice, _ fic.Exercice, body []byte) (interface{}, error) {
@ -430,7 +425,7 @@ func showFlagChoice(choice fic.FlagChoice, _ fic.Exercice, body []byte) (interfa
}
func updateFlagChoice(choice fic.FlagChoice, _ fic.Exercice, body []byte) (interface{}, error) {
var uc uploadedChoice
var uc fic.FlagChoice
if err := json.Unmarshal(body, &uc); err != nil {
return nil, err
}
@ -503,7 +498,7 @@ func updateExerciceQuiz(quiz fic.MCQ, exercice fic.Exercice, body []byte) (inter
// Add new choices
for _, choice := range uq.Entries {
if choice.Id == 0 {
if c, err := quiz.AddEntry(choice.Label, choice.Response); err != nil {
if c, err := quiz.AddEntry(choice); err != nil {
return nil, err
} else {
quiz.Entries = append(quiz.Entries, c)
@ -553,7 +548,6 @@ func deleteExerciceFile(file fic.EFile, _ []byte) (interface{}, error) {
return file.Delete()
}
func listExerciceTags(exercice fic.Exercice, _ []byte) (interface{}, error) {
return exercice.GetTags()
}