achei e consertei outro bug '-'

This commit is contained in:
2025-06-22 09:34:59 -03:00
parent 366d1c5538
commit abda2ed46d
4 changed files with 25 additions and 1 deletions

Binary file not shown.

View File

@@ -46,10 +46,16 @@ func anyEmpty(values ...string) bool {
}
func updateField(query string, args ...interface{}) error {
_, err := db.Exec(query, args...)
res, err := db.Exec(query, args...)
if err != nil {
log.Println(err)
}
rows, _ := res.RowsAffected()
if rows == 0 {
return fmt.Errorf("erro ao rodar query")
}
return err
}

View File

@@ -99,6 +99,7 @@ func main() {
e.GET("login", badreq)
e.GET("player", player_data)
e.GET("player/inv", inv_get)
e.GET("player/inv/:id", inv_del)
e.POST("player/update", player_updateInputs)
e.PATCH("player/:atb/:updown", player_update)

View File

@@ -382,3 +382,20 @@ func inv_get(c echo.Context) error {
InvItems: lista,
})
}
func inv_del(c echo.Context) error {
session, err := requireSession(c)
if err != nil {
return nil
}
if session["playerName"] == "" {
return jsonError(c, http.StatusUnauthorized, "você precisa estar logado para apagar um item")
}
itemID := c.Param("id")
err = updateField(fmt.Sprintf("DELETE FROM inv_%s WHERE id=?;", session["playerName"]), itemID)
if err != nil {
return jsonError(c, http.StatusInternalServerError, "erro ao deletar item.")
}
return jsonSuccess(c, "você item deletado")
}