Add admin-route & dropdown-menu. Add clear-cache & create-code. Adjustments for activation-code and user models. Add sweet-alert for admin-tools.

This commit is contained in:
MaxJa4
2024-01-20 16:47:22 +01:00
parent f2ab72ba1e
commit e5d13f2270
15 changed files with 281 additions and 55 deletions

View File

@@ -5,6 +5,7 @@ import (
"InfantrySkillCalculator/utils"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"net/http"
"time"
)
@@ -49,8 +50,6 @@ func AddCache(c *gin.Context) {
cache := models.PlayerCache{CacheDate: input.CacheDate, PlayerID: input.PlayerID, Score: input.Score, Game: input.Game}
//CreateOrUpdateCache(cache)
c.JSON(http.StatusOK, cache)
}
@@ -68,15 +67,11 @@ func UpdateCacheByPlayerID(c *gin.Context) {
return
}
//log.Println("Updating cache for player #" + utils.UintToString(cache.PlayerID))
models.DB.Model(&cache).Updates(map[string]interface{}{
"CacheDate": input.CacheDate,
"Score": input.Score,
})
//UpdateCacheTimestamp()
c.JSON(http.StatusOK, cache)
}
@@ -90,11 +85,21 @@ func DeleteCacheByPlayerID(c *gin.Context) {
models.DB.Delete(&cache)
//UpdateCacheTimestamp()
c.JSON(http.StatusOK, true)
}
//log.Println("Deleted cache for player #" + utils.UintToString(cache.PlayerID))
// DeleteAllCaches DELETE /cache
func DeleteAllCaches(c *gin.Context) {
var caches []models.PlayerCache
if err := models.DB.
Session(&gorm.Session{AllowGlobalUpdate: true}).
Clauses(clause.Returning{}).
Delete(&caches).Error; err != nil {
c.String(http.StatusBadRequest, "Purge failed! Error: "+err.Error())
return
}
c.String(http.StatusOK, "Purged "+utils.UintToString(uint(len(caches)))+" caches!")
}
func FindCacheGin(out interface{}, c *gin.Context) *gorm.DB {