admin: Really expose route to update team history
Related-to: a35aa7be70
This commit is contained in:
parent
a0bc832910
commit
c7fc18bfb4
2 changed files with 17 additions and 7 deletions
|
@ -1,7 +1,6 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
|
@ -146,6 +145,7 @@ func declareTeamsRoutes(router *gin.RouterGroup) {
|
|||
|
||||
c.JSON(http.StatusOK, history)
|
||||
})
|
||||
apiTeamsRoutes.PATCH("/history.json", updateHistory)
|
||||
apiTeamsRoutes.DELETE("/history.json", delHistory)
|
||||
apiTeamsPublicRoutes.GET("/tries", func(c *gin.Context) {
|
||||
team := c.MustGet("team").(*fic.Team)
|
||||
|
@ -486,10 +486,14 @@ type uploadedHistory struct {
|
|||
Coefficient float32
|
||||
}
|
||||
|
||||
func updateHistory(team *fic.Team, body []byte) (interface{}, error) {
|
||||
func updateHistory(c *gin.Context) {
|
||||
team := c.MustGet("team").(*fic.Team)
|
||||
|
||||
var uh uploadedHistory
|
||||
if err := json.Unmarshal(body, &uh); err != nil {
|
||||
return nil, err
|
||||
err := c.ShouldBindJSON(&uh)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
var givenId int64
|
||||
|
@ -499,7 +503,13 @@ func updateHistory(team *fic.Team, body []byte) (interface{}, error) {
|
|||
givenId = *uh.Primary
|
||||
}
|
||||
|
||||
return team.UpdateHistoryCoeff(uh.Kind, uh.Time, givenId, uh.Coefficient)
|
||||
_, err = team.UpdateHistoryCoeff(uh.Kind, uh.Time, givenId, uh.Coefficient)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to update this history line: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, true)
|
||||
}
|
||||
|
||||
func delHistory(c *gin.Context) {
|
||||
|
|
Reference in a new issue