admin: Add ability to append element to exercice history
This commit is contained in:
parent
ae5068f8b8
commit
977caccc1f
6 changed files with 237 additions and 3 deletions
|
@ -35,6 +35,7 @@ func declareExercicesRoutes(router *gin.RouterGroup) {
|
|||
apiExercicesRoutes.GET("/stats.json", getExerciceStats)
|
||||
|
||||
apiExercicesRoutes.GET("/history.json", getExerciceHistory)
|
||||
apiExercicesRoutes.PUT("/history.json", appendExerciceHistory)
|
||||
apiExercicesRoutes.PATCH("/history.json", updateExerciceHistory)
|
||||
apiExercicesRoutes.DELETE("/history.json", delExerciceHistory)
|
||||
|
||||
|
@ -476,6 +477,26 @@ type uploadedExerciceHistory struct {
|
|||
Coeff float32
|
||||
}
|
||||
|
||||
func appendExerciceHistory(c *gin.Context) {
|
||||
exercice := c.MustGet("exercice").(*fic.Exercice)
|
||||
|
||||
var uh uploadedExerciceHistory
|
||||
err := c.ShouldBindJSON(&uh)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
err = exercice.AppendHistoryItem(uh.IdTeam, uh.Kind, uh.Secondary)
|
||||
if err != nil {
|
||||
log.Println("Unable to appendExerciceHistory:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs during history moditication."})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, uh)
|
||||
}
|
||||
|
||||
func updateExerciceHistory(c *gin.Context) {
|
||||
exercice := c.MustGet("exercice").(*fic.Exercice)
|
||||
|
||||
|
|
Reference in a new issue