作者 yangfu

Merge branch 'dev' into test

@@ -136,6 +136,8 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction. @@ -136,6 +136,8 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
136 default: 136 default:
137 tx = tx.Order("created_at desc") 137 tx = tx.Order("created_at desc")
138 } 138 }
  139 + } else {
  140 + tx = tx.Order("created_at desc")
139 } 141 }
140 if v, ok := queryOptions["ids"]; ok { 142 if v, ok := queryOptions["ids"]; ok {
141 tx = tx.Where("id in (?)", v) 143 tx = tx.Where("id in (?)", v)
@@ -102,7 +102,7 @@ func (m *Article) SetSummary(sectionList []*ArticleSection) { @@ -102,7 +102,7 @@ func (m *Article) SetSummary(sectionList []*ArticleSection) {
102 //设置内容概要 102 //设置内容概要
103 103
104 // 截取内容 50个字 104 // 截取内容 50个字
105 - stringIndex := 0 //字符串长度 105 + length := 0 //字符串长度
106 content := "" 106 content := ""
107 for i := range sectionList { 107 for i := range sectionList {
108 str := strings.TrimSpace(sectionList[i].Content) 108 str := strings.TrimSpace(sectionList[i].Content)
@@ -111,11 +111,12 @@ func (m *Article) SetSummary(sectionList []*ArticleSection) { @@ -111,11 +111,12 @@ func (m *Article) SetSummary(sectionList []*ArticleSection) {
111 break 111 break
112 } 112 }
113 } 113 }
114 - stringIndex = len(content)  
115 - if len(content) > 50 {  
116 - stringIndex = 50 114 + runeContent := []rune(content)
  115 + length = len(runeContent)
  116 + if length > 50 {
  117 + length = 50
117 } 118 }
118 - m.Summary = content[0:stringIndex] 119 + m.Summary = string(runeContent[0:length])
119 } 120 }
120 121
121 func (m *Article) WhoCanRead(userId int64) bool { 122 func (m *Article) WhoCanRead(userId int64) bool {