bindbox-game/.trae/documents/Add Product Description Field.md
邹方成 45815bfb7d chore: 清理无用文件与优化代码结构
refactor(utils): 修复密码哈希比较逻辑错误
feat(user): 新增按状态筛选优惠券接口
docs: 添加虚拟发货与任务中心相关文档
fix(wechat): 修正Code2Session上下文传递问题
test: 补充订单折扣与积分转换测试用例
build: 更新配置文件与构建脚本
style: 清理多余的空行与注释
2025-12-18 17:35:55 +08:00

32 lines
1.6 KiB
Markdown

# Add Product Description Field for App Detail
## 1. Database Migration
We need to add a `description` column to the `products` table to store the product details.
**SQL Statement:**
```sql
ALTER TABLE products ADD COLUMN description TEXT COMMENT '商品详情';
```
## 2. Backend Model Update
Update the GORM model and DAO to reflect the database change.
* **Model**: Update `internal/repository/mysql/model/products.gen.go` to include the `Description` field.
* **DAO**: Update `internal/repository/mysql/dao/products.gen.go` to include the `Description` field definition and mapping.
## 3. Service Layer Update
Update `internal/service/product/product.go` to handle the new field.
* **Input Structs**: Add `Description` to `CreateProductInput` and `ModifyProductInput`.
* **Business Logic**:
* Update `CreateProduct` to save the description.
* Update `ModifyProduct` to update the description.
* Update `GetDetailForApp` to populate the `Description` field from the database instead of returning an empty string.
## 4. Admin API Update
Update the Admin API to allow creating and editing products with a description.
* **File**: `internal/api/admin/product_create.go`
* **Request Structs**: Add `description` field to `createProductRequest` and `modifyProductRequest`.
* **Handlers**: Pass the `description` from the request to the service layer.
## 5. App API Verification
* **File**: `internal/api/app/product.go`
* The `GetProductDetailForApp` function already returns a `Description` field in the response. By updating the service layer to populate this field, the App API will automatically return the correct data.