admin: Better identify tries on exercice page
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
38e3a4efdf
commit
f6713c768b
6 changed files with 177 additions and 3 deletions
|
@ -36,9 +36,16 @@ func declareExercicesRoutes(router *gin.RouterGroup) {
|
|||
|
||||
apiExercicesRoutes.POST("/diff-sync", APIDiffExerciceWithRemote)
|
||||
|
||||
apiExercicesRoutes.GET("/history.json", getExerciceHistory)
|
||||
|
||||
apiExercicesRoutes.GET("/stats.json", getExerciceStats)
|
||||
|
||||
apiExercicesRoutes.GET("/history.json", getExerciceHistory)
|
||||
apiExercicesRoutes.GET("/tries", listTries)
|
||||
|
||||
apiTriesRoutes := apiExercicesRoutes.Group("/tries/:trid")
|
||||
apiTriesRoutes.Use(ExerciceTryHandler)
|
||||
apiTriesRoutes.GET("", getExerciceTry)
|
||||
apiTriesRoutes.DELETE("", deleteExerciceTry)
|
||||
|
||||
apiHistoryRoutes := apiExercicesRoutes.Group("/history.json")
|
||||
apiHistoryRoutes.Use(AssigneeCookieHandler)
|
||||
|
@ -1619,3 +1626,58 @@ func APIDiffExerciceWithRemote(c *gin.Context) {
|
|||
|
||||
c.JSON(http.StatusOK, diffs)
|
||||
}
|
||||
|
||||
func listTries(c *gin.Context) {
|
||||
exercice := c.MustGet("exercice").(*fic.Exercice)
|
||||
|
||||
tries, err := exercice.TriesList()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, tries)
|
||||
}
|
||||
|
||||
func ExerciceTryHandler(c *gin.Context) {
|
||||
trid, err := strconv.ParseInt(string(c.Params.ByName("trid")), 10, 32)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Invalid try identifier"})
|
||||
return
|
||||
}
|
||||
|
||||
exercice := c.MustGet("exercice").(*fic.Exercice)
|
||||
try, err := exercice.GetTry(trid)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Try not found"})
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("try", try)
|
||||
|
||||
c.Next()
|
||||
}
|
||||
|
||||
func getExerciceTry(c *gin.Context) {
|
||||
try := c.MustGet("try").(*fic.ExerciceTry)
|
||||
|
||||
err := try.FillDetails()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, try)
|
||||
}
|
||||
|
||||
func deleteExerciceTry(c *gin.Context) {
|
||||
try := c.MustGet("try").(*fic.ExerciceTry)
|
||||
|
||||
_, err := try.Delete()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
|
Reference in a new issue