parte do cliente completa, falta so a parte do obs e do mestre.
This commit is contained in:
Binary file not shown.
@@ -102,6 +102,9 @@ func main() {
|
||||
e.POST("player/inv", inv_add)
|
||||
e.GET("player/inv/del/:id", inv_del)
|
||||
e.GET("player/inv/use/:id", inv_use)
|
||||
e.GET("player/inv/ph", inv_ph)
|
||||
e.GET("player/inv/ph/del/:id", inv_phDel)
|
||||
e.POST("player/inv/ph", inv_phAdd)
|
||||
e.POST("player/update", player_updateInputs)
|
||||
e.PATCH("player/:atb/:updown", player_update)
|
||||
|
||||
|
||||
@@ -417,7 +417,7 @@ func inv_del(c echo.Context) error {
|
||||
return jsonError(c, http.StatusInternalServerError, "erro ao deletar item.")
|
||||
}
|
||||
|
||||
return jsonSuccess(c, "você item deletado")
|
||||
return jsonSuccess(c, "você deletou um item")
|
||||
}
|
||||
|
||||
func inv_use(c echo.Context) error {
|
||||
@@ -512,3 +512,82 @@ func inv_add(c echo.Context) error {
|
||||
|
||||
return jsonSuccess(c, fmt.Sprintf("%s %ss foram colocados no seu inventário.", quantidade, nome))
|
||||
}
|
||||
func inv_ph(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 adicionar itens ao inventário.")
|
||||
}
|
||||
|
||||
row, err := db.Query(fmt.Sprintf("SELECT * FROM invPower_%s ORDER BY id DESC;", session["playerName"]))
|
||||
if err != nil {
|
||||
log.Println("Erro ao consultar sua lista de habilidade.")
|
||||
return jsonError(c, http.StatusInternalServerError, "Erro ao consultar sua lista de habilidade.")
|
||||
}
|
||||
defer row.Close()
|
||||
|
||||
var lista []plyPwr
|
||||
for row.Next() {
|
||||
var id int
|
||||
var nome, desc string
|
||||
if err := row.Scan(&id, &nome, &desc); err != nil {
|
||||
return jsonError(c, http.StatusInternalServerError, "algo deu errado ao montar lista de rolagem")
|
||||
}
|
||||
lista = append(lista, plyPwr{ID: id, Name: nome, Desc: desc})
|
||||
}
|
||||
|
||||
sort.Slice(lista, func(i, j int) bool {
|
||||
return lista[i].ID < lista[j].ID
|
||||
})
|
||||
|
||||
if len(lista) == 0 {
|
||||
return jsonError(c, http.StatusNotFound, "você ainda não tem habilidades")
|
||||
}
|
||||
return c.JSON(http.StatusOK, resp_json{
|
||||
Status: "Success",
|
||||
InvPws: lista,
|
||||
})
|
||||
}
|
||||
|
||||
func inv_phAdd(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 adicionar itens ao inventário.")
|
||||
}
|
||||
|
||||
nome := c.FormValue("nameph")
|
||||
desc := c.FormValue("descph")
|
||||
|
||||
if anyEmpty(nome, desc) {
|
||||
return jsonError(c, http.StatusBadRequest, "Algum parâmetro está faltando ou está vazio. Tente novamente.")
|
||||
}
|
||||
|
||||
_, err = db.Exec(fmt.Sprintf("INSERT INTO invPower_%s (name_power, desc_power) VALUES (?, ?)", session["playerName"]), nome, desc)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return jsonError(c, http.StatusInternalServerError, fmt.Sprintf("erro ao adicionar %s a sua lista", nome))
|
||||
}
|
||||
return jsonSuccess(c, fmt.Sprintf("%s foi adicionado a sua lista", nome))
|
||||
}
|
||||
|
||||
func inv_phDel(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 uma habilidade")
|
||||
}
|
||||
itemID := c.Param("id")
|
||||
err = updateField(fmt.Sprintf("DELETE FROM invPower_%s WHERE id=?;", session["playerName"]), itemID)
|
||||
if err != nil {
|
||||
return jsonError(c, http.StatusInternalServerError, "erro ao deletar habilidade.")
|
||||
}
|
||||
|
||||
return jsonSuccess(c, "você deletou uma habilidade")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user