Add clan-purge and player-purge. Optimized performance with template-init.

This commit is contained in:
MaxJa4
2024-01-20 17:14:47 +01:00
parent e5d13f2270
commit 9e3e2723d3
6 changed files with 94 additions and 59 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"log"
"net/http"
)
@@ -131,6 +132,20 @@ func DeleteClanByID(c *gin.Context) {
}
}
// DeleteAllClans DELETE /admin/clan
func DeleteAllClans(c *gin.Context) {
var clans []models.Clan
if err := models.DB.
Session(&gorm.Session{AllowGlobalUpdate: true}).
Clauses(clause.Returning{}).
Delete(&clans).Error; err != nil {
c.String(http.StatusBadRequest, "Purge failed! Error: "+err.Error())
return
}
c.String(http.StatusOK, "Purged "+utils.UintToString(uint(len(clans)))+" clans!")
}
func FindClanByName(out interface{}, name string) *gorm.DB {
return models.DB.Where("name = ?", name).First(out)
}