admin: add exercice history.json
This commit is contained in:
parent
1dd55a0f73
commit
b73eaa8b3f
4 changed files with 182 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/sync"
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
|
|
@ -21,6 +22,9 @@ func init() {
|
|||
router.PATCH("/api/exercices/:eid", apiHandler(exerciceHandler(partUpdateExercice)))
|
||||
router.DELETE("/api/exercices/:eid", apiHandler(exerciceHandler(deleteExercice)))
|
||||
|
||||
router.GET("/api/exercices/:eid/history.json", apiHandler(exerciceHandler(getExerciceHistory)))
|
||||
router.DELETE("/api/exercices/:eid/history.json", apiHandler(exerciceHandler(delExerciceHistory)))
|
||||
|
||||
router.GET("/api/exercices/:eid/files", apiHandler(exerciceHandler(listExerciceFiles)))
|
||||
router.POST("/api/exercices/:eid/files", apiHandler(exerciceHandler(createExerciceFile)))
|
||||
router.GET("/api/exercices/:eid/files/:fid", apiHandler(exerciceFileHandler(showExerciceFile)))
|
||||
|
|
@ -132,6 +136,26 @@ func showExercice(exercice fic.Exercice, body []byte) (interface{}, error) {
|
|||
return exercice, nil
|
||||
}
|
||||
|
||||
func getExerciceHistory(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
return exercice.GetHistory()
|
||||
}
|
||||
|
||||
type uploadedExerciceHistory struct {
|
||||
IdTeam int64 `json:"team_id"`
|
||||
Kind string
|
||||
Time time.Time
|
||||
Secondary *int64
|
||||
}
|
||||
|
||||
func delExerciceHistory(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uh uploadedExerciceHistory
|
||||
if err := json.Unmarshal(body, &uh); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return exercice.DelHistoryItem(uh.IdTeam, uh.Kind, uh.Time, uh.Secondary)
|
||||
}
|
||||
|
||||
func deleteExercice(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
return exercice.Delete()
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue