notification.go 1005 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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).
  22. SetEqual("type").
  23. PagingList()
  24. }
  25. func Destroy(c *gin.Context) {
  26. cosy.Core[model.Notification](c).Destroy()
  27. }
  28. func DestroyAll(c *gin.Context) {
  29. db := model.UseDB()
  30. // remove all records
  31. err := db.Exec("DELETE FROM notifications").Error
  32. if err != nil {
  33. cosy.ErrHandler(c, err)
  34. return
  35. }
  36. // reset auto increment
  37. err = db.Exec("UPDATE sqlite_sequence SET seq = 0 WHERE name = 'notifications';").Error
  38. if err != nil {
  39. cosy.ErrHandler(c, err)
  40. return
  41. }
  42. c.JSON(http.StatusOK, gin.H{
  43. "message": "ok",
  44. })
  45. }