app-cloudep-product-service/pkg/domain/product/item_status.go

51 lines
1.2 KiB
Go
Raw Normal View History

2025-03-19 06:45:44 +00:00
package product
type ItemStatus int8
func (p *ItemStatus) ToString() string {
s, _ := StatusToString(*p)
return s
}
const (
2025-04-01 09:44:57 +00:00
StatusActive ItemStatus = 1 + iota // 上架
StatusInactive // 下架
StatusOutOfStock // 缺貨
StatusUnderReview // 商品審核中
2025-03-19 06:45:44 +00:00
)
const (
2025-04-01 09:44:57 +00:00
StatusActiveStr = "active"
StatusInactiveStr = "inactive"
StatusOutOfStockStr = "out_of_stock"
StatusUnderReviewStr = "under_review"
2025-03-19 06:45:44 +00:00
)
var statusToStringMap = map[ItemStatus]string{
StatusActive: StatusActiveStr,
StatusInactive: StatusInactiveStr,
StatusOutOfStock: StatusOutOfStockStr,
}
var stringToStatusMap = map[string]ItemStatus{
2025-04-01 09:44:57 +00:00
StatusActiveStr: StatusActive,
StatusInactiveStr: StatusInactive,
StatusOutOfStockStr: StatusOutOfStock,
StatusUnderReviewStr: StatusUnderReview,
2025-03-19 06:45:44 +00:00
}
// StatusToString 將 ProductItemStatus 轉換為字串
func StatusToString(status ItemStatus) (string, bool) {
str, ok := statusToStringMap[status]
return str, ok
}
// StringToItemStatus 將字串轉換為 ProductItemStatus
func StringToItemStatus(statusStr string) (ItemStatus, bool) {
status, ok := stringToStatusMap[statusStr]
return status, ok
}