feat: now user can top up via redemption code (close #9)

This commit is contained in:
JustSong
2023-04-26 17:02:26 +08:00
parent e7a809b082
commit 9e2f2383b9
13 changed files with 886 additions and 14 deletions

View File

@@ -201,3 +201,34 @@ func UpdateToken(c *gin.Context) {
})
return
}
type topUpRequest struct {
Id int `json:"id"`
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
}
quota, err := model.Redeem(req.Key, req.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
}