feat: product number
CI / changes (push) Successful in 36s
CI / docker-bff (push) Successful in 3m8s
CI / docker-product (push) Successful in 3m36s
CI / docker-admin (push) Successful in 3m35s
CI / docker-user (push) Successful in 9s
CI / docker-ad (push) Successful in 29s
CI / docker-chore (push) Failing after 4s
CI / changes (push) Successful in 36s
CI / docker-bff (push) Successful in 3m8s
CI / docker-product (push) Successful in 3m36s
CI / docker-admin (push) Successful in 3m35s
CI / docker-user (push) Successful in 9s
CI / docker-ad (push) Successful in 29s
CI / docker-chore (push) Failing after 4s
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
product "lone-services/rpc/product/pb"
|
||||
"lone-services/services/product/internal/dao"
|
||||
"time"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
func toProductItem(row dao.ProductInfo) *product.Item {
|
||||
func toProductItem(row dao.Info) *product.Item {
|
||||
publishTime := ""
|
||||
if !row.PublishTime.IsZero() {
|
||||
publishTime = row.PublishTime.Format(time.DateTime)
|
||||
@@ -31,7 +36,7 @@ func toProductItem(row dao.ProductInfo) *product.Item {
|
||||
IndexImage: row.IndexImage,
|
||||
Cubage: row.Cubage,
|
||||
Label: row.Label,
|
||||
Images: row.Images,
|
||||
Images: splitImages(row.Images),
|
||||
IsBuy: uint32(row.IsBuy),
|
||||
PeriodValidity: int32(row.PeriodValidity),
|
||||
PublishTime: publishTime,
|
||||
@@ -50,3 +55,38 @@ func toProductItem(row dao.ProductInfo) *product.Item {
|
||||
Edit: uint32(row.Edit),
|
||||
}
|
||||
}
|
||||
|
||||
func joinImages(images []string) string {
|
||||
list := cleanImages(images)
|
||||
if len(list) == 0 {
|
||||
return "[]"
|
||||
}
|
||||
buf, err := jsoniter.Marshal(list)
|
||||
if err != nil {
|
||||
return "[]"
|
||||
}
|
||||
return string(buf)
|
||||
}
|
||||
|
||||
func splitImages(images string) []string {
|
||||
images = strings.TrimSpace(images)
|
||||
if images == utils.StringEmpty {
|
||||
return []string{}
|
||||
}
|
||||
var list []string
|
||||
if err := jsoniter.Unmarshal([]byte(images), &list); err != nil {
|
||||
return []string{}
|
||||
}
|
||||
return cleanImages(list)
|
||||
}
|
||||
|
||||
func cleanImages(images []string) []string {
|
||||
out := make([]string, 0, len(images))
|
||||
for _, img := range images {
|
||||
img = strings.TrimSpace(img)
|
||||
if img != utils.StringEmpty {
|
||||
out = append(out, img)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user