Save hashed PW. Simplify model update. Bugfixes & improvements. Working user-settings & games.
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"InfrantrySkillCalculator/models"
|
||||
"InfrantrySkillCalculator/utils"
|
||||
"InfantrySkillCalculator/models"
|
||||
"InfantrySkillCalculator/utils"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type AddClanInput struct {
|
||||
@@ -66,8 +65,6 @@ func AddClan(c *gin.Context) {
|
||||
clan = models.Clan{Name: input.Name, Tag: input.Tag, KeepUpdated: input.KeepUpdated}
|
||||
models.DB.Create(&clan)
|
||||
|
||||
//UpdateClanTimestamp()
|
||||
|
||||
c.JSON(http.StatusOK, clan)
|
||||
|
||||
_, err := fmt.Fprintf(utils.GinWriter, "Added clan '"+clan.Name+"' with tag '"+clan.Tag+"'\n")
|
||||
@@ -90,45 +87,30 @@ func GetClanByID(c *gin.Context) {
|
||||
|
||||
// UpdateClanByID PATCH /clan/:id
|
||||
func UpdateClanByID(c *gin.Context) {
|
||||
var clan models.Clan
|
||||
if err := FindClanByID(&clan, c).Error; err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Record not found!"})
|
||||
return
|
||||
}
|
||||
|
||||
var input UpdateClanInput
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
msg := "Updating clan '" + clan.Name + "'#" + strconv.FormatUint(uint64(clan.ID), 10)
|
||||
if clan.Name != input.Name {
|
||||
msg += " (new: '" + input.Name + "')"
|
||||
}
|
||||
msg += " with tag '" + clan.Tag + "'"
|
||||
if clan.Tag != input.Tag {
|
||||
msg += " (new: '" + input.Tag + "')"
|
||||
}
|
||||
msg += " with updating '" + strconv.FormatBool(clan.KeepUpdated) + "'"
|
||||
if clan.KeepUpdated != input.KeepUpdated {
|
||||
msg += " (new: '" + strconv.FormatBool(input.KeepUpdated) + "')"
|
||||
res := models.DB.Model(&models.Clan{}).
|
||||
Where("id = ?", c.Param("id")).
|
||||
Updates(map[string]interface{}{
|
||||
"Name": input.Name,
|
||||
"Tag": input.Tag,
|
||||
"KeepUpdated": input.KeepUpdated,
|
||||
})
|
||||
if res.Error != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": res.Error.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
_, err := fmt.Fprintf(utils.GinWriter, msg+"\n")
|
||||
c.JSON(http.StatusOK, nil)
|
||||
|
||||
_, err := fmt.Fprintf(utils.GinWriter, "Updated clan '"+input.Name+"' with tag '"+input.Tag+"'\n")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
models.DB.Model(&clan).Updates(map[string]interface{}{
|
||||
"Name": input.Name,
|
||||
"Tag": input.Tag,
|
||||
"KeepUpdated": input.KeepUpdated,
|
||||
})
|
||||
|
||||
//UpdateClanTimestamp()
|
||||
|
||||
c.JSON(http.StatusOK, clan)
|
||||
}
|
||||
|
||||
// DeleteClanByID DELETE /clan/:id
|
||||
@@ -141,8 +123,6 @@ func DeleteClanByID(c *gin.Context) {
|
||||
|
||||
models.DB.Delete(&clan)
|
||||
|
||||
//UpdateClanTimestamp()
|
||||
|
||||
c.JSON(http.StatusOK, true)
|
||||
|
||||
_, err := fmt.Fprintf(utils.GinWriter, "Deleted clan '"+clan.Name+"' with tag '"+clan.Tag+"'\n")
|
||||
|
||||
Reference in New Issue
Block a user