feat v2版本
Some checks failed
Build image / build (push) Failing after 1m42s

This commit is contained in:
timerzz 2024-09-13 20:36:54 +08:00
parent 83dec0ee7a
commit ad6991d87a
5 changed files with 155 additions and 14 deletions

View File

@ -14,11 +14,11 @@ jobs:
with:
version: v0.15.4
env:
KO_DOCKER_REPO: 192.168.31.55:5000/kedaya/${REPO_NAME}
KO_DOCKER_REPO: 192.168.31.55:5000/kedaya/${REPO_NAME}:v2
HTTP_PROXY: http://192.168.31.55:10809
HTTPS_PROXY: http://192.168.31.55:10809
- run: ko build --bare ./cmd
env:
KO_DOCKER_REPO: 192.168.31.55:5000/kedaya/${REPO_NAME}
KO_DOCKER_REPO: 192.168.31.55:5000/kedaya/${REPO_NAME}:v2
HTTP_PROXY: http://192.168.31.55:10809
HTTPS_PROXY: http://192.168.31.55:10809

View File

@ -2,9 +2,11 @@ package main
import (
"context"
"flag"
"os"
"os/signal"
"gitea.timerzz.com/kedaya_haitao/article/service"
"gitea.timerzz.com/kedaya_haitao/common/pkg/database"
"gitea.timerzz.com/kedaya_haitao/common/pkg/web"
"gitea.timerzz.com/kedaya_haitao/common/structs/storage"
@ -16,6 +18,7 @@ import (
)
func main() {
flag.Parse()
glog.Info(">>> BEGIN INIT<<<")
ctx, cancel := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt)
defer cancel()
@ -32,6 +35,7 @@ func main() {
svc := []web.Register{
web.NewProbe(),
service.NewArticle(stg),
}
for _, s := range svc {

32
go.mod
View File

@ -2,3 +2,35 @@ module gitea.timerzz.com/kedaya_haitao/article
go 1.22.5
require (
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.2
)
require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/expr-lang/expr v1.16.9 // indirect
github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/samber/lo v1.39.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.7 // indirect
gorm.io/gorm v1.25.10 // indirect
)

12
go.sum
View File

@ -1,5 +1,5 @@
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240904073547-7677cd470a33 h1:faziFCeUdnDOsAse6iI6ZKXY68BBTgeQfoRS5ef8ag0=
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240904073547-7677cd470a33/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=
@ -11,14 +11,12 @@ github.com/gofiber/fiber/v3 v3.0.0-beta.3 h1:7Q2I+HsIqnIEEDB+9oe7Gadpakh6ZLhXpTY
github.com/gofiber/fiber/v3 v3.0.0-beta.3/go.mod h1:kcMur0Dxqk91R7p4vxEpJfDWZ9u5IfvrtQc8Bvv/JmY=
github.com/gofiber/utils/v2 v2.0.0-beta.4 h1:1gjbVFFwVwUb9arPcqiB6iEjHBwo7cHsyS41NeIW3co=
github.com/gofiber/utils/v2 v2.0.0-beta.4/go.mod h1:sdRsPU1FXX6YiDGGxd+q2aPJRMzpsxdzCXo9dz+xtOY=
github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4=
github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/glog v1.2.2 h1:1+mZ9upx1Dh6FmUTFR1naJ77miKiXgALjWOZ3NVFPmY=
github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/henrylee2cn/ameda v1.4.10 h1:JdvI2Ekq7tapdPsuhrc4CaFiqw6QXFvZIULWJgQyCAk=
github.com/henrylee2cn/ameda v1.4.10/go.mod h1:liZulR8DgHxdK+MEwvZIylGnmcjzQ6N6f2PlWe7nEO4=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
@ -50,7 +48,6 @@ github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
@ -73,7 +70,6 @@ golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -1,12 +1,14 @@
package service
import (
"fmt"
"strconv"
"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"
)
type Article struct {
@ -21,10 +23,117 @@ func NewArticle(storage *storage.Storage) *Article {
func (s *Article) Registry(r fiber.Router) {
api := r.Group("/api/v2")
api.Get("articles", s.List)
api.Get("articles/:id", s.Get)
api.Get("articles/dict/brand", s.BrandDict)
api.Patch("articles", s.Update)
api.Get("articles/provider/history/:id", s.ProviderHistory)
api.Get("articles/seller/history/:id", s.SellerHistory)
api.Patch("articles/provider", s.UpdateProviderArticle)
api.Patch("articles/seller", s.UpdateSellerArticle)
}
func (s *Article) List(c fiber.Ctx) error {
return c.JSON(web.NewResponse(web.NewListResponse(total, sellers)))
var q storage.FindArticleQuery
if err := c.Bind().Query(&q); err != nil {
return err
}
var query = storage.NewPageListQuery(&q)
if err := c.Bind().Query(query); err != nil {
return err
}
articles, total, err := s.storage.Article().List(*query, q.SortScope)
if err != nil {
return err
}
return c.JSON(web.NewResponse(web.NewListResponse(total, articles)))
}
func (s *Article) Get(c fiber.Ctx) error {
id := c.Params("id")
if id == "" {
return fiber.NewError(fiber.StatusBadRequest, "id is required")
}
i, _ := strconv.Atoi(id)
query := storage.NewGetArticleQuery().SetID(uint(i))
article, err := s.storage.Article().Get(query)
if err != nil {
return err
}
return c.JSON(web.NewResponse(article))
}
func (s *Article) Update(c fiber.Ctx) error {
var article v2.Article
if err := c.Bind().JSON(&article); err != nil {
return err
}
if article.ID == 0 {
return fiber.NewError(fiber.StatusBadRequest, "id is required")
}
if err := s.storage.Article().Update(article); err != nil {
return err
}
return c.JSON(web.NewResponse(article))
}
func (s *Article) BrandDict(c fiber.Ctx) error {
var dict = []utils.Dict{
{
Key: string(v2.Brand_Coach),
Title: fmt.Sprintf("蔻驰/%s", v2.Brand_Coach),
Value: v2.Brand_Coach,
},
}
return c.JSON(web.NewResponse(dict))
}
// 获取供应商历史价格
func (s *Article) ProviderHistory(c fiber.Ctx) error {
i := c.Params("id")
id, _ := strconv.Atoi(i)
if id == 0 {
return fiber.NewError(fiber.StatusBadRequest, "id is required")
}
prices, err := s.storage.ProviderArticle().ProviderPrice(uint(id))
if err != nil {
return err
}
return c.JSON(web.NewResponse(prices))
}
// 获取销售商历史价格
func (s *Article) SellerHistory(c fiber.Ctx) error {
i := c.Params("id")
id, _ := strconv.Atoi(i)
if id == 0 {
return fiber.NewError(fiber.StatusBadRequest, "id is required")
}
prices, err := s.storage.SellerArticle().SellerPrice(uint(id))
if err != nil {
return err
}
return c.JSON(web.NewResponse(prices))
}
func (s *Article) UpdateProviderArticle(c fiber.Ctx) error {
var article v2.ProviderArticle
if err := c.Bind().JSON(&article); err != nil {
return err
}
if err := s.storage.ProviderArticle().Update(article); err != nil {
return err
}
return c.JSON(web.NewResponse(article))
}
func (s *Article) UpdateSellerArticle(c fiber.Ctx) error {
var article v2.SellerArticle
if err := c.Bind().JSON(&article); err != nil {
return err
}
if err := s.storage.SellerArticle().Update(article); err != nil {
return err
}
return c.JSON(web.NewResponse(article))
}