移动端弹幕优化
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
// ProductApplicationService 产品应用服务接口
|
||||
type ProductApplicationService interface {
|
||||
// 产品管理
|
||||
CreateProduct(ctx context.Context, cmd *commands.CreateProductCommand) error
|
||||
CreateProduct(ctx context.Context, cmd *commands.CreateProductCommand) (*responses.ProductAdminInfoResponse, error)
|
||||
UpdateProduct(ctx context.Context, cmd *commands.UpdateProductCommand) error
|
||||
DeleteProduct(ctx context.Context, cmd *commands.DeleteProductCommand) error
|
||||
|
||||
@@ -46,6 +46,4 @@ type ProductApplicationService interface {
|
||||
CreateProductApiConfig(ctx context.Context, productID string, config *responses.ProductApiConfigResponse) error
|
||||
UpdateProductApiConfig(ctx context.Context, configID string, config *responses.ProductApiConfigResponse) error
|
||||
DeleteProductApiConfig(ctx context.Context, configID string) error
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func NewProductApplicationService(
|
||||
|
||||
// CreateProduct 创建产品
|
||||
// 业务流程<E6B581>?. 构建产品实体 2. 创建产品
|
||||
func (s *ProductApplicationServiceImpl) CreateProduct(ctx context.Context, cmd *commands.CreateProductCommand) error {
|
||||
func (s *ProductApplicationServiceImpl) CreateProduct(ctx context.Context, cmd *commands.CreateProductCommand) (*responses.ProductAdminInfoResponse, error) {
|
||||
// 1. 构建产品实体
|
||||
product := &entities.Product{
|
||||
Name: cmd.Name,
|
||||
@@ -71,8 +71,13 @@ func (s *ProductApplicationServiceImpl) CreateProduct(ctx context.Context, cmd *
|
||||
}
|
||||
|
||||
// 2. 创建产品
|
||||
_, err := s.productManagementService.CreateProduct(ctx, product)
|
||||
return err
|
||||
createdProduct, err := s.productManagementService.CreateProduct(ctx, product)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 3. 转换为响应对象
|
||||
return s.convertToProductAdminInfoResponse(createdProduct), nil
|
||||
}
|
||||
|
||||
// UpdateProduct 更新产品
|
||||
|
||||
@@ -34,7 +34,13 @@ func NewGormProductRepository(db *gorm.DB, logger *zap.Logger) repositories.Prod
|
||||
}
|
||||
|
||||
func (r *GormProductRepository) Create(ctx context.Context, entity entities.Product) (entities.Product, error) {
|
||||
err := r.CreateEntity(ctx, &entity)
|
||||
// 使用 Select 明确指定所有字段,确保 false 值也能正确保存
|
||||
// 这样可以避免 GORM 的 default:true 标签在字段为 false 时使用数据库默认值
|
||||
err := r.GetDB(ctx).Select(
|
||||
"id", "old_id", "name", "code", "description", "content", "category_id",
|
||||
"price", "cost_price", "remark", "is_enabled", "is_visible", "is_package",
|
||||
"seo_title", "seo_description", "seo_keywords",
|
||||
).Create(&entity).Error
|
||||
return entity, err
|
||||
}
|
||||
|
||||
|
||||
@@ -73,13 +73,14 @@ func (h *ProductAdminHandler) CreateProduct(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.productAppService.CreateProduct(c.Request.Context(), &cmd); err != nil {
|
||||
result, err := h.productAppService.CreateProduct(c.Request.Context(), &cmd)
|
||||
if err != nil {
|
||||
h.logger.Error("创建产品失败", zap.Error(err))
|
||||
h.responseBuilder.BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
h.responseBuilder.Created(c, nil, "产品创建成功")
|
||||
h.responseBuilder.Created(c, result, "产品创建成功")
|
||||
}
|
||||
|
||||
// UpdateProduct 更新产品
|
||||
|
||||
Reference in New Issue
Block a user