| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package serializer
- import (
- "dsbqj-admin/model/mongo/channel"
- )
- // ChannelResponse 渠道响应,匹配前端 ChannelData 格式
- type ChannelResponse struct {
- ID string `json:"id"`
- Name string `json:"name"`
- Code string `json:"code"`
- Description string `json:"description"`
- Status bool `json:"status"`
- CreateTime string `json:"createTime"`
- }
- // BuildChannel 构建单条渠道响应
- func BuildChannel(c *channel.Channel) *ChannelResponse {
- if c == nil {
- return nil
- }
- return &ChannelResponse{
- ID: c.ID.Hex(),
- Name: c.Name,
- Code: c.Code,
- Description: c.Description,
- Status: c.Status,
- CreateTime: c.GetCreateTime(),
- }
- }
- // BuildChannelList 构建渠道列表响应
- func BuildChannelList(list []channel.Channel, total int) map[string]interface{} {
- items := make([]*ChannelResponse, 0, len(list))
- for i := range list {
- items = append(items, BuildChannel(&list[i]))
- }
- return map[string]interface{}{
- "list": items,
- "total": total,
- }
- }
- // BuildChannelAll 构建渠道列表响应
- func BuildChannelAll(list []channel.Channel) []*ChannelResponse {
- items := make([]*ChannelResponse, 0, len(list))
- for i := range list {
- items = append(items, BuildChannel(&list[i]))
- }
- return items
- }
|