40 lines
862 B
Go
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)))
|
|
}
|