Compare commits

..

No commits in common. 'fa45b1d79967cf146250143851fbb834dbfb49ff' and '645326b148bc98803b28c36ef7478b0c666cf025' have entirely different histories.

  1. 15
      app/rts.go

@ -423,8 +423,8 @@ func UpdateGoods(w *ResponseWriter, r *Request) {
} }
} }
// ListGoods 查询商品列表 // GetGoodsList 查询商品列表
func ListGoods(w *ResponseWriter, r *Request) { func GetGoodsList(w *ResponseWriter, r *Request) {
search := func(db *gorm.DB) *gorm.DB { search := func(db *gorm.DB) *gorm.DB {
return db. return db.
Model(&Goods{}). Model(&Goods{}).
@ -436,7 +436,7 @@ func ListGoods(w *ResponseWriter, r *Request) {
var total int64 var total int64
var err error var err error
if err = DB.Scopes(search).Count(&total).Error; err == nil { if err = DB.Scopes(search).Count(&total).Error; err == nil {
err = DB.Scopes(search).Preload("Creator").Preload("Updater").Find(&goodsList).Error err = DB.Scopes(search).Find(&goodsList).Error
} }
if err != nil { if err != nil {
w.Error(err) w.Error(err)
@ -448,8 +448,7 @@ func ListGoods(w *ResponseWriter, r *Request) {
} }
} }
// 查询价格列表 func GetGoodsPrices(w *ResponseWriter, r *Request) {
func ListPrices(w *ResponseWriter, r *Request) {
id := uint(r.Uint64("id", 0)) id := uint(r.Uint64("id", 0))
var goods Goods var goods Goods
if err := DB.Scopes(func(db *gorm.DB) *gorm.DB { if err := DB.Scopes(func(db *gorm.DB) *gorm.DB {
@ -464,7 +463,7 @@ func ListPrices(w *ResponseWriter, r *Request) {
args = append(args, val) args = append(args, val)
} }
if len(queries) == 0 { if len(queries) == 0 {
return db.Preload("Prices.Creator") return db.Preload("Prices")
} }
args = append([]any{strings.Join(queries, " AND ")}, args...) args = append([]any{strings.Join(queries, " AND ")}, args...)
return db.Preload("Prices", args...) return db.Preload("Prices", args...)
@ -517,8 +516,8 @@ func RegisterRoutes(r chi.Router) {
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {
r.Post("/goods", Handler(CreateGoods)) r.Post("/goods", Handler(CreateGoods))
r.Patch("/goods/:id", Handler(UpdateGoods)) r.Patch("/goods/:id", Handler(UpdateGoods))
r.Get("/goods", Handler(ListGoods)) r.Get("/goods", Handler(GetGoodsList))
r.Get("/goods/:id/prices", Handler(ListPrices)) r.Get("/goods/:id/prices", Handler(GetGoodsPrices))
}) })
}) })
} }

Loading…
Cancel
Save