Write docs!

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

View file

@ -21,7 +21,9 @@ func init() {
router.GET("/api/ca/", apiHandler(infoCA))
router.GET("/api/ca.pem", apiHandler(getCAPEM))
router.POST("/api/ca/new", apiHandler(
func(_ httprouter.Params, _ []byte) (interface{}, error) { return true, pki.GenerateCA(time.Date(2018, 01, 21, 0, 0, 0, 0, time.UTC), time.Date(2018, 01, 24, 23, 59, 59, 0, time.UTC)) }))
func(_ httprouter.Params, _ []byte) (interface{}, error) {
return true, pki.GenerateCA(time.Date(2018, 01, 21, 0, 0, 0, 0, time.UTC), time.Date(2018, 01, 24, 23, 59, 59, 0, time.UTC))
}))
router.GET("/api/teams/:tid/certificates", apiHandler(teamHandler(
func(team fic.Team, _ []byte) (interface{}, error) { return fic.GetTeamCertificates(team) })))
@ -142,7 +144,6 @@ func getCertificates(_ httprouter.Params, _ []byte) (interface{}, error) {
}
}
type CertUploaded struct {
Team *int64 `json:"id_team"`
}

View file

@ -119,7 +119,6 @@ func clearClaims(_ httprouter.Params, _ []byte) (interface{}, error) {
return fic.ClearClaims()
}
func addClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
var ud fic.ClaimDescription
if err := json.Unmarshal(body, &ud); err != nil {
@ -152,7 +151,6 @@ func deleteClaim(claim fic.Claim, _ []byte) (interface{}, error) {
return claim.Delete()
}
func getAssignees(_ httprouter.Params, _ []byte) (interface{}, error) {
return fic.GetAssignees()
}

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
}

View file

@ -14,7 +14,6 @@ import (
"github.com/julienschmidt/httprouter"
)
type DispatchFunction func(httprouter.Params, []byte) (interface{}, error)
func apiHandler(f DispatchFunction) func(http.ResponseWriter, *http.Request, httprouter.Params) {
@ -82,8 +81,8 @@ func apiHandler(f DispatchFunction) func(http.ResponseWriter, *http.Request, htt
}
}
func teamPublicHandler(f func(*fic.Team,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func teamPublicHandler(f func(*fic.Team, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if tid, err := strconv.ParseInt(string(ps.ByName("tid")), 10, 64); err != nil {
return nil, err
} else if tid == 0 {
@ -96,8 +95,8 @@ func teamPublicHandler(f func(*fic.Team,[]byte) (interface{}, error)) func (http
}
}
func teamHandler(f func(fic.Team,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func teamHandler(f func(fic.Team, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if tid, err := strconv.ParseInt(string(ps.ByName("tid")), 10, 64); err != nil {
return nil, err
} else if team, err := fic.GetTeam(tid); err != nil {
@ -108,8 +107,8 @@ func teamHandler(f func(fic.Team,[]byte) (interface{}, error)) func (httprouter.
}
}
func themeHandler(f func(fic.Theme,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func themeHandler(f func(fic.Theme, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if thid, err := strconv.Atoi(string(ps.ByName("thid"))); err != nil {
return nil, err
} else if theme, err := fic.GetTheme(thid); err != nil {
@ -120,8 +119,8 @@ func themeHandler(f func(fic.Theme,[]byte) (interface{}, error)) func (httproute
}
}
func exerciceHandler(f func(fic.Exercice,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func exerciceHandler(f func(fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if eid, err := strconv.Atoi(string(ps.ByName("eid"))); err != nil {
return nil, err
} else if exercice, err := fic.GetExercice(int64(eid)); err != nil {
@ -132,27 +131,27 @@ func exerciceHandler(f func(fic.Exercice,[]byte) (interface{}, error)) func (htt
}
}
func themedExerciceHandler(f func(fic.Theme,fic.Exercice,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func themedExerciceHandler(f func(fic.Theme, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
var theme fic.Theme
var exercice fic.Exercice
themeHandler(func (th fic.Theme, _[]byte) (interface{}, error) {
themeHandler(func(th fic.Theme, _ []byte) (interface{}, error) {
theme = th
return nil,nil
return nil, nil
})(ps, body)
exerciceHandler(func (ex fic.Exercice, _[]byte) (interface{}, error) {
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
exercice = ex
return nil,nil
return nil, nil
})(ps, body)
return f(theme, exercice, body)
}
}
func hintHandler(f func(fic.EHint,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func hintHandler(f func(fic.EHint, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if hid, err := strconv.Atoi(string(ps.ByName("hid"))); err != nil {
return nil, err
} else if hint, err := fic.GetHint(int64(hid)); err != nil {
@ -163,12 +162,12 @@ func hintHandler(f func(fic.EHint,[]byte) (interface{}, error)) func (httprouter
}
}
func keyHandler(f func(fic.Key,fic.Exercice,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func keyHandler(f func(fic.Key, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
var exercice fic.Exercice
exerciceHandler(func (ex fic.Exercice, _[]byte) (interface{}, error) {
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
exercice = ex
return nil,nil
return nil, nil
})(ps, body)
if kid, err := strconv.Atoi(string(ps.ByName("kid"))); err != nil {
@ -177,7 +176,7 @@ func keyHandler(f func(fic.Key,fic.Exercice,[]byte) (interface{}, error)) func (
return nil, err
} else {
for _, key := range keys {
if (key.Id == int64(kid)) {
if key.Id == int64(kid) {
return f(key, exercice, body)
}
}
@ -186,12 +185,12 @@ func keyHandler(f func(fic.Key,fic.Exercice,[]byte) (interface{}, error)) func (
}
}
func quizHandler(f func(fic.MCQ,fic.Exercice,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func quizHandler(f func(fic.MCQ, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
var exercice fic.Exercice
exerciceHandler(func (ex fic.Exercice, _[]byte) (interface{}, error) {
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
exercice = ex
return nil,nil
return nil, nil
})(ps, body)
if qid, err := strconv.Atoi(string(ps.ByName("qid"))); err != nil {
@ -200,7 +199,7 @@ func quizHandler(f func(fic.MCQ,fic.Exercice,[]byte) (interface{}, error)) func
return nil, err
} else {
for _, mcq := range mcqs {
if (mcq.Id == int64(qid)) {
if mcq.Id == int64(qid) {
return f(mcq, exercice, body)
}
}
@ -209,12 +208,12 @@ func quizHandler(f func(fic.MCQ,fic.Exercice,[]byte) (interface{}, error)) func
}
}
func exerciceFileHandler(f func(fic.EFile,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func exerciceFileHandler(f func(fic.EFile, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
var exercice fic.Exercice
exerciceHandler(func (ex fic.Exercice, _[]byte) (interface{}, error) {
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
exercice = ex
return nil,nil
return nil, nil
})(ps, body)
if fid, err := strconv.Atoi(string(ps.ByName("fid"))); err != nil {
@ -223,7 +222,7 @@ func exerciceFileHandler(f func(fic.EFile,[]byte) (interface{}, error)) func (ht
return nil, err
} else {
for _, file := range files {
if (file.Id == int64(fid)) {
if file.Id == int64(fid) {
return f(file, body)
}
}
@ -232,8 +231,8 @@ func exerciceFileHandler(f func(fic.EFile,[]byte) (interface{}, error)) func (ht
}
}
func eventHandler(f func(fic.Event,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func eventHandler(f func(fic.Event, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if evid, err := strconv.Atoi(string(ps.ByName("evid"))); err != nil {
return nil, err
} else if event, err := fic.GetEvent(evid); err != nil {
@ -244,8 +243,8 @@ func eventHandler(f func(fic.Event,[]byte) (interface{}, error)) func (httproute
}
}
func claimHandler(f func(fic.Claim,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func claimHandler(f func(fic.Claim, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if cid, err := strconv.Atoi(string(ps.ByName("cid"))); err != nil {
return nil, err
} else if claim, err := fic.GetClaim(cid); err != nil {
@ -256,8 +255,8 @@ func claimHandler(f func(fic.Claim,[]byte) (interface{}, error)) func (httproute
}
}
func claimAssigneeHandler(f func(fic.ClaimAssignee,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func claimAssigneeHandler(f func(fic.ClaimAssignee, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if aid, err := strconv.Atoi(string(ps.ByName("aid"))); err != nil {
return nil, err
} else if assignee, err := fic.GetAssignee(int64(aid)); err != nil {
@ -268,8 +267,8 @@ func claimAssigneeHandler(f func(fic.ClaimAssignee,[]byte) (interface{}, error))
}
}
func fileHandler(f func(fic.EFile,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func fileHandler(f func(fic.EFile, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if fileid, err := strconv.Atoi(string(ps.ByName("fileid"))); err != nil {
return nil, err
} else if file, err := fic.GetFile(fileid); err != nil {
@ -280,8 +279,8 @@ func fileHandler(f func(fic.EFile,[]byte) (interface{}, error)) func (httprouter
}
}
func certificateHandler(f func(fic.Certificate,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func certificateHandler(f func(fic.Certificate, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if certid, err := strconv.ParseUint(string(ps.ByName("certid")), 10, 64); err != nil {
return nil, err
} else if cert, err := fic.GetCertificate(certid); err != nil {

View file

@ -18,8 +18,8 @@ func init() {
}
type FICPublicScene struct {
Type string `json:"type"`
Params map[string]interface{} `json:"params"`
Type string `json:"type"`
Params map[string]interface{} `json:"params"`
}
func readPublic(path string) ([]FICPublicScene, error) {

View file

@ -37,18 +37,18 @@ func getSettings(_ httprouter.Params, body []byte) (interface{}, error) {
return settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile))
} else {
return settings.FICSettings{
Title: "Challenge FIC",
Authors: "Laboratoire SRS, ÉPITA",
Start: time.Unix(0,0),
End: time.Unix(0,0),
Generation: time.Unix(0,0),
FirstBlood: fic.FirstBlood,
SubmissionCostBase: fic.SubmissionCostBase,
AllowRegistration: false,
DenyNameChange: false,
Title: "Challenge FIC",
Authors: "Laboratoire SRS, ÉPITA",
Start: time.Unix(0, 0),
End: time.Unix(0, 0),
Generation: time.Unix(0, 0),
FirstBlood: fic.FirstBlood,
SubmissionCostBase: fic.SubmissionCostBase,
AllowRegistration: false,
DenyNameChange: false,
EnableResolutionRoute: false,
PartialValidation: true,
EnableExerciceDepend: true,
PartialValidation: true,
EnableExerciceDepend: true,
}, nil
}
}

View file

@ -3,7 +3,6 @@ package api
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
@ -14,37 +13,46 @@ import (
func init() {
router.GET("/api/teams.json", apiHandler(
func(httprouter.Params,[]byte) (interface{}, error) {
return fic.ExportTeams() }))
func(httprouter.Params, []byte) (interface{}, error) {
return fic.ExportTeams()
}))
router.GET("/api/teams-binding", apiHandler(
func(httprouter.Params,[]byte) (interface{}, error) {
return bindingTeams() }))
func(httprouter.Params, []byte) (interface{}, error) {
return bindingTeams()
}))
router.GET("/api/teams-nginx-members", apiHandler(
func(httprouter.Params,[]byte) (interface{}, error) {
return nginxGenMember() }))
func(httprouter.Params, []byte) (interface{}, error) {
return nginxGenMember()
}))
router.GET("/api/teams-tries.json", apiHandler(
func(httprouter.Params,[]byte) (interface{}, error) {
return fic.GetTries(nil, nil) }))
func(httprouter.Params, []byte) (interface{}, error) {
return fic.GetTries(nil, nil)
}))
router.GET("/api/teams/", apiHandler(
func(httprouter.Params,[]byte) (interface{}, error) {
return fic.GetTeams() }))
func(httprouter.Params, []byte) (interface{}, error) {
return fic.GetTeams()
}))
router.POST("/api/teams/", apiHandler(createTeam))
router.GET("/api/teams/:tid/", apiHandler(teamHandler(
func(team fic.Team, _ []byte) (interface{}, error) {
return team, nil })))
return team, nil
})))
router.PUT("/api/teams/:tid/", apiHandler(teamHandler(updateTeam)))
router.POST("/api/teams/:tid/", apiHandler(teamHandler(addTeamMember)))
router.DELETE("/api/teams/:tid/", apiHandler(teamHandler(
func(team fic.Team, _ []byte) (interface{}, error) {
return team.Delete() })))
return team.Delete()
})))
router.GET("/api/teams/:tid/my.json", apiHandler(teamPublicHandler(
func(team *fic.Team, _ []byte) (interface{}, error) {
return fic.MyJSONTeam(team, true) })))
return fic.MyJSONTeam(team, true)
})))
router.GET("/api/teams/:tid/wait.json", apiHandler(teamPublicHandler(
func(team *fic.Team, _ []byte) (interface{}, error) {
return fic.MyJSONTeam(team, false) })))
return fic.MyJSONTeam(team, false)
})))
router.GET("/api/teams/:tid/stats.json", apiHandler(teamPublicHandler(
func(team *fic.Team, _ []byte) (interface{}, error) {
if team != nil {
@ -64,14 +72,14 @@ func init() {
router.DELETE("/api/teams/:tid/history.json", apiHandler(teamPublicHandler(delHistory)))
router.GET("/api/teams/:tid/tries", apiHandler(teamPublicHandler(
func(team *fic.Team, _ []byte) (interface{}, error) {
return fic.GetTries(team, nil) })))
return fic.GetTries(team, nil)
})))
router.GET("/api/teams/:tid/members", apiHandler(teamHandler(
func(team fic.Team, _ []byte) (interface{}, error) {
return team.GetMembers() })))
return team.GetMembers()
})))
router.POST("/api/teams/:tid/members", apiHandler(teamHandler(addTeamMember)))
router.PUT("/api/teams/:tid/members", apiHandler(teamHandler(setTeamMember)))
router.GET("/api/members/:mid/team", apiHandler(dispMemberTeam))
}
func nginxGenMember() (string, error) {
@ -96,17 +104,17 @@ func nginxGenMember() (string, error) {
func bindingTeams() (string, error) {
if teams, err := fic.GetTeams(); err != nil {
return "", err
} else {
ret := ""
for _, team := range teams {
if members, err := team.GetMembers(); err != nil {
return "", err
} else {
ret := ""
for _, team := range teams {
if members, err := team.GetMembers(); err != nil {
return "", err
} else {
var mbs []string
var mbs []string
for _, member := range members {
mbs = append(mbs, fmt.Sprintf("%s %s", member.Firstname, member.Lastname))
mbs = append(mbs, fmt.Sprintf("%s %s", member.Firstname, member.Lastname))
}
ret += fmt.Sprintf("%d;%s;%s\n", team.Id, team.Name, strings.Join(mbs, ";"))
ret += fmt.Sprintf("%d;%s;%s\n", team.Id, team.Name, strings.Join(mbs, ";"))
}
}
return ret, nil
@ -176,15 +184,6 @@ func setTeamMember(team fic.Team, body []byte) (interface{}, error) {
return team.GetMembers()
}
func dispMemberTeam(ps httprouter.Params, body []byte) (interface{}, error) {
if mid, err := strconv.Atoi(string(ps.ByName("mid"))); err != nil {
return fic.Team{}, err
} else {
return fic.GetMember(mid)
}
}
type uploadedHistory struct {
Kind string
Time time.Time

View file

@ -29,7 +29,6 @@ func init() {
router.PUT("/api/themes/:thid/exercices/:eid", apiHandler(exerciceHandler(updateExercice)))
router.DELETE("/api/themes/:thid/exercices/:eid", apiHandler(exerciceHandler(deleteExercice)))
router.GET("/api/themes/:thid/exercices/:eid/files", apiHandler(exerciceHandler(listExerciceFiles)))
router.POST("/api/themes/:thid/exercices/:eid/files", apiHandler(exerciceHandler(createExerciceFile)))
@ -46,19 +45,33 @@ func init() {
// Synchronize
router.POST("/api/sync/deep", apiHandler(
func(_ httprouter.Params, _ []byte) (interface{}, error) { return sync.SyncDeep(sync.GlobalImporter), nil }))
func(_ httprouter.Params, _ []byte) (interface{}, error) {
return sync.SyncDeep(sync.GlobalImporter), nil
}))
router.POST("/api/sync/themes", apiHandler(
func(_ httprouter.Params, _ []byte) (interface{}, error) { return sync.SyncThemes(sync.GlobalImporter), nil }))
func(_ httprouter.Params, _ []byte) (interface{}, error) {
return sync.SyncThemes(sync.GlobalImporter), nil
}))
router.POST("/api/sync/themes/:thid/exercices", apiHandler(themeHandler(
func(theme fic.Theme, _ []byte) (interface{}, error) { return sync.SyncExercices(sync.GlobalImporter, theme), nil })))
func(theme fic.Theme, _ []byte) (interface{}, error) {
return sync.SyncExercices(sync.GlobalImporter, theme), nil
})))
router.POST("/api/sync/themes/:thid/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/themes/:thid/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/themes/:thid/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/themes/:thid/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/themes/:thid/fixurlid", apiHandler(themeHandler(
func(theme fic.Theme, _ []byte) (interface{}, error) {
@ -96,9 +109,9 @@ func fixAllURLIds(_ httprouter.Params, _ []byte) (interface{}, error) {
func bindingFiles(_ httprouter.Params, body []byte) (interface{}, error) {
if files, err := fic.GetFiles(); err != nil {
return "", err
} else {
ret := ""
for _, file := range files {
} else {
ret := ""
for _, file := range files {
ret += fmt.Sprintf("%s;%s\n", file.GetOrigin(), file.Path)
}
return ret, nil
@ -137,7 +150,6 @@ func showThemedExercice(theme fic.Theme, exercice fic.Exercice, body []byte) (in
return exercice, nil
}
type uploadedTheme struct {
Name string
URLId string