module_index_act_delete.go 828 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package modules
  2. import (
  3. "context"
  4. "golang-fave/engine/utils"
  5. "golang-fave/engine/wrapper"
  6. )
  7. func (this *Modules) RegisterAction_IndexDelete() *Action {
  8. return this.newAction(AInfo{
  9. Mount: "index-delete",
  10. WantAdmin: true,
  11. }, func(wrap *wrapper.Wrapper) {
  12. pf_id := utils.Trim(wrap.R.FormValue("id"))
  13. if !utils.IsNumeric(pf_id) {
  14. wrap.MsgError(`Inner system error`)
  15. return
  16. }
  17. err := wrap.DB.Transaction(wrap.R.Context(), func(ctx context.Context, tx *wrapper.Tx) error {
  18. // Process
  19. if _, err := tx.Exec(ctx, "DELETE FROM fave_pages WHERE id = ?;", utils.StrToInt(pf_id)); err != nil {
  20. return err
  21. }
  22. return nil
  23. })
  24. if err != nil {
  25. wrap.MsgError(err.Error())
  26. return
  27. }
  28. wrap.ResetCacheBlocks()
  29. // Reload current page
  30. wrap.Write(`window.location.reload(false);`)
  31. })
  32. }