Add API for keys and files
This commit is contained in:
parent
381aefa597
commit
8655997246
3 changed files with 153 additions and 53 deletions
|
|
@ -18,15 +18,6 @@ type uploadedTheme struct {
|
|||
Name string
|
||||
}
|
||||
|
||||
type uploadedExercice struct {
|
||||
Title string
|
||||
Statement string
|
||||
Hint string
|
||||
Depend *int
|
||||
Gain int
|
||||
VideoURI string
|
||||
}
|
||||
|
||||
func getTheme(args []string) (fic.Theme, error) {
|
||||
if tid, err := strconv.Atoi(string(args[0])); err != nil {
|
||||
return fic.Theme{}, err
|
||||
|
|
@ -46,43 +37,33 @@ func getExercice(args []string) (fic.Exercice, error) {
|
|||
}
|
||||
|
||||
func listTheme(args []string, body []byte) (interface{}, error) {
|
||||
if len(args) == 2 {
|
||||
if len(args) == 3 {
|
||||
if e, err := getExercice(args); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if args[2] == "files" {
|
||||
return e.GetFiles()
|
||||
} else if args[2] == "keys" {
|
||||
return e.GetKeys()
|
||||
}
|
||||
}
|
||||
} else if len(args) == 2 {
|
||||
return getExercice(args)
|
||||
} else if len(args) == 1 {
|
||||
return getTheme(args)
|
||||
} else if len(args) == 0 {
|
||||
// List all themes
|
||||
return fic.GetThemes()
|
||||
} else {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func creationTheme(args []string, body []byte) (interface{}, error) {
|
||||
if len(args) == 1 {
|
||||
if len(args) >= 1 {
|
||||
if theme, err := getTheme(args); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
// Create a new exercice
|
||||
var ue uploadedExercice
|
||||
if err := json.Unmarshal(body, &ue); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(ue.Title) == 0 {
|
||||
return nil, errors.New("Title not filled")
|
||||
}
|
||||
|
||||
var depend *fic.Exercice = nil
|
||||
if ue.Depend != nil {
|
||||
if d, err := fic.GetExercice(*ue.Depend); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
depend = &d
|
||||
}
|
||||
}
|
||||
|
||||
return theme.AddExercice(ue.Title, ue.Statement, ue.Hint, depend, ue.Gain, ue.VideoURI)
|
||||
return createExercice(theme, args[1:], body)
|
||||
}
|
||||
} else if len(args) == 0 {
|
||||
// Create a new theme
|
||||
|
|
|
|||
Reference in a new issue