Write docs!

This commit is contained in:
nemunaire 2018-03-09 19:07:08 +01:00
commit bcc598ebd5
37 changed files with 478 additions and 188 deletions

View file

@ -1,13 +1,13 @@
package api
import (
"encoding/json"
"encoding/hex"
"encoding/json"
"errors"
"strings"
"srs.epita.fr/fic-server/libfic"
"srs.epita.fr/fic-server/admin/sync"
"srs.epita.fr/fic-server/libfic"
"github.com/julienschmidt/httprouter"
)
@ -40,16 +40,23 @@ func init() {
router.GET("/api/exercices/:eid/quiz/:qid", apiHandler(quizHandler(showExerciceQuiz)))
router.DELETE("/api/exercices/:eid/quiz/:qid", apiHandler(quizHandler(deleteExerciceQuiz)))
// Synchronize
router.POST("/api/sync/exercices/:eid/files", apiHandler(exerciceHandler(
func(exercice fic.Exercice, _ []byte) (interface{}, error) { return sync.SyncExerciceFiles(sync.GlobalImporter, exercice), nil })))
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
return sync.SyncExerciceFiles(sync.GlobalImporter, exercice), nil
})))
router.POST("/api/sync/exercices/:eid/hints", apiHandler(exerciceHandler(
func(exercice fic.Exercice, _ []byte) (interface{}, error) { return sync.SyncExerciceHints(sync.GlobalImporter, exercice), nil })))
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
return sync.SyncExerciceHints(sync.GlobalImporter, exercice), nil
})))
router.POST("/api/sync/exercices/:eid/keys", apiHandler(exerciceHandler(
func(exercice fic.Exercice, _ []byte) (interface{}, error) { return sync.SyncExerciceKeys(sync.GlobalImporter, exercice), nil })))
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
return sync.SyncExerciceKeys(sync.GlobalImporter, exercice), nil
})))
router.POST("/api/sync/exercices/:eid/quiz", apiHandler(exerciceHandler(
func(exercice fic.Exercice, _ []byte) (interface{}, error) { return sync.SyncExerciceMCQ(sync.GlobalImporter, exercice), nil })))
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
return sync.SyncExerciceMCQ(sync.GlobalImporter, exercice), nil
})))
router.POST("/api/sync/exercices/:eid/fixurlid", apiHandler(exerciceHandler(
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
@ -131,13 +138,12 @@ func createExercice(theme fic.Theme, body []byte) (interface{}, error) {
return theme.AddExercice(ue.Title, ue.URLId, ue.Path, ue.Statement, ue.Overview, depend, ue.Gain, ue.VideoURI)
}
type uploadedHint struct {
Title string
Path string
Content string
Cost int64
URI string
Title string
Path string
Content string
Cost int64
URI string
}
func createExerciceHint(exercice fic.Exercice, body []byte) (interface{}, error) {
@ -151,7 +157,7 @@ func createExerciceHint(exercice fic.Exercice, body []byte) (interface{}, error)
} else if len(uh.URI) != 0 {
return sync.ImportFile(sync.GlobalImporter, uh.URI,
func(filePath string, origin string) (interface{}, error) {
return exercice.AddHint(uh.Title, "$FILES" + strings.TrimPrefix(filePath, fic.FilesDir), uh.Cost)
return exercice.AddHint(uh.Title, "$FILES"+strings.TrimPrefix(filePath, fic.FilesDir), uh.Cost)
})
} else {
return nil, errors.New("Hint's content not filled")
@ -185,7 +191,6 @@ func deleteExerciceHint(hint fic.EHint, _ []byte) (interface{}, error) {
return hint.Delete()
}
type uploadedKey struct {
Label string
Key string
@ -234,7 +239,6 @@ func deleteExerciceKey(key fic.Key, _ fic.Exercice, _ []byte) (interface{}, erro
return key.Delete()
}
func showExerciceQuiz(quiz fic.MCQ, _ fic.Exercice, body []byte) (interface{}, error) {
return quiz, nil
}