notification.go 982 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package notification
  2. import (
  3. "net/http"
  4. "github.com/0xJacky/Nginx-UI/model"
  5. "github.com/0xJacky/Nginx-UI/query"
  6. "github.com/gin-gonic/gin"
  7. "github.com/spf13/cast"
  8. "github.com/uozi-tech/cosy"
  9. )
  10. func Get(c *gin.Context) {
  11. n := query.Notification
  12. id := cast.ToUint64(c.Param("id"))
  13. data, err := n.FirstByID(id)
  14. if err != nil {
  15. cosy.ErrHandler(c, err)
  16. return
  17. }
  18. c.JSON(http.StatusOK, data)
  19. }
  20. func GetList(c *gin.Context) {
  21. cosy.Core[model.Notification](c).PagingList()
  22. }
  23. func Destroy(c *gin.Context) {
  24. cosy.Core[model.Notification](c).Destroy()
  25. }
  26. func DestroyAll(c *gin.Context) {
  27. db := model.UseDB()
  28. // remove all records
  29. err := db.Exec("DELETE FROM notifications").Error
  30. if err != nil {
  31. cosy.ErrHandler(c, err)
  32. return
  33. }
  34. // reset auto increment
  35. err = db.Exec("UPDATE sqlite_sequence SET seq = 0 WHERE name = 'notifications';").Error
  36. if err != nil {
  37. cosy.ErrHandler(c, err)
  38. return
  39. }
  40. c.JSON(http.StatusOK, gin.H{
  41. "message": "ok",
  42. })
  43. }