This commit is contained in:
parent
f579485745
commit
671169e621
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
@ -17,6 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
glog.Info(">>> BEGIN INIT<<<")
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt)
|
||||
defer cancel()
|
||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module gitea.timerzz.com/kedaya_haitao/seller
|
||||
go 1.22.5
|
||||
|
||||
require (
|
||||
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240901105924-1290c1e1fd6a
|
||||
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240913121100-f0a601466ba1
|
||||
github.com/gofiber/fiber/v3 v3.0.0-beta.3
|
||||
github.com/golang/glog v1.2.1
|
||||
github.com/henrylee2cn/ameda v1.4.10
|
||||
|
4
go.sum
4
go.sum
@ -1,5 +1,5 @@
|
||||
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240901105924-1290c1e1fd6a h1:BAsCJt5lj0L23qCzfy6dPhfDxoKrW64KxQtXTjuXfaA=
|
||||
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240901105924-1290c1e1fd6a/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE=
|
||||
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240913121100-f0a601466ba1 h1:5Bu3V2w4Jd7mgFIeH8GkVaEfvOXIFtPSoApwzsmp9rc=
|
||||
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240913121100-f0a601466ba1/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE=
|
||||
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
|
||||
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"gitea.timerzz.com/kedaya_haitao/common/pkg/web"
|
||||
"gitea.timerzz.com/kedaya_haitao/common/structs/storage"
|
||||
"gitea.timerzz.com/kedaya_haitao/common/structs/utils"
|
||||
v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/henrylee2cn/ameda"
|
||||
@ -21,10 +22,13 @@ func NewSeller(storage *storage.Storage) *Seller {
|
||||
func (s *Seller) Registry(r fiber.Router) {
|
||||
api := r.Group("/api/v2")
|
||||
api.Get("sellers", s.ListSellers)
|
||||
api.Get("/sellers/:id", s.GetSeller)
|
||||
api.Get("sellers/find", s.FindSellers)
|
||||
api.Get("sellers/:id", s.GetSeller)
|
||||
api.Post("sellers", s.CreateSeller)
|
||||
api.Put("sellers", s.UpdateSeller)
|
||||
api.Delete("/sellers/:id", s.DeleteSeller)
|
||||
api.Delete("sellers/:id", s.DeleteSeller)
|
||||
// 获取状态字典
|
||||
api.Get("sellers/dict/status", s.DictStatus)
|
||||
}
|
||||
|
||||
func (s *Seller) ListSellers(c fiber.Ctx) error {
|
||||
@ -96,3 +100,47 @@ func (s *Seller) DeleteSeller(c fiber.Ctx) error {
|
||||
}
|
||||
return c.JSON(web.NewResponse(seller))
|
||||
}
|
||||
|
||||
// 返回所有符合条件的销售商
|
||||
func (s *Seller) FindSellers(c fiber.Ctx) error {
|
||||
var query storage.ListSellerQuery
|
||||
if err := c.Bind().Query(&query); err != nil {
|
||||
return err
|
||||
}
|
||||
sellers, err := s.storage.Seller().Find(&query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.JSON(web.NewResponse(sellers))
|
||||
}
|
||||
|
||||
// 返回状态字典
|
||||
func (s *Seller) DictStatus(c fiber.Ctx) error {
|
||||
dicts := []utils.Dict{
|
||||
{
|
||||
Key: "seller_status_normal",
|
||||
Value: v2.SellerStatus_Normal,
|
||||
Title: "正常",
|
||||
Color: "#87d068",
|
||||
},
|
||||
{
|
||||
Key: "seller_status_pulling",
|
||||
Value: v2.SellerStatus_Pulling,
|
||||
Title: "抓取中",
|
||||
Color: "#108ee9",
|
||||
},
|
||||
{
|
||||
Key: "seller_status_calculate",
|
||||
Value: v2.SellerStatus_Calculating,
|
||||
Title: "计算中",
|
||||
Color: "#108ee9",
|
||||
},
|
||||
{
|
||||
Key: "seller_status_error",
|
||||
Value: v2.SellerStatus_Error,
|
||||
Title: "出错",
|
||||
Color: "red",
|
||||
},
|
||||
}
|
||||
return c.JSON(web.NewResponse(dicts))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user