Skip to content

Commit

Permalink
feat(promotion): 巨量广告升级版「获取广告列表接口」图文素材类型参数枚举值将于12月19日变更.
Browse files Browse the repository at this point in the history
carousel_type 由int类型变为enum.ImageMode; 为适用变化为enum.ImageMode增加自定义UnmarshalJSON以同时支持解析int/enum.ImageMode类型
  • Loading branch information
bububa committed Nov 24, 2023
1 parent c849d4e commit 4ebd8b4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions marketing-api/enum/image_mode.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package enum

import "strconv"

// ImageMode 素材类型
// 不符合下列素材类型尺寸比例,投放后台不显示
type ImageMode string
Expand Down Expand Up @@ -39,3 +41,27 @@ const (
// SEARCH_DISPLAY_WINDOW_IMAGE 搜索橱窗橱窗
SEARCH_DISPLAY_WINDOW_IMAGE ImageMode = "SEARCH_DISPLAY_WINDOW_IMAGE"
)

// UnmarshalJSON implement json Unmarshal interface
func (im *ImageMode) UnmarshalJSON(b []byte) (err error) {
if b[0] == '"' && b[len(b)-1] == '"' {
b = b[1 : len(b)-1]
}
str := string(b)
if i, err := strconv.ParseUint(str, 10, 64); err != nil {
*im = ImageMode(str)
return nil
} else {
switch i {
case 1:
*im = INFORMATION_FLOW_IMAGE
case 2:
*im = TOUTIAO_SEARCH_AD_IMAGE
case 3:
*im = SEARCH_DISPLAY_WINDOW_IMAGE
default:
*im = ImageMode(str)
}
}
return
}
2 changes: 1 addition & 1 deletion marketing-api/model/v3/promotion/promotion.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ type CarouselMaterial struct {
// MaterialStatus 素材审核状态
MaterialStatus string `json:"material_status,omitempty"`
// CarouselType 图集素材类型
CarouselType int `json:"carousel_type,omitempty"`
CarouselType enum.ImageMode `json:"carousel_type,omitempty"`
// ImageSubject 图片主题
ImageSubject []file.ImageSubject `json:"image_subject,omitempty"`
}

0 comments on commit 4ebd8b4

Please sign in to comment.