Move common structs to libfic

This commit is contained in:
nemunaire 2016-01-13 20:25:25 +01:00
parent d841542be4
commit 92b81e467f
10 changed files with 42 additions and 36 deletions

View file

@ -4,6 +4,8 @@ import (
"encoding/json"
"errors"
"strconv"
"srs.epita.fr/fic-server/libfic"
)
var ApiThemesRouting = map[string]DispatchFunction{
@ -25,19 +27,19 @@ type uploadedExercice struct {
VideoURI string
}
func getTheme(args []string) (Theme, error) {
func getTheme(args []string) (fic.Theme, error) {
if tid, err := strconv.Atoi(string(args[0])); err != nil {
return Theme{}, err
return fic.Theme{}, err
} else {
return GetTheme(tid)
return fic.GetTheme(tid)
}
}
func getExercice(args []string) (Exercice, error) {
func getExercice(args []string) (fic.Exercice, error) {
if theme, err := getTheme(args); err != nil {
return Exercice{}, err
return fic.Exercice{}, err
} else if eid, err := strconv.Atoi(string(args[1])); err != nil {
return Exercice{}, err
return fic.Exercice{}, err
} else {
return theme.GetExercice(eid)
}
@ -50,7 +52,7 @@ func listTheme(args []string, body []byte) (interface{}, error) {
return getTheme(args)
} else if len(args) == 0 {
// List all themes
return GetThemes()
return fic.GetThemes()
} else {
return nil, nil
}
@ -71,9 +73,9 @@ func creationTheme(args []string, body []byte) (interface{}, error) {
return nil, errors.New("Title not filled")
}
var depend *Exercice = nil
var depend *fic.Exercice = nil
if ue.Depend != nil {
if d, err := GetExercice(*ue.Depend); err != nil {
if d, err := fic.GetExercice(*ue.Depend); err != nil {
return nil, err
} else {
depend = &d
@ -93,7 +95,7 @@ func creationTheme(args []string, body []byte) (interface{}, error) {
return nil, errors.New("Theme's name not filled")
}
return CreateTheme(ut.Name)
return fic.CreateTheme(ut.Name)
} else {
return nil, nil
}