feat 版本用latest
All checks were successful
Build image / build (push) Successful in 56s

This commit is contained in:
timerzz 2024-09-13 22:08:09 +08:00
parent f579485745
commit 671169e621
4 changed files with 55 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"flag"
"os" "os"
"os/signal" "os/signal"
@ -17,6 +18,7 @@ import (
) )
func main() { func main() {
flag.Parse()
glog.Info(">>> BEGIN INIT<<<") glog.Info(">>> BEGIN INIT<<<")
ctx, cancel := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt) ctx, cancel := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt)
defer cancel() defer cancel()

2
go.mod
View File

@ -3,7 +3,7 @@ module gitea.timerzz.com/kedaya_haitao/seller
go 1.22.5 go 1.22.5
require ( 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/gofiber/fiber/v3 v3.0.0-beta.3
github.com/golang/glog v1.2.1 github.com/golang/glog v1.2.1
github.com/henrylee2cn/ameda v1.4.10 github.com/henrylee2cn/ameda v1.4.10

4
go.sum
View File

@ -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-20240913121100-f0a601466ba1 h1:5Bu3V2w4Jd7mgFIeH8GkVaEfvOXIFtPSoApwzsmp9rc=
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/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= 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= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View File

@ -3,6 +3,7 @@ package service
import ( import (
"gitea.timerzz.com/kedaya_haitao/common/pkg/web" "gitea.timerzz.com/kedaya_haitao/common/pkg/web"
"gitea.timerzz.com/kedaya_haitao/common/structs/storage" "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" v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
"github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3"
"github.com/henrylee2cn/ameda" "github.com/henrylee2cn/ameda"
@ -21,10 +22,13 @@ func NewSeller(storage *storage.Storage) *Seller {
func (s *Seller) Registry(r fiber.Router) { func (s *Seller) Registry(r fiber.Router) {
api := r.Group("/api/v2") api := r.Group("/api/v2")
api.Get("sellers", s.ListSellers) 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.Post("sellers", s.CreateSeller)
api.Put("sellers", s.UpdateSeller) 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 { 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)) 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))
}