36 lines
757 B
Go
36 lines
757 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 Provider struct {
|
||
|
storage *storage.Storage
|
||
|
}
|
||
|
|
||
|
func NewProvider(storage *storage.Storage) *Provider {
|
||
|
return &Provider{
|
||
|
storage: storage,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (s *Provider) Registry(r fiber.Router) {
|
||
|
r.Get("providers", s.ListProviders)
|
||
|
}
|
||
|
|
||
|
func (s *Provider) ListProviders(c fiber.Ctx) error {
|
||
|
query := storage.NewPageListQuery(&storage.ListProviderQuery{})
|
||
|
if err := c.Bind().Query(&query); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
providers, total, err := s.storage.Provider().List(*query)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return c.JSON(web.NewResponse(web.NewListResponse(total, providers)))
|
||
|
}
|