chore: decrease token quota in ConsumeToken function

This commit modifies the ConsumeToken function in the token.go file to decrease the token quota by the specified amount. It replaces the previous code that directly updated the quota values with a call to the DecreaseTokenQuota function from the model package. This change improves code clarity and maintainability.

Closes #123
This commit is contained in:
Laisky.Cai 2024-06-25 06:15:07 +00:00
parent 671039f050
commit 4fd0b247d2

View File

@ -279,8 +279,14 @@ func ConsumeToken(c *gin.Context) {
return
}
cleanToken.UsedQuota += int64(tokenPatch.AddUsedQuota)
cleanToken.RemainQuota -= int64(tokenPatch.AddUsedQuota)
if err = model.DecreaseTokenQuota(cleanToken.Id, int64(tokenPatch.AddUsedQuota)); err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": err.Error(),
})
return
}
model.RecordConsumeLog(c.Request.Context(),
userID, 0, 0, 0, tokenPatch.AddReason, cleanToken.Name,
int64(tokenPatch.AddUsedQuota),