refactor: bind quota to account instead of token (close #64, #31)

This commit is contained in:
JustSong
2023-05-16 11:26:09 +08:00
parent 7c56a36a1c
commit 01abed0a30
12 changed files with 240 additions and 176 deletions

View File

@@ -654,3 +654,34 @@ func EmailBind(c *gin.Context) {
})
return
}
type topUpRequest struct {
Key string `json:"key"`
}
func TopUp(c *gin.Context) {
req := topUpRequest{}
err := c.ShouldBindJSON(&req)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": err.Error(),
})
return
}
id := c.GetInt("id")
quota, err := model.Redeem(req.Key, id)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": quota,
})
return
}