qa: Back to the same situation

This commit is contained in:
nemunaire 2022-11-07 01:00:04 +01:00
parent 00f84e43ca
commit 1aa82bb2ef
27 changed files with 1336 additions and 22 deletions

View file

@ -12,8 +12,7 @@ import (
)
func declareQARoutes(router *gin.RouterGroup) {
exercicesRoutes := router.Group("/qa/:eid")
exercicesRoutes.Use(exerciceHandler)
exercicesRoutes := router.Group("/qa")
exercicesRoutes.GET("", getExerciceQA)
exercicesRoutes.POST("", createExerciceQA)
@ -30,12 +29,21 @@ func declareQARoutes(router *gin.RouterGroup) {
}
func qaHandler(c *gin.Context) {
exercice := c.MustGet("exercice").(*fic.Exercice)
var qa *fic.QAQuery
if qid, err := strconv.ParseInt(string(c.Param("qid")), 10, 64); err != nil {
qid, err := strconv.ParseInt(string(c.Param("qid")), 10, 64)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Bad QA identifier."})
return
} else if qa, err = exercice.GetQAQuery(qid); err != nil {
}
if exercice, ok := c.Get("exercice"); ok {
qa, err = exercice.(*fic.Exercice).GetQAQuery(qid)
} else {
qa, err = fic.GetQAQuery(qid)
}
if err != nil {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "QA entry not found."})
return
}