1
0

notification.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package notification
  2. import (
  3. "github.com/0xJacky/Nginx-UI/api"
  4. "github.com/0xJacky/Nginx-UI/internal/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).Destroy()
  26. }
  27. func DestroyAll(c *gin.Context) {
  28. db := model.UseDB()
  29. // remove all records
  30. err := db.Exec("DELETE FROM notifications").Error
  31. if err != nil {
  32. api.ErrHandler(c, err)
  33. return
  34. }
  35. // reset auto increment
  36. err = db.Exec("UPDATE sqlite_sequence SET seq = 0 WHERE name = 'notifications';").Error
  37. if err != nil {
  38. api.ErrHandler(c, err)
  39. return
  40. }
  41. c.JSON(http.StatusOK, gin.H{
  42. "message": "ok",
  43. })
  44. }