api: remote route takes advantage from builds functions
This commit is contained in:
parent
ded583008a
commit
f2fc142869
6 changed files with 83 additions and 6 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"gopkg.in/russross/blackfriday.v2"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
|
@ -264,6 +265,26 @@ func SyncExercices(i Importer, theme fic.Theme) (errs []string) {
|
|||
}
|
||||
|
||||
// ApiListRemoteExercices is an accessor letting foreign packages to access remote exercices list.
|
||||
func ApiListRemoteExercices(theme fic.Theme, _ []byte) (interface{}, error) {
|
||||
return GetExercices(GlobalImporter, theme)
|
||||
func ApiListRemoteExercices(ps httprouter.Params, _ []byte) (interface{}, error) {
|
||||
theme, errs := BuildTheme(GlobalImporter, ps.ByName("thid"))
|
||||
if theme != nil {
|
||||
return GetExercices(GlobalImporter, *theme)
|
||||
} else {
|
||||
return nil, errors.New(fmt.Sprintf("%q", errs))
|
||||
}
|
||||
}
|
||||
|
||||
// ApiListRemoteExercice is an accessor letting foreign packages to access remote exercice attributes.
|
||||
func ApiGetRemoteExercice(ps httprouter.Params, _ []byte) (interface{}, error) {
|
||||
theme, errs := BuildTheme(GlobalImporter, ps.ByName("thid"))
|
||||
if theme != nil {
|
||||
exercice, _, _, _, errs := BuildExercice(GlobalImporter, *theme, path.Join(theme.Path, ps.ByName("exid")), nil)
|
||||
if exercice != nil {
|
||||
return exercice, nil
|
||||
} else {
|
||||
return exercice, errors.New(fmt.Sprintf("%q", errs))
|
||||
}
|
||||
} else {
|
||||
return nil, errors.New(fmt.Sprintf("%q", errs))
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue