Add clan-purge and player-purge. Optimized performance with template-init.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -145,6 +146,20 @@ func DeletePlayerByID(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteAllPlayers DELETE /admin/player
|
||||
func DeleteAllPlayers(c *gin.Context) {
|
||||
var players []models.Player
|
||||
if err := models.DB.
|
||||
Session(&gorm.Session{AllowGlobalUpdate: true}).
|
||||
Clauses(clause.Returning{}).
|
||||
Delete(&players).Error; err != nil {
|
||||
c.String(http.StatusBadRequest, "Purge failed! Error: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.String(http.StatusOK, "Purged "+utils.UintToString(uint(len(players)))+" players!")
|
||||
}
|
||||
|
||||
func FindPlayerByID(id uint) *models.Player {
|
||||
var res models.Player
|
||||
if err := models.DB.Where("id = ?", id).First(&res).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user