Fix player deletion. Add PersonaID + NucleusID fetching upon Add-Player action.
This commit is contained in:
@@ -37,6 +37,10 @@ func GetAllPlayers(c *gin.Context) {
|
||||
func GetPlayersByClanHTML(c *gin.Context) {
|
||||
var players []models.Player
|
||||
clanId := c.Request.URL.Query().Get("clan_id")
|
||||
if clanId == "NaN" {
|
||||
c.String(http.StatusBadRequest, "")
|
||||
return
|
||||
}
|
||||
if err := models.DB.
|
||||
Where("clan_id = ?", utils.StringToUint(clanId)).
|
||||
Find(&players).Error; err != nil {
|
||||
@@ -103,7 +107,14 @@ func AddPlayer(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
player = models.Player{Name: input.Name, ClanID: input.ClanID}
|
||||
personaID, nucleusID, statusCode := GetPlayerIds(input.Name)
|
||||
if personaID == 0 || nucleusID == 0 {
|
||||
c.JSON(statusCode, gin.H{"error": "Player not found!"})
|
||||
utils.Logger.Errorf("[PLAYER] Could not find player! Name: %s, Status: %d", input.Name, statusCode)
|
||||
return
|
||||
}
|
||||
|
||||
player = models.Player{Name: input.Name, ClanID: input.ClanID, PersonaID: personaID, NucleusID: nucleusID}
|
||||
if err := models.DB.Create(&player); err.Error != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error.Error()})
|
||||
utils.Logger.Errorf("[PLAYER] Could not create player! Error: %s", err.Error.Error())
|
||||
@@ -168,7 +179,7 @@ func UpdatePlayerByID(c *gin.Context) {
|
||||
func DeletePlayerByID(c *gin.Context) {
|
||||
var player models.Player
|
||||
|
||||
if err := models.DB.Clauses(clause.Returning{}).Delete(&player).Error; err != nil {
|
||||
if err := models.DB.Clauses(clause.Returning{}).Where("id = ?", c.Param("id")).Delete(&player).Error; err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
utils.Logger.Errorf("[PLAYER] Could not delete player! Error: %s", err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user