admin: Use gin-gonic as router

This commit is contained in:
nemunaire 2022-05-16 11:38:46 +02:00
commit 8b3fbdb64a
32 changed files with 2748 additions and 1598 deletions

View file

@ -3,12 +3,13 @@ package sync
import (
"fmt"
"log"
"net/http"
"path"
"strconv"
"strings"
"github.com/BurntSushi/toml"
"github.com/julienschmidt/httprouter"
"github.com/gin-gonic/gin"
"github.com/russross/blackfriday/v2"
"srs.epita.fr/fic-server/libfic"
@ -308,26 +309,36 @@ func SyncExercices(i Importer, theme *fic.Theme) (errs []string) {
}
// ApiListRemoteExercices is an accessor letting foreign packages to access remote exercices list.
func ApiListRemoteExercices(ps httprouter.Params, _ []byte) (interface{}, error) {
theme, errs := BuildTheme(GlobalImporter, ps.ByName("thid"))
func ApiListRemoteExercices(c *gin.Context) {
theme, errs := BuildTheme(GlobalImporter, c.Params.ByName("thid"))
if theme != nil {
return GetExercices(GlobalImporter, theme)
exercices, err := GetExercices(GlobalImporter, theme)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
return
}
c.JSON(http.StatusOK, exercices)
} else {
return nil, fmt.Errorf("%q", errs)
c.AbortWithStatusJSON(http.StatusInternalServerError, fmt.Errorf("%q", errs))
return
}
}
// 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"))
func ApiGetRemoteExercice(c *gin.Context) {
theme, errs := BuildTheme(GlobalImporter, c.Params.ByName("thid"))
if theme != nil {
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, ps.ByName("exid")), nil)
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil)
if exercice != nil {
return exercice, nil
c.JSON(http.StatusOK, exercice)
return
} else {
return exercice, fmt.Errorf("%q", errs)
c.JSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Errorf("%q", errs)})
return
}
} else {
return nil, fmt.Errorf("%q", errs)
c.JSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Errorf("%q", errs)})
return
}
}