notification.go 1.0 KB

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