article.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. package client
  2. import (
  3. "context"
  4. "go-common/app/interface/openplatform/article/model"
  5. "go-common/library/net/rpc"
  6. )
  7. const (
  8. _addArticle = "RPC.AddArticle"
  9. _updateArticle = "RPC.UpdateArticle"
  10. _delArticle = "RPC.DelArticle"
  11. _creationUpperArticles = "RPC.CreationUpperArticles"
  12. _creationArticle = "RPC.CreationArticle"
  13. _categories = "RPC.Categories"
  14. _categoriesMap = "RPC.CategoriesMap"
  15. _setStat = "RPC.SetStat"
  16. _addArticleCache = "RPC.AddArticleCache"
  17. _updateArticleCache = "RPC.UpdateArticleCache"
  18. _delArticleCache = "RPC.DelArticleCache"
  19. _upsArtMetas = "RPC.UpsArtMetas"
  20. _artMetas = "RPC.ArticleMetas"
  21. _updateRecommends = "RPC.UpdateRecommends"
  22. _recommends = "RPC.Recommends"
  23. _creationWithdrawArticle = "RPC.CreationWithdrawArticle"
  24. _upArtMetas = "RPC.UpArtMetas"
  25. _addArtDraft = "RPC.AddArtDraft"
  26. _delArtDraft = "RPC.DelArtDraft"
  27. _artDraft = "RPC.ArtDraft"
  28. _upperDrafts = "RPC.UpperDrafts"
  29. _articleRemainCount = "RPC.ArticleRemainCount"
  30. _delRecommendArtCache = "RPC.DelRecommendArtCache"
  31. _favorites = "RPC.Favorites"
  32. _updateAuthorCache = "RPC.UpdateAuthorCache"
  33. _updateSortCache = "RPC.UpdateSortCache"
  34. _isAuthor = "RPC.IsAuthor"
  35. _newArticleCount = "RPC.NewArticleCount"
  36. _hadLikesByMid = "RPC.HadLikesByMid"
  37. _upMoreArts = "RPC.UpMoreArts"
  38. _creationUpStat = "RPC.CreationUpStat"
  39. _creationUpThirtyDayStat = "RPC.CreationUpThirtyDayStat"
  40. _upLists = "RPC.UpLists"
  41. _rebuildAllRC = "RPC.RebuildAllListReadCount"
  42. _updateHotspots = "RPC.UpdateHotspots"
  43. )
  44. const (
  45. _appid = "article.service"
  46. )
  47. var (
  48. _noArg = &struct{}{}
  49. _noReply = &struct{}{}
  50. )
  51. // Service struct info.
  52. type Service struct {
  53. client *rpc.Client2
  54. }
  55. //go:generate mockgen -source article.go -destination mock.go -package client
  56. // ArticleRPC article rpc.
  57. type ArticleRPC interface {
  58. AddArticle(c context.Context, arg *model.ArgArticle) (id int64, err error)
  59. AddArticleCache(c context.Context, arg *model.ArgAid) (err error)
  60. UpdateArticleCache(c context.Context, arg *model.ArgAidCid) (err error)
  61. DelArticleCache(c context.Context, arg *model.ArgAidMid) (err error)
  62. UpdateArticle(c context.Context, arg *model.ArgArticle) (err error)
  63. CreationWithdrawArticle(c context.Context, arg *model.ArgAidMid) (err error)
  64. DelArticle(c context.Context, arg *model.ArgAidMid) (err error)
  65. CreationArticle(c context.Context, arg *model.ArgAidMid) (res *model.Article, err error)
  66. CreationUpperArticles(c context.Context, arg *model.ArgCreationArts) (res *model.CreationArts, err error)
  67. Categories(c context.Context, arg *model.ArgIP) (res *model.Categories, err error)
  68. CategoriesMap(c context.Context, arg *model.ArgIP) (res map[int64]*model.Category, err error)
  69. SetStat(c context.Context, arg *model.ArgStats) (err error)
  70. UpsArtMetas(c context.Context, arg *model.ArgUpsArts) (res map[int64][]*model.Meta, err error)
  71. ArticleMetas(c context.Context, arg *model.ArgAids) (res map[int64]*model.Meta, err error)
  72. UpdateRecommends(c context.Context) (err error)
  73. Recommends(c context.Context, arg *model.ArgRecommends) (res []*model.Meta, err error)
  74. UpArtMetas(c context.Context, arg *model.ArgUpArts) (res *model.UpArtMetas, err error)
  75. AddArtDraft(c context.Context, arg *model.ArgArticle) (id int64, err error)
  76. UpdateArtDraft(c context.Context, arg *model.ArgAidMid) (err error)
  77. DelArtDraft(c context.Context, arg *model.ArgAidMid) (err error)
  78. ArtDraft(c context.Context, arg *model.ArgAidMid) (res *model.Draft, err error)
  79. UpperDrafts(c context.Context, arg *model.ArgUpDraft) (res *model.Drafts, err error)
  80. ArticleRemainCount(c context.Context, arg *model.ArgMid) (res int, err error)
  81. DelRecommendArtCache(c context.Context, arg *model.ArgAidCid) (err error)
  82. Favorites(c context.Context, arg *model.ArgFav) (res []*model.Favorite, err error)
  83. UpdateAuthorCache(c context.Context, arg *model.ArgAuthor) (err error)
  84. UpdateSortCache(c context.Context, arg *model.ArgSort) (err error)
  85. IsAuthor(c context.Context, arg *model.ArgMid) (res bool, err error)
  86. NewArticleCount(c context.Context, arg *model.ArgNewArt) (res int64, err error)
  87. HadLikesByMid(c context.Context, arg *model.ArgMidAids) (res map[int64]int, err error)
  88. UpMoreArts(c context.Context, arg *model.ArgAid) (res []*model.Meta, err error)
  89. CreationUpStat(c context.Context, arg *model.ArgMid) (res model.UpStat, err error)
  90. CreationUpThirtyDayStat(c context.Context, arg *model.ArgMid) (res []*model.ThirtyDayArticle, err error)
  91. UpLists(c context.Context, arg *model.ArgMid) (res model.UpLists, err error)
  92. }
  93. // New new service instance and return.
  94. func New(c *rpc.ClientConfig) (s *Service) {
  95. s = &Service{}
  96. s.client = rpc.NewDiscoveryCli(_appid, c)
  97. return
  98. }
  99. // AddArticle adds article when article passed. purge cache.
  100. func (s *Service) AddArticle(c context.Context, arg *model.ArgArticle) (id int64, err error) {
  101. err = s.client.Call(c, _addArticle, arg, &id)
  102. return
  103. }
  104. // AddArticleCache adds article when article passed. purge cache.
  105. func (s *Service) AddArticleCache(c context.Context, arg *model.ArgAid) (err error) {
  106. err = s.client.Call(c, _addArticleCache, arg, _noReply)
  107. return
  108. }
  109. // UpdateArticleCache adds article when article passed. purge cache.
  110. func (s *Service) UpdateArticleCache(c context.Context, arg *model.ArgAidCid) (err error) {
  111. err = s.client.Call(c, _updateArticleCache, arg, _noReply)
  112. return
  113. }
  114. // DelArticleCache adds article when article passed. purge cache.
  115. func (s *Service) DelArticleCache(c context.Context, arg *model.ArgAidMid) (err error) {
  116. err = s.client.Call(c, _delArticleCache, arg, _noReply)
  117. return
  118. }
  119. // UpdateArticle updates article when article passed. purge cache.
  120. func (s *Service) UpdateArticle(c context.Context, arg *model.ArgArticle) (err error) {
  121. err = s.client.Call(c, _updateArticle, arg, _noReply)
  122. return
  123. }
  124. // CreationWithdrawArticle author withdraw article.
  125. func (s *Service) CreationWithdrawArticle(c context.Context, arg *model.ArgAidMid) (err error) {
  126. err = s.client.Call(c, _creationWithdrawArticle, arg, _noReply)
  127. return
  128. }
  129. // DelArticle drops article when article not passed. purge cache.
  130. func (s *Service) DelArticle(c context.Context, arg *model.ArgAidMid) (err error) {
  131. err = s.client.Call(c, _delArticle, arg, _noReply)
  132. return
  133. }
  134. // CreationArticle gets article's meta.
  135. func (s *Service) CreationArticle(c context.Context, arg *model.ArgAidMid) (res *model.Article, err error) {
  136. err = s.client.Call(c, _creationArticle, arg, &res)
  137. return
  138. }
  139. // CreationUpperArticles gets article's meta.
  140. func (s *Service) CreationUpperArticles(c context.Context, arg *model.ArgCreationArts) (res *model.CreationArts, err error) {
  141. err = s.client.Call(c, _creationUpperArticles, arg, &res)
  142. return
  143. }
  144. // Categories list categories of article
  145. func (s *Service) Categories(c context.Context, arg *model.ArgIP) (res *model.Categories, err error) {
  146. err = s.client.Call(c, _categories, arg, &res)
  147. return
  148. }
  149. // CategoriesMap list categories of article map
  150. func (s *Service) CategoriesMap(c context.Context, arg *model.ArgIP) (res map[int64]*model.Category, err error) {
  151. err = s.client.Call(c, _categoriesMap, arg, &res)
  152. return
  153. }
  154. // SetStat updates article's stat cache.
  155. func (s *Service) SetStat(c context.Context, arg *model.ArgStats) (err error) {
  156. err = s.client.Call(c, _setStat, arg, _noReply)
  157. return
  158. }
  159. // UpsArtMetas list passed article meta of ups
  160. func (s *Service) UpsArtMetas(c context.Context, arg *model.ArgUpsArts) (res map[int64][]*model.Meta, err error) {
  161. err = s.client.Call(c, _upsArtMetas, arg, &res)
  162. return
  163. }
  164. // ArticleMetas get article metas by aids
  165. func (s *Service) ArticleMetas(c context.Context, arg *model.ArgAids) (res map[int64]*model.Meta, err error) {
  166. err = s.client.Call(c, _artMetas, arg, &res)
  167. return
  168. }
  169. // UpdateRecommends updates recommended articles.
  170. func (s *Service) UpdateRecommends(c context.Context) (err error) {
  171. err = s.client.Call(c, _updateRecommends, _noArg, _noReply)
  172. return
  173. }
  174. // Recommends list recommend articles
  175. func (s *Service) Recommends(c context.Context, arg *model.ArgRecommends) (res []*model.Meta, err error) {
  176. err = s.client.Call(c, _recommends, arg, &res)
  177. return
  178. }
  179. // UpArtMetas list up's article list
  180. func (s *Service) UpArtMetas(c context.Context, arg *model.ArgUpArts) (res *model.UpArtMetas, err error) {
  181. err = s.client.Call(c, _upArtMetas, arg, &res)
  182. return
  183. }
  184. // AddArtDraft add article draft.
  185. func (s *Service) AddArtDraft(c context.Context, arg *model.ArgArticle) (id int64, err error) {
  186. err = s.client.Call(c, _addArtDraft, arg, &id)
  187. return
  188. }
  189. // DelArtDraft deletes draft.
  190. func (s *Service) DelArtDraft(c context.Context, arg *model.ArgAidMid) (err error) {
  191. err = s.client.Call(c, _delArtDraft, arg, _noReply)
  192. return
  193. }
  194. // ArtDraft get article draft by id
  195. func (s *Service) ArtDraft(c context.Context, arg *model.ArgAidMid) (res *model.Draft, err error) {
  196. err = s.client.Call(c, _artDraft, arg, &res)
  197. return
  198. }
  199. // UpperDrafts get article drafts by mid
  200. func (s *Service) UpperDrafts(c context.Context, arg *model.ArgUpDraft) (res *model.Drafts, err error) {
  201. err = s.client.Call(c, _upperDrafts, arg, &res)
  202. return
  203. }
  204. // ArticleRemainCount returns the number that user could be use to posting new articles.
  205. func (s *Service) ArticleRemainCount(c context.Context, arg *model.ArgMid) (res int, err error) {
  206. err = s.client.Call(c, _articleRemainCount, arg, &res)
  207. return
  208. }
  209. // DelRecommendArtCache del recommend article cache
  210. func (s *Service) DelRecommendArtCache(c context.Context, arg *model.ArgAidCid) (err error) {
  211. err = s.client.Boardcast(c, _delRecommendArtCache, arg, _noReply)
  212. return
  213. }
  214. // Favorites list user's favorite articles
  215. func (s *Service) Favorites(c context.Context, arg *model.ArgFav) (res []*model.Favorite, err error) {
  216. err = s.client.Call(c, _favorites, arg, &res)
  217. return
  218. }
  219. // UpdateAuthorCache update author cache
  220. func (s *Service) UpdateAuthorCache(c context.Context, arg *model.ArgAuthor) (err error) {
  221. err = s.client.Call(c, _updateAuthorCache, arg, _noReply)
  222. return
  223. }
  224. // UpdateSortCache update sort cache
  225. func (s *Service) UpdateSortCache(c context.Context, arg *model.ArgSort) (err error) {
  226. err = s.client.Call(c, _updateSortCache, arg, _noReply)
  227. return
  228. }
  229. // IsAuthor checks that whether user has permission to write model.
  230. func (s *Service) IsAuthor(c context.Context, arg *model.ArgMid) (res bool, err error) {
  231. err = s.client.Call(c, _isAuthor, arg, &res)
  232. return
  233. }
  234. // NewArticleCount get new article count since given pubtime
  235. func (s *Service) NewArticleCount(c context.Context, arg *model.ArgNewArt) (res int64, err error) {
  236. err = s.client.Call(c, _newArticleCount, arg, &res)
  237. return
  238. }
  239. // HadLikesByMid check user if has liked articles
  240. func (s *Service) HadLikesByMid(c context.Context, arg *model.ArgMidAids) (res map[int64]int, err error) {
  241. err = s.client.Call(c, _hadLikesByMid, arg, &res)
  242. return
  243. }
  244. // UpMoreArts get upper more arts
  245. func (s *Service) UpMoreArts(c context.Context, arg *model.ArgAid) (res []*model.Meta, err error) {
  246. err = s.client.Call(c, _upMoreArts, arg, &res)
  247. return
  248. }
  249. // CreationUpStat creation up stat
  250. func (s *Service) CreationUpStat(c context.Context, arg *model.ArgMid) (res model.UpStat, err error) {
  251. err = s.client.Call(c, _creationUpStat, arg, &res)
  252. return
  253. }
  254. // CreationUpThirtyDayStat creation up thirty day stat
  255. func (s *Service) CreationUpThirtyDayStat(c context.Context, arg *model.ArgMid) (res []*model.ThirtyDayArticle, err error) {
  256. err = s.client.Call(c, _creationUpThirtyDayStat, arg, &res)
  257. return
  258. }
  259. // UpLists get upper article lists
  260. func (s *Service) UpLists(c context.Context, arg *model.ArgMid) (res model.UpLists, err error) {
  261. err = s.client.Call(c, _upLists, arg, &res)
  262. return
  263. }
  264. // RebuildAllListReadCount rebuild all list read count
  265. func (s *Service) RebuildAllListReadCount(c context.Context) (err error) {
  266. err = s.client.Call(c, _rebuildAllRC, _noArg, _noReply)
  267. return
  268. }
  269. // UpdateHotspots update hotspots
  270. func (s *Service) UpdateHotspots(c context.Context, arg *model.ArgForce) (err error) {
  271. err = s.client.Call(c, _updateHotspots, arg, _noReply)
  272. return
  273. }