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