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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user