fix: 批量改进 (#2/#23/#38/#39/#40/#47)
- Web: 隐藏 ICP 备案号(条件渲染),联系入口改为微信咨询(条件渲染,配置 wechat 字段后生效) - backend: 拼音回填抽取为独立 cmd/backfill-pinyin 工具,不再在启动时运行 - backend: DB 连接池参数(max_idle_conns/max_open_conns)改为配置可控,默认 10/100 - backend: Inventory 反范式字段添加注释说明快照语义 - backend: 全量 handler 采用 util.RespondSuccess/RespondCreated 统一响应格式(51 处) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/wangjia/jiu/backend/internal/service"
|
||||
"github.com/wangjia/jiu/backend/internal/util"
|
||||
)
|
||||
|
||||
type AuthHandler struct {
|
||||
@@ -63,7 +64,7 @@ func (h *AuthHandler) Register(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"data": result})
|
||||
util.RespondSuccess(c, result)
|
||||
}
|
||||
|
||||
// Refresh POST /api/v1/auth/refresh
|
||||
@@ -82,5 +83,5 @@ func (h *AuthHandler) Refresh(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"data": pair})
|
||||
util.RespondSuccess(c, pair)
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ func (h *FinanceHandler) Summary(c *gin.Context) {
|
||||
ORDER BY total_amount DESC
|
||||
`, shopID).Scan(&rows)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"data": rows})
|
||||
util.RespondSuccess(c, rows)
|
||||
}
|
||||
|
||||
// partnerLastBalance 查询该往来单位最后一条财务记录的余额
|
||||
|
||||
@@ -178,7 +178,7 @@ func (h *InventoryHandler) CreateCheck(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": req})
|
||||
util.RespondCreated(c, req)
|
||||
}
|
||||
|
||||
// GetCheck GET /api/v1/inventory/checks/:id
|
||||
@@ -191,7 +191,7 @@ func (h *InventoryHandler) GetCheck(c *gin.Context) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": check})
|
||||
util.RespondSuccess(c, check)
|
||||
}
|
||||
|
||||
// CompleteCheck PUT /api/v1/inventory/checks/:id/complete
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/wangjia/jiu/backend/internal/middleware"
|
||||
"github.com/wangjia/jiu/backend/internal/service"
|
||||
"github.com/wangjia/jiu/backend/internal/util"
|
||||
)
|
||||
|
||||
type LicenseHandler struct {
|
||||
@@ -35,7 +36,7 @@ func (h *LicenseHandler) Activate(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": lic})
|
||||
util.RespondSuccess(c, lic)
|
||||
}
|
||||
|
||||
// Verify GET /api/v1/license/verify
|
||||
@@ -52,7 +53,7 @@ func (h *LicenseHandler) Verify(c *gin.Context) {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": lic})
|
||||
util.RespondSuccess(c, lic)
|
||||
}
|
||||
|
||||
// Info GET /api/v1/license/info — 当前门店授权概况
|
||||
@@ -60,7 +61,7 @@ func (h *LicenseHandler) Info(c *gin.Context) {
|
||||
shopID := middleware.GetShopID(c)
|
||||
lic, err := h.svc.ShopInfo(shopID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"data": nil})
|
||||
util.RespondSuccess(c, nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ func (h *LicenseHandler) Devices(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": devs})
|
||||
util.RespondSuccess(c, devs)
|
||||
}
|
||||
|
||||
// Deactivate POST /api/v1/license/deactivate
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/wangjia/jiu/backend/internal/middleware"
|
||||
"github.com/wangjia/jiu/backend/internal/model"
|
||||
"github.com/wangjia/jiu/backend/internal/util"
|
||||
)
|
||||
|
||||
type NumberRuleHandler struct {
|
||||
@@ -43,7 +44,7 @@ func (h *NumberRuleHandler) List(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"data": rules})
|
||||
util.RespondSuccess(c, rules)
|
||||
}
|
||||
|
||||
// Update PUT /api/v1/number-rules/:id
|
||||
@@ -82,5 +83,5 @@ func (h *NumberRuleHandler) Update(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": rule})
|
||||
util.RespondSuccess(c, rule)
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (h *PartnerHandler) Create(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": p})
|
||||
util.RespondCreated(c, p)
|
||||
}
|
||||
|
||||
func (h *PartnerHandler) Update(c *gin.Context) {
|
||||
@@ -113,7 +113,7 @@ func (h *PartnerHandler) Update(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
h.db.Where("id = ? AND shop_id = ?", p.ID, shopID).First(&p)
|
||||
c.JSON(http.StatusOK, gin.H{"data": p})
|
||||
util.RespondSuccess(c, p)
|
||||
}
|
||||
|
||||
func (h *PartnerHandler) Delete(c *gin.Context) {
|
||||
|
||||
@@ -104,7 +104,7 @@ func (h *ProductHandler) Create(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": createErr.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": product})
|
||||
util.RespondCreated(c, product)
|
||||
}
|
||||
|
||||
// Update PUT /api/v1/products/:id
|
||||
@@ -155,7 +155,7 @@ func (h *ProductHandler) Update(c *gin.Context) {
|
||||
|
||||
// 重新读取完整数据返回
|
||||
h.db.Preload("Category").First(&product, product.ID)
|
||||
c.JSON(http.StatusOK, gin.H{"data": product})
|
||||
util.RespondSuccess(c, product)
|
||||
}
|
||||
|
||||
// Detail GET /api/v1/products/:id/detail
|
||||
@@ -178,7 +178,7 @@ func (h *ProductHandler) Detail(c *gin.Context) {
|
||||
h.db.Model(&product).Update("public_id", product.PublicID)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"data": product})
|
||||
util.RespondSuccess(c, product)
|
||||
}
|
||||
|
||||
// QRCode GET /api/v1/products/:id/qrcode
|
||||
@@ -248,7 +248,7 @@ func (h *ProductHandler) FindOrCreate(c *gin.Context) {
|
||||
if len(attrUpdates) > 0 {
|
||||
h.db.Model(&product).Updates(attrUpdates)
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": product})
|
||||
util.RespondSuccess(c, product)
|
||||
return
|
||||
}
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
@@ -277,13 +277,13 @@ func (h *ProductHandler) FindOrCreate(c *gin.Context) {
|
||||
// Race condition: try to find the record created by another request
|
||||
if h.db.Where("shop_id = ? AND name = ? AND series = ? AND spec = ? AND deleted_at IS NULL",
|
||||
shopID, req.Name, req.Series, req.Spec).First(&product).Error == nil {
|
||||
c.JSON(http.StatusOK, gin.H{"data": product})
|
||||
util.RespondSuccess(c, product)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": createErr.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": product})
|
||||
util.RespondCreated(c, product)
|
||||
}
|
||||
|
||||
// Delete DELETE /api/v1/products/:id (软删除)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/wangjia/jiu/backend/internal/middleware"
|
||||
"github.com/wangjia/jiu/backend/internal/model"
|
||||
"github.com/wangjia/jiu/backend/internal/util"
|
||||
)
|
||||
|
||||
// ProductAttrHandler 处理商品属性字典(产地/保质期/储存方式/描述文档)
|
||||
@@ -25,7 +26,7 @@ func (h *ProductAttrHandler) ListOrigins(c *gin.Context) {
|
||||
shopID := middleware.GetShopID(c)
|
||||
items := make([]model.ProductOriginOption, 0)
|
||||
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
|
||||
c.JSON(http.StatusOK, gin.H{"data": items})
|
||||
util.RespondSuccess(c, items)
|
||||
}
|
||||
|
||||
func (h *ProductAttrHandler) CreateOrigin(c *gin.Context) {
|
||||
@@ -49,7 +50,7 @@ func (h *ProductAttrHandler) CreateOrigin(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": item})
|
||||
util.RespondCreated(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductAttrHandler) UpdateOrigin(c *gin.Context) {
|
||||
@@ -71,7 +72,7 @@ func (h *ProductAttrHandler) UpdateOrigin(c *gin.Context) {
|
||||
h.db.Model(&item).Where("shop_id = ?", shopID).Updates(map[string]interface{}{
|
||||
"code": req.Code, "name": req.Name, "remark": req.Remark,
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{"data": item})
|
||||
util.RespondSuccess(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductAttrHandler) DeleteOrigin(c *gin.Context) {
|
||||
@@ -86,7 +87,7 @@ func (h *ProductAttrHandler) ListShelfLives(c *gin.Context) {
|
||||
shopID := middleware.GetShopID(c)
|
||||
items := make([]model.ProductShelfLifeOption, 0)
|
||||
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
|
||||
c.JSON(http.StatusOK, gin.H{"data": items})
|
||||
util.RespondSuccess(c, items)
|
||||
}
|
||||
|
||||
func (h *ProductAttrHandler) CreateShelfLife(c *gin.Context) {
|
||||
@@ -110,7 +111,7 @@ func (h *ProductAttrHandler) CreateShelfLife(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": item})
|
||||
util.RespondCreated(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductAttrHandler) UpdateShelfLife(c *gin.Context) {
|
||||
@@ -132,7 +133,7 @@ func (h *ProductAttrHandler) UpdateShelfLife(c *gin.Context) {
|
||||
h.db.Model(&item).Where("shop_id = ?", shopID).Updates(map[string]interface{}{
|
||||
"code": req.Code, "name": req.Name, "remark": req.Remark,
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{"data": item})
|
||||
util.RespondSuccess(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductAttrHandler) DeleteShelfLife(c *gin.Context) {
|
||||
@@ -147,7 +148,7 @@ func (h *ProductAttrHandler) ListStorages(c *gin.Context) {
|
||||
shopID := middleware.GetShopID(c)
|
||||
items := make([]model.ProductStorageOption, 0)
|
||||
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
|
||||
c.JSON(http.StatusOK, gin.H{"data": items})
|
||||
util.RespondSuccess(c, items)
|
||||
}
|
||||
|
||||
func (h *ProductAttrHandler) CreateStorage(c *gin.Context) {
|
||||
@@ -171,7 +172,7 @@ func (h *ProductAttrHandler) CreateStorage(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": item})
|
||||
util.RespondCreated(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductAttrHandler) UpdateStorage(c *gin.Context) {
|
||||
@@ -193,7 +194,7 @@ func (h *ProductAttrHandler) UpdateStorage(c *gin.Context) {
|
||||
h.db.Model(&item).Where("shop_id = ?", shopID).Updates(map[string]interface{}{
|
||||
"code": req.Code, "name": req.Name, "remark": req.Remark,
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{"data": item})
|
||||
util.RespondSuccess(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductAttrHandler) DeleteStorage(c *gin.Context) {
|
||||
@@ -208,7 +209,7 @@ func (h *ProductAttrHandler) ListDescriptionDocs(c *gin.Context) {
|
||||
shopID := middleware.GetShopID(c)
|
||||
items := make([]model.ProductDescriptionDoc, 0)
|
||||
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
|
||||
c.JSON(http.StatusOK, gin.H{"data": items})
|
||||
util.RespondSuccess(c, items)
|
||||
}
|
||||
|
||||
func (h *ProductAttrHandler) CreateDescriptionDoc(c *gin.Context) {
|
||||
@@ -232,7 +233,7 @@ func (h *ProductAttrHandler) CreateDescriptionDoc(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": item})
|
||||
util.RespondCreated(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductAttrHandler) UpdateDescriptionDoc(c *gin.Context) {
|
||||
@@ -254,7 +255,7 @@ func (h *ProductAttrHandler) UpdateDescriptionDoc(c *gin.Context) {
|
||||
h.db.Model(&item).Where("shop_id = ?", shopID).Updates(map[string]interface{}{
|
||||
"title": req.Title, "content": req.Content, "remark": req.Remark,
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{"data": item})
|
||||
util.RespondSuccess(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductAttrHandler) DeleteDescriptionDoc(c *gin.Context) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/wangjia/jiu/backend/config"
|
||||
"github.com/wangjia/jiu/backend/internal/middleware"
|
||||
"github.com/wangjia/jiu/backend/internal/model"
|
||||
"github.com/wangjia/jiu/backend/internal/util"
|
||||
)
|
||||
|
||||
type ProductImageHandler struct {
|
||||
@@ -105,7 +106,7 @@ func (h *ProductImageHandler) Upload(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, gin.H{"data": pi})
|
||||
util.RespondCreated(c, pi)
|
||||
}
|
||||
|
||||
// Delete DELETE /api/v1/products/:id/images/:image_id
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/wangjia/jiu/backend/internal/middleware"
|
||||
"github.com/wangjia/jiu/backend/internal/model"
|
||||
"github.com/wangjia/jiu/backend/internal/util"
|
||||
)
|
||||
|
||||
type ProductOptionHandler struct {
|
||||
@@ -24,7 +25,7 @@ func (h *ProductOptionHandler) ListNames(c *gin.Context) {
|
||||
shopID := middleware.GetShopID(c)
|
||||
items := make([]model.ProductNameOption, 0)
|
||||
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
|
||||
c.JSON(http.StatusOK, gin.H{"data": items})
|
||||
util.RespondSuccess(c, items)
|
||||
}
|
||||
|
||||
func (h *ProductOptionHandler) CreateName(c *gin.Context) {
|
||||
@@ -48,7 +49,7 @@ func (h *ProductOptionHandler) CreateName(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": item})
|
||||
util.RespondCreated(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductOptionHandler) UpdateName(c *gin.Context) {
|
||||
@@ -70,7 +71,7 @@ func (h *ProductOptionHandler) UpdateName(c *gin.Context) {
|
||||
h.db.Model(&item).Where("shop_id = ?", shopID).Updates(map[string]interface{}{
|
||||
"code": req.Code, "name": req.Name, "remark": req.Remark,
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{"data": item})
|
||||
util.RespondSuccess(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductOptionHandler) DeleteName(c *gin.Context) {
|
||||
@@ -85,7 +86,7 @@ func (h *ProductOptionHandler) ListSeries(c *gin.Context) {
|
||||
shopID := middleware.GetShopID(c)
|
||||
items := make([]model.ProductSeriesOption, 0)
|
||||
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
|
||||
c.JSON(http.StatusOK, gin.H{"data": items})
|
||||
util.RespondSuccess(c, items)
|
||||
}
|
||||
|
||||
func (h *ProductOptionHandler) CreateSeries(c *gin.Context) {
|
||||
@@ -109,7 +110,7 @@ func (h *ProductOptionHandler) CreateSeries(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": item})
|
||||
util.RespondCreated(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductOptionHandler) UpdateSeries(c *gin.Context) {
|
||||
@@ -131,7 +132,7 @@ func (h *ProductOptionHandler) UpdateSeries(c *gin.Context) {
|
||||
h.db.Model(&item).Where("shop_id = ?", shopID).Updates(map[string]interface{}{
|
||||
"code": req.Code, "name": req.Name, "remark": req.Remark,
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{"data": item})
|
||||
util.RespondSuccess(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductOptionHandler) DeleteSeries(c *gin.Context) {
|
||||
@@ -146,7 +147,7 @@ func (h *ProductOptionHandler) ListSpecs(c *gin.Context) {
|
||||
shopID := middleware.GetShopID(c)
|
||||
items := make([]model.ProductSpecOption, 0)
|
||||
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
|
||||
c.JSON(http.StatusOK, gin.H{"data": items})
|
||||
util.RespondSuccess(c, items)
|
||||
}
|
||||
|
||||
func (h *ProductOptionHandler) CreateSpec(c *gin.Context) {
|
||||
@@ -172,7 +173,7 @@ func (h *ProductOptionHandler) CreateSpec(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": item})
|
||||
util.RespondCreated(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductOptionHandler) UpdateSpec(c *gin.Context) {
|
||||
@@ -195,7 +196,7 @@ func (h *ProductOptionHandler) UpdateSpec(c *gin.Context) {
|
||||
h.db.Model(&item).Where("shop_id = ?", shopID).Updates(map[string]interface{}{
|
||||
"code": req.Code, "name": req.Name, "quantity": req.Quantity, "remark": req.Remark,
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{"data": item})
|
||||
util.RespondSuccess(c, item)
|
||||
}
|
||||
|
||||
func (h *ProductOptionHandler) DeleteSpec(c *gin.Context) {
|
||||
|
||||
@@ -72,7 +72,7 @@ func (h *StockInHandler) Get(c *gin.Context) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": order})
|
||||
util.RespondSuccess(c, order)
|
||||
}
|
||||
|
||||
// Create POST /api/v1/stock-in/orders
|
||||
@@ -114,7 +114,7 @@ func (h *StockInHandler) Create(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": req})
|
||||
util.RespondCreated(c, req)
|
||||
}
|
||||
|
||||
// Update PUT /api/v1/stock-in/orders/:id (只允许草稿状态)
|
||||
|
||||
@@ -63,7 +63,7 @@ func (h *StockOutHandler) Get(c *gin.Context) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": order})
|
||||
util.RespondSuccess(c, order)
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ func (h *StockOutHandler) Create(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": req})
|
||||
util.RespondCreated(c, req)
|
||||
}
|
||||
|
||||
// Update PUT /api/v1/stock-out/orders/:id (只允许草稿状态)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/wangjia/jiu/backend/internal/middleware"
|
||||
"github.com/wangjia/jiu/backend/internal/model"
|
||||
"github.com/wangjia/jiu/backend/internal/util"
|
||||
)
|
||||
|
||||
type UserHandler struct {
|
||||
@@ -25,7 +26,7 @@ func (h *UserHandler) List(c *gin.Context) {
|
||||
users := make([]model.User, 0)
|
||||
h.db.Where("shop_id = ? AND deleted_at IS NULL", shopID).
|
||||
Order("id ASC").Find(&users)
|
||||
c.JSON(http.StatusOK, gin.H{"data": users})
|
||||
util.RespondSuccess(c, users)
|
||||
}
|
||||
|
||||
// Create POST /api/v1/users
|
||||
@@ -64,7 +65,7 @@ func (h *UserHandler) Create(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "用户名已存在"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, gin.H{"data": u})
|
||||
util.RespondCreated(c, u)
|
||||
}
|
||||
|
||||
// Update PUT /api/v1/users/:id
|
||||
@@ -100,7 +101,7 @@ func (h *UserHandler) Update(c *gin.Context) {
|
||||
h.db.Model(&u).Where("shop_id = ?", shopID).Updates(updates)
|
||||
}
|
||||
h.db.Where("id = ? AND shop_id = ?", u.ID, shopID).First(&u)
|
||||
c.JSON(http.StatusOK, gin.H{"data": u})
|
||||
util.RespondSuccess(c, u)
|
||||
}
|
||||
|
||||
// ResetPassword PUT /api/v1/users/:id/reset-password
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/wangjia/jiu/backend/internal/middleware"
|
||||
"github.com/wangjia/jiu/backend/internal/model"
|
||||
"github.com/wangjia/jiu/backend/internal/util"
|
||||
)
|
||||
|
||||
type WarehouseHandler struct {
|
||||
@@ -22,7 +23,7 @@ func (h *WarehouseHandler) List(c *gin.Context) {
|
||||
shopID := middleware.GetShopID(c)
|
||||
warehouses := make([]model.Warehouse, 0)
|
||||
h.db.Where("shop_id = ? AND deleted_at IS NULL", shopID).Find(&warehouses)
|
||||
c.JSON(http.StatusOK, gin.H{"data": warehouses})
|
||||
util.RespondSuccess(c, warehouses)
|
||||
}
|
||||
|
||||
func (h *WarehouseHandler) Create(c *gin.Context) {
|
||||
@@ -34,7 +35,7 @@ func (h *WarehouseHandler) Create(c *gin.Context) {
|
||||
}
|
||||
w.ShopID = shopID
|
||||
h.db.Create(&w)
|
||||
c.JSON(http.StatusCreated, gin.H{"data": w})
|
||||
util.RespondCreated(c, w)
|
||||
}
|
||||
|
||||
func (h *WarehouseHandler) Update(c *gin.Context) {
|
||||
@@ -63,7 +64,7 @@ func (h *WarehouseHandler) Update(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
h.db.Where("id = ? AND shop_id = ?", w.ID, shopID).First(&w)
|
||||
c.JSON(http.StatusOK, gin.H{"data": w})
|
||||
util.RespondSuccess(c, w)
|
||||
}
|
||||
|
||||
func (h *WarehouseHandler) Delete(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user