admin: Add ability to append element to exercice history

This commit is contained in:
nemunaire 2024-03-17 10:19:35 +01:00
parent ae5068f8b8
commit 977caccc1f
6 changed files with 237 additions and 3 deletions

View file

@ -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)