MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / UpdateRedemption

Function UpdateRedemption

controller/redemption.go:135–172  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

133}
134
135func UpdateRedemption(c *gin.Context) {
136 statusOnly := c.Query("status_only")
137 redemption := model.Redemption{}
138 err := c.ShouldBindJSON(&redemption)
139 if err != nil {
140 common.ApiError(c, err)
141 return
142 }
143 cleanRedemption, err := model.GetRedemptionById(redemption.Id)
144 if err != nil {
145 common.ApiError(c, err)
146 return
147 }
148 if statusOnly == "" {
149 if err := validateExpiredTime(redemption.ExpiredTime); err != nil {
150 c.JSON(http.StatusOK, gin.H{"success": false, "message": err.Error()})
151 return
152 }
153 // If you add more fields, please also update redemption.Update()
154 cleanRedemption.Name = redemption.Name
155 cleanRedemption.Quota = redemption.Quota
156 cleanRedemption.ExpiredTime = redemption.ExpiredTime
157 }
158 if statusOnly != "" {
159 cleanRedemption.Status = redemption.Status
160 }
161 err = cleanRedemption.Update()
162 if err != nil {
163 common.ApiError(c, err)
164 return
165 }
166 c.JSON(http.StatusOK, gin.H{
167 "success": true,
168 "message": "",
169 "data": cleanRedemption,
170 })
171 return
172}
173
174func DeleteInvalidRedemption(c *gin.Context) {
175 rows, err := model.DeleteInvalidRedemptions()

Callers

nothing calls this directly

Calls 5

ApiErrorFunction · 0.92
GetRedemptionByIdFunction · 0.92
validateExpiredTimeFunction · 0.85
ErrorMethod · 0.80
UpdateMethod · 0.45

Tested by

no test coverage detected