feat: add redeem batch revocation
This commit is contained in:
@@ -54,6 +54,7 @@ func main() {
|
|||||||
admin.PUT("/users/:id", a.adminUpdateUser)
|
admin.PUT("/users/:id", a.adminUpdateUser)
|
||||||
admin.GET("/redeem", a.adminListRedeemBatches)
|
admin.GET("/redeem", a.adminListRedeemBatches)
|
||||||
admin.POST("/redeem", a.adminCreateRedeemBatch)
|
admin.POST("/redeem", a.adminCreateRedeemBatch)
|
||||||
|
admin.POST("/redeem/:id/revoke", a.adminRevokeRedeemBatch)
|
||||||
admin.GET("/settings", a.getSettings)
|
admin.GET("/settings", a.getSettings)
|
||||||
admin.PUT("/settings", a.putSettings)
|
admin.PUT("/settings", a.putSettings)
|
||||||
admin.POST("/webdav/test", a.testWebDAV)
|
admin.POST("/webdav/test", a.testWebDAV)
|
||||||
|
|||||||
@@ -129,6 +129,15 @@ func (a *App) redeem(c *gin.Context) {
|
|||||||
c.JSON(200, gin.H{"credits": amount})
|
c.JSON(200, gin.H{"credits": amount})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) adminRevokeRedeemBatch(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
if err := a.db.Model(&RedeemCode{}).Where("batch_id = ? AND status = ?", id, "unused").Update("status", "revoked").Error; err != nil {
|
||||||
|
c.JSON(500, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(200, gin.H{"ok": true})
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) adminListRedeemBatches(c *gin.Context) {
|
func (a *App) adminListRedeemBatches(c *gin.Context) {
|
||||||
var batches []RedeemBatch
|
var batches []RedeemBatch
|
||||||
if err := a.db.Order("id desc").Limit(100).Find(&batches).Error; err != nil {
|
if err := a.db.Order("id desc").Limit(100).Find(&batches).Error; err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user