module_index_act_delete.go 847 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. WantDB: true,
  10. Mount: "index-delete",
  11. WantAdmin: true,
  12. }, func(wrap *wrapper.Wrapper) {
  13. pf_id := utils.Trim(wrap.R.FormValue("id"))
  14. if !utils.IsNumeric(pf_id) {
  15. wrap.MsgError(`Inner system error`)
  16. return
  17. }
  18. err := wrap.DB.Transaction(wrap.R.Context(), func(ctx context.Context, tx *wrapper.Tx) error {
  19. // Process
  20. if _, err := tx.Exec(ctx, "DELETE FROM fave_pages WHERE id = ?;", utils.StrToInt(pf_id)); err != nil {
  21. return err
  22. }
  23. return nil
  24. })
  25. if err != nil {
  26. wrap.MsgError(err.Error())
  27. return
  28. }
  29. wrap.ResetCacheBlocks()
  30. // Reload current page
  31. wrap.Write(`window.location.reload(false);`)
  32. })
  33. }