watcher/service/watcher_svc.go
timerzz 2206fa9a95
Some checks failed
Build image / build (push) Failing after 2m25s
feat 重构watcher
2024-11-30 20:26:39 +08:00

40 lines
862 B
Go

package service
import (
"gitea.timerzz.com/kedaya_haitao/common/pkg/web"
"gitea.timerzz.com/kedaya_haitao/common/structs/storage"
"github.com/gofiber/fiber/v3"
)
type Watcher struct {
storage *storage.Storage
}
func NewWatcher(storage *storage.Storage) *Watcher {
return &Watcher{
storage: storage,
}
}
func (s *Watcher) Registry(r fiber.Router) {
api := r.Group("/api/v2")
api.Get("watchers", s.List)
}
func (s *Watcher) List(c fiber.Ctx) error {
var q storage.GetProviderArticleQuery
if err := c.Bind().Query(&q); err != nil {
return err
}
q.WatchNotNull = true
var query = storage.NewPageListQuery(&q)
if err := c.Bind().Query(query); err != nil {
return err
}
articles, total, err := s.storage.ProviderArticle().List(*query)
if err != nil {
return err
}
return c.JSON(web.NewResponse(web.NewListResponse(total, articles)))
}