channel.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package serializer
  2. import (
  3. "dsbqj-admin/model/mongo/channel"
  4. )
  5. // ChannelResponse 渠道响应,匹配前端 ChannelData 格式
  6. type ChannelResponse struct {
  7. ID string `json:"id"`
  8. Name string `json:"name"`
  9. Code string `json:"code"`
  10. Platform string `json:"platform"`
  11. Description string `json:"description"`
  12. Status bool `json:"status"`
  13. CreateTime string `json:"createTime"`
  14. }
  15. // BuildChannel 构建单条渠道响应
  16. func BuildChannel(c *channel.Channel) *ChannelResponse {
  17. if c == nil {
  18. return nil
  19. }
  20. return &ChannelResponse{
  21. ID: c.ID.Hex(),
  22. Name: c.Name,
  23. Code: c.Code,
  24. Platform: c.Platform,
  25. Description: c.Description,
  26. Status: c.Status,
  27. CreateTime: c.GetCreateTime(),
  28. }
  29. }
  30. // BuildChannelList 构建渠道列表响应
  31. func BuildChannelList(list []channel.Channel, total int) map[string]interface{} {
  32. items := make([]*ChannelResponse, 0, len(list))
  33. for i := range list {
  34. items = append(items, BuildChannel(&list[i]))
  35. }
  36. return map[string]interface{}{
  37. "list": items,
  38. "total": total,
  39. }
  40. }
  41. // BuildChannelAll 构建渠道列表响应
  42. func BuildChannelAll(list []channel.Channel) []*ChannelResponse {
  43. items := make([]*ChannelResponse, 0, len(list))
  44. for i := range list {
  45. items = append(items, BuildChannel(&list[i]))
  46. }
  47. return items
  48. }