fix(backend): JWT config mapstructure tag 修复 + 模型从 hotel 重构为 shop
- 修复 JWTConfig 缺少 mapstructure tag 导致 access_expire_min 解析为 0, token 签发即过期,所有 API 请求返回 401 - 全部 config struct 补齐 mapstructure tag(secret/dsn/hmac_secret 等) - 模型层从 hotel/HotelID 统一重命名为 shop/ShopID - 删除旧 migrations(001-004),新增 001_init 综合迁移文件 - 更新 schema.sql、testutil、handler/service/model 相关引用 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -19,43 +19,43 @@ func NewWarehouseHandler(db *gorm.DB) *WarehouseHandler {
|
||||
}
|
||||
|
||||
func (h *WarehouseHandler) List(c *gin.Context) {
|
||||
hotelID := middleware.GetHotelID(c)
|
||||
shopID := middleware.GetShopID(c)
|
||||
var warehouses []model.Warehouse
|
||||
h.db.Where("hotel_id = ? AND deleted_at IS NULL", hotelID).Find(&warehouses)
|
||||
h.db.Where("shop_id = ? AND deleted_at IS NULL", shopID).Find(&warehouses)
|
||||
c.JSON(http.StatusOK, gin.H{"data": warehouses})
|
||||
}
|
||||
|
||||
func (h *WarehouseHandler) Create(c *gin.Context) {
|
||||
hotelID := middleware.GetHotelID(c)
|
||||
shopID := middleware.GetShopID(c)
|
||||
var w model.Warehouse
|
||||
if err := c.ShouldBindJSON(&w); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
w.HotelID = hotelID
|
||||
w.ShopID = shopID
|
||||
h.db.Create(&w)
|
||||
c.JSON(http.StatusCreated, gin.H{"data": w})
|
||||
}
|
||||
|
||||
func (h *WarehouseHandler) Update(c *gin.Context) {
|
||||
hotelID := middleware.GetHotelID(c)
|
||||
shopID := middleware.GetShopID(c)
|
||||
var w model.Warehouse
|
||||
if err := h.db.Where("id = ? AND hotel_id = ? AND deleted_at IS NULL", c.Param("id"), hotelID).
|
||||
if err := h.db.Where("id = ? AND shop_id = ? AND deleted_at IS NULL", c.Param("id"), shopID).
|
||||
First(&w).Error; err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
|
||||
return
|
||||
}
|
||||
c.ShouldBindJSON(&w)
|
||||
w.HotelID = hotelID
|
||||
w.ShopID = shopID
|
||||
h.db.Save(&w)
|
||||
c.JSON(http.StatusOK, gin.H{"data": w})
|
||||
}
|
||||
|
||||
func (h *WarehouseHandler) Delete(c *gin.Context) {
|
||||
hotelID := middleware.GetHotelID(c)
|
||||
shopID := middleware.GetShopID(c)
|
||||
now := timeNow()
|
||||
h.db.Model(&model.Warehouse{}).
|
||||
Where("id = ? AND hotel_id = ? AND deleted_at IS NULL", c.Param("id"), hotelID).
|
||||
Where("id = ? AND shop_id = ? AND deleted_at IS NULL", c.Param("id"), shopID).
|
||||
Update("deleted_at", now)
|
||||
c.JSON(http.StatusOK, gin.H{"message": "deleted"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user