pagination.go 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "fmt"
  6. "wechat-api/ent/agent"
  7. "wechat-api/ent/agentbase"
  8. "wechat-api/ent/aliyunavatar"
  9. "wechat-api/ent/batchmsg"
  10. "wechat-api/ent/category"
  11. "wechat-api/ent/chatrecords"
  12. "wechat-api/ent/chatsession"
  13. "wechat-api/ent/contact"
  14. "wechat-api/ent/employee"
  15. "wechat-api/ent/employeeconfig"
  16. "wechat-api/ent/label"
  17. "wechat-api/ent/labelrelationship"
  18. "wechat-api/ent/message"
  19. "wechat-api/ent/messagerecords"
  20. "wechat-api/ent/msg"
  21. "wechat-api/ent/server"
  22. "wechat-api/ent/sopnode"
  23. "wechat-api/ent/sopstage"
  24. "wechat-api/ent/soptask"
  25. "wechat-api/ent/token"
  26. "wechat-api/ent/tutorial"
  27. "wechat-api/ent/workexperience"
  28. "wechat-api/ent/wx"
  29. "wechat-api/ent/wxcard"
  30. "wechat-api/ent/wxcarduser"
  31. "wechat-api/ent/wxcardvisit"
  32. )
  33. const errInvalidPage = "INVALID_PAGE"
  34. const (
  35. listField = "list"
  36. pageNumField = "pageNum"
  37. pageSizeField = "pageSize"
  38. )
  39. type PageDetails struct {
  40. Page uint64 `json:"page"`
  41. Size uint64 `json:"size"`
  42. Total uint64 `json:"total"`
  43. }
  44. // OrderDirection defines the directions in which to order a list of items.
  45. type OrderDirection string
  46. const (
  47. // OrderDirectionAsc specifies an ascending order.
  48. OrderDirectionAsc OrderDirection = "ASC"
  49. // OrderDirectionDesc specifies a descending order.
  50. OrderDirectionDesc OrderDirection = "DESC"
  51. )
  52. // Validate the order direction value.
  53. func (o OrderDirection) Validate() error {
  54. if o != OrderDirectionAsc && o != OrderDirectionDesc {
  55. return fmt.Errorf("%s is not a valid OrderDirection", o)
  56. }
  57. return nil
  58. }
  59. // String implements fmt.Stringer interface.
  60. func (o OrderDirection) String() string {
  61. return string(o)
  62. }
  63. func (o OrderDirection) reverse() OrderDirection {
  64. if o == OrderDirectionDesc {
  65. return OrderDirectionAsc
  66. }
  67. return OrderDirectionDesc
  68. }
  69. const errInvalidPagination = "INVALID_PAGINATION"
  70. type AgentPager struct {
  71. Order agent.OrderOption
  72. Filter func(*AgentQuery) (*AgentQuery, error)
  73. }
  74. // AgentPaginateOption enables pagination customization.
  75. type AgentPaginateOption func(*AgentPager)
  76. // DefaultAgentOrder is the default ordering of Agent.
  77. var DefaultAgentOrder = Desc(agent.FieldID)
  78. func newAgentPager(opts []AgentPaginateOption) (*AgentPager, error) {
  79. pager := &AgentPager{}
  80. for _, opt := range opts {
  81. opt(pager)
  82. }
  83. if pager.Order == nil {
  84. pager.Order = DefaultAgentOrder
  85. }
  86. return pager, nil
  87. }
  88. func (p *AgentPager) ApplyFilter(query *AgentQuery) (*AgentQuery, error) {
  89. if p.Filter != nil {
  90. return p.Filter(query)
  91. }
  92. return query, nil
  93. }
  94. // AgentPageList is Agent PageList result.
  95. type AgentPageList struct {
  96. List []*Agent `json:"list"`
  97. PageDetails *PageDetails `json:"pageDetails"`
  98. }
  99. func (a *AgentQuery) Page(
  100. ctx context.Context, pageNum uint64, pageSize uint64, opts ...AgentPaginateOption,
  101. ) (*AgentPageList, error) {
  102. pager, err := newAgentPager(opts)
  103. if err != nil {
  104. return nil, err
  105. }
  106. if a, err = pager.ApplyFilter(a); err != nil {
  107. return nil, err
  108. }
  109. ret := &AgentPageList{}
  110. ret.PageDetails = &PageDetails{
  111. Page: pageNum,
  112. Size: pageSize,
  113. }
  114. query := a.Clone()
  115. query.ctx.Fields = nil
  116. count, err := query.Count(ctx)
  117. if err != nil {
  118. return nil, err
  119. }
  120. ret.PageDetails.Total = uint64(count)
  121. if pager.Order != nil {
  122. a = a.Order(pager.Order)
  123. } else {
  124. a = a.Order(DefaultAgentOrder)
  125. }
  126. a = a.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  127. list, err := a.All(ctx)
  128. if err != nil {
  129. return nil, err
  130. }
  131. ret.List = list
  132. return ret, nil
  133. }
  134. type AgentBasePager struct {
  135. Order agentbase.OrderOption
  136. Filter func(*AgentBaseQuery) (*AgentBaseQuery, error)
  137. }
  138. // AgentBasePaginateOption enables pagination customization.
  139. type AgentBasePaginateOption func(*AgentBasePager)
  140. // DefaultAgentBaseOrder is the default ordering of AgentBase.
  141. var DefaultAgentBaseOrder = Desc(agentbase.FieldID)
  142. func newAgentBasePager(opts []AgentBasePaginateOption) (*AgentBasePager, error) {
  143. pager := &AgentBasePager{}
  144. for _, opt := range opts {
  145. opt(pager)
  146. }
  147. if pager.Order == nil {
  148. pager.Order = DefaultAgentBaseOrder
  149. }
  150. return pager, nil
  151. }
  152. func (p *AgentBasePager) ApplyFilter(query *AgentBaseQuery) (*AgentBaseQuery, error) {
  153. if p.Filter != nil {
  154. return p.Filter(query)
  155. }
  156. return query, nil
  157. }
  158. // AgentBasePageList is AgentBase PageList result.
  159. type AgentBasePageList struct {
  160. List []*AgentBase `json:"list"`
  161. PageDetails *PageDetails `json:"pageDetails"`
  162. }
  163. func (ab *AgentBaseQuery) Page(
  164. ctx context.Context, pageNum uint64, pageSize uint64, opts ...AgentBasePaginateOption,
  165. ) (*AgentBasePageList, error) {
  166. pager, err := newAgentBasePager(opts)
  167. if err != nil {
  168. return nil, err
  169. }
  170. if ab, err = pager.ApplyFilter(ab); err != nil {
  171. return nil, err
  172. }
  173. ret := &AgentBasePageList{}
  174. ret.PageDetails = &PageDetails{
  175. Page: pageNum,
  176. Size: pageSize,
  177. }
  178. query := ab.Clone()
  179. query.ctx.Fields = nil
  180. count, err := query.Count(ctx)
  181. if err != nil {
  182. return nil, err
  183. }
  184. ret.PageDetails.Total = uint64(count)
  185. if pager.Order != nil {
  186. ab = ab.Order(pager.Order)
  187. } else {
  188. ab = ab.Order(DefaultAgentBaseOrder)
  189. }
  190. ab = ab.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  191. list, err := ab.All(ctx)
  192. if err != nil {
  193. return nil, err
  194. }
  195. ret.List = list
  196. return ret, nil
  197. }
  198. type AliyunAvatarPager struct {
  199. Order aliyunavatar.OrderOption
  200. Filter func(*AliyunAvatarQuery) (*AliyunAvatarQuery, error)
  201. }
  202. // AliyunAvatarPaginateOption enables pagination customization.
  203. type AliyunAvatarPaginateOption func(*AliyunAvatarPager)
  204. // DefaultAliyunAvatarOrder is the default ordering of AliyunAvatar.
  205. var DefaultAliyunAvatarOrder = Desc(aliyunavatar.FieldID)
  206. func newAliyunAvatarPager(opts []AliyunAvatarPaginateOption) (*AliyunAvatarPager, error) {
  207. pager := &AliyunAvatarPager{}
  208. for _, opt := range opts {
  209. opt(pager)
  210. }
  211. if pager.Order == nil {
  212. pager.Order = DefaultAliyunAvatarOrder
  213. }
  214. return pager, nil
  215. }
  216. func (p *AliyunAvatarPager) ApplyFilter(query *AliyunAvatarQuery) (*AliyunAvatarQuery, error) {
  217. if p.Filter != nil {
  218. return p.Filter(query)
  219. }
  220. return query, nil
  221. }
  222. // AliyunAvatarPageList is AliyunAvatar PageList result.
  223. type AliyunAvatarPageList struct {
  224. List []*AliyunAvatar `json:"list"`
  225. PageDetails *PageDetails `json:"pageDetails"`
  226. }
  227. func (aa *AliyunAvatarQuery) Page(
  228. ctx context.Context, pageNum uint64, pageSize uint64, opts ...AliyunAvatarPaginateOption,
  229. ) (*AliyunAvatarPageList, error) {
  230. pager, err := newAliyunAvatarPager(opts)
  231. if err != nil {
  232. return nil, err
  233. }
  234. if aa, err = pager.ApplyFilter(aa); err != nil {
  235. return nil, err
  236. }
  237. ret := &AliyunAvatarPageList{}
  238. ret.PageDetails = &PageDetails{
  239. Page: pageNum,
  240. Size: pageSize,
  241. }
  242. query := aa.Clone()
  243. query.ctx.Fields = nil
  244. count, err := query.Count(ctx)
  245. if err != nil {
  246. return nil, err
  247. }
  248. ret.PageDetails.Total = uint64(count)
  249. if pager.Order != nil {
  250. aa = aa.Order(pager.Order)
  251. } else {
  252. aa = aa.Order(DefaultAliyunAvatarOrder)
  253. }
  254. aa = aa.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  255. list, err := aa.All(ctx)
  256. if err != nil {
  257. return nil, err
  258. }
  259. ret.List = list
  260. return ret, nil
  261. }
  262. type BatchMsgPager struct {
  263. Order batchmsg.OrderOption
  264. Filter func(*BatchMsgQuery) (*BatchMsgQuery, error)
  265. }
  266. // BatchMsgPaginateOption enables pagination customization.
  267. type BatchMsgPaginateOption func(*BatchMsgPager)
  268. // DefaultBatchMsgOrder is the default ordering of BatchMsg.
  269. var DefaultBatchMsgOrder = Desc(batchmsg.FieldID)
  270. func newBatchMsgPager(opts []BatchMsgPaginateOption) (*BatchMsgPager, error) {
  271. pager := &BatchMsgPager{}
  272. for _, opt := range opts {
  273. opt(pager)
  274. }
  275. if pager.Order == nil {
  276. pager.Order = DefaultBatchMsgOrder
  277. }
  278. return pager, nil
  279. }
  280. func (p *BatchMsgPager) ApplyFilter(query *BatchMsgQuery) (*BatchMsgQuery, error) {
  281. if p.Filter != nil {
  282. return p.Filter(query)
  283. }
  284. return query, nil
  285. }
  286. // BatchMsgPageList is BatchMsg PageList result.
  287. type BatchMsgPageList struct {
  288. List []*BatchMsg `json:"list"`
  289. PageDetails *PageDetails `json:"pageDetails"`
  290. }
  291. func (bm *BatchMsgQuery) Page(
  292. ctx context.Context, pageNum uint64, pageSize uint64, opts ...BatchMsgPaginateOption,
  293. ) (*BatchMsgPageList, error) {
  294. pager, err := newBatchMsgPager(opts)
  295. if err != nil {
  296. return nil, err
  297. }
  298. if bm, err = pager.ApplyFilter(bm); err != nil {
  299. return nil, err
  300. }
  301. ret := &BatchMsgPageList{}
  302. ret.PageDetails = &PageDetails{
  303. Page: pageNum,
  304. Size: pageSize,
  305. }
  306. query := bm.Clone()
  307. query.ctx.Fields = nil
  308. count, err := query.Count(ctx)
  309. if err != nil {
  310. return nil, err
  311. }
  312. ret.PageDetails.Total = uint64(count)
  313. if pager.Order != nil {
  314. bm = bm.Order(pager.Order)
  315. } else {
  316. bm = bm.Order(DefaultBatchMsgOrder)
  317. }
  318. bm = bm.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  319. list, err := bm.All(ctx)
  320. if err != nil {
  321. return nil, err
  322. }
  323. ret.List = list
  324. return ret, nil
  325. }
  326. type CategoryPager struct {
  327. Order category.OrderOption
  328. Filter func(*CategoryQuery) (*CategoryQuery, error)
  329. }
  330. // CategoryPaginateOption enables pagination customization.
  331. type CategoryPaginateOption func(*CategoryPager)
  332. // DefaultCategoryOrder is the default ordering of Category.
  333. var DefaultCategoryOrder = Desc(category.FieldID)
  334. func newCategoryPager(opts []CategoryPaginateOption) (*CategoryPager, error) {
  335. pager := &CategoryPager{}
  336. for _, opt := range opts {
  337. opt(pager)
  338. }
  339. if pager.Order == nil {
  340. pager.Order = DefaultCategoryOrder
  341. }
  342. return pager, nil
  343. }
  344. func (p *CategoryPager) ApplyFilter(query *CategoryQuery) (*CategoryQuery, error) {
  345. if p.Filter != nil {
  346. return p.Filter(query)
  347. }
  348. return query, nil
  349. }
  350. // CategoryPageList is Category PageList result.
  351. type CategoryPageList struct {
  352. List []*Category `json:"list"`
  353. PageDetails *PageDetails `json:"pageDetails"`
  354. }
  355. func (c *CategoryQuery) Page(
  356. ctx context.Context, pageNum uint64, pageSize uint64, opts ...CategoryPaginateOption,
  357. ) (*CategoryPageList, error) {
  358. pager, err := newCategoryPager(opts)
  359. if err != nil {
  360. return nil, err
  361. }
  362. if c, err = pager.ApplyFilter(c); err != nil {
  363. return nil, err
  364. }
  365. ret := &CategoryPageList{}
  366. ret.PageDetails = &PageDetails{
  367. Page: pageNum,
  368. Size: pageSize,
  369. }
  370. query := c.Clone()
  371. query.ctx.Fields = nil
  372. count, err := query.Count(ctx)
  373. if err != nil {
  374. return nil, err
  375. }
  376. ret.PageDetails.Total = uint64(count)
  377. if pager.Order != nil {
  378. c = c.Order(pager.Order)
  379. } else {
  380. c = c.Order(DefaultCategoryOrder)
  381. }
  382. c = c.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  383. list, err := c.All(ctx)
  384. if err != nil {
  385. return nil, err
  386. }
  387. ret.List = list
  388. return ret, nil
  389. }
  390. type ChatRecordsPager struct {
  391. Order chatrecords.OrderOption
  392. Filter func(*ChatRecordsQuery) (*ChatRecordsQuery, error)
  393. }
  394. // ChatRecordsPaginateOption enables pagination customization.
  395. type ChatRecordsPaginateOption func(*ChatRecordsPager)
  396. // DefaultChatRecordsOrder is the default ordering of ChatRecords.
  397. var DefaultChatRecordsOrder = Desc(chatrecords.FieldID)
  398. func newChatRecordsPager(opts []ChatRecordsPaginateOption) (*ChatRecordsPager, error) {
  399. pager := &ChatRecordsPager{}
  400. for _, opt := range opts {
  401. opt(pager)
  402. }
  403. if pager.Order == nil {
  404. pager.Order = DefaultChatRecordsOrder
  405. }
  406. return pager, nil
  407. }
  408. func (p *ChatRecordsPager) ApplyFilter(query *ChatRecordsQuery) (*ChatRecordsQuery, error) {
  409. if p.Filter != nil {
  410. return p.Filter(query)
  411. }
  412. return query, nil
  413. }
  414. // ChatRecordsPageList is ChatRecords PageList result.
  415. type ChatRecordsPageList struct {
  416. List []*ChatRecords `json:"list"`
  417. PageDetails *PageDetails `json:"pageDetails"`
  418. }
  419. func (cr *ChatRecordsQuery) Page(
  420. ctx context.Context, pageNum uint64, pageSize uint64, opts ...ChatRecordsPaginateOption,
  421. ) (*ChatRecordsPageList, error) {
  422. pager, err := newChatRecordsPager(opts)
  423. if err != nil {
  424. return nil, err
  425. }
  426. if cr, err = pager.ApplyFilter(cr); err != nil {
  427. return nil, err
  428. }
  429. ret := &ChatRecordsPageList{}
  430. ret.PageDetails = &PageDetails{
  431. Page: pageNum,
  432. Size: pageSize,
  433. }
  434. query := cr.Clone()
  435. query.ctx.Fields = nil
  436. count, err := query.Count(ctx)
  437. if err != nil {
  438. return nil, err
  439. }
  440. ret.PageDetails.Total = uint64(count)
  441. if pager.Order != nil {
  442. cr = cr.Order(pager.Order)
  443. } else {
  444. cr = cr.Order(DefaultChatRecordsOrder)
  445. }
  446. cr = cr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  447. list, err := cr.All(ctx)
  448. if err != nil {
  449. return nil, err
  450. }
  451. ret.List = list
  452. return ret, nil
  453. }
  454. type ChatSessionPager struct {
  455. Order chatsession.OrderOption
  456. Filter func(*ChatSessionQuery) (*ChatSessionQuery, error)
  457. }
  458. // ChatSessionPaginateOption enables pagination customization.
  459. type ChatSessionPaginateOption func(*ChatSessionPager)
  460. // DefaultChatSessionOrder is the default ordering of ChatSession.
  461. var DefaultChatSessionOrder = Desc(chatsession.FieldID)
  462. func newChatSessionPager(opts []ChatSessionPaginateOption) (*ChatSessionPager, error) {
  463. pager := &ChatSessionPager{}
  464. for _, opt := range opts {
  465. opt(pager)
  466. }
  467. if pager.Order == nil {
  468. pager.Order = DefaultChatSessionOrder
  469. }
  470. return pager, nil
  471. }
  472. func (p *ChatSessionPager) ApplyFilter(query *ChatSessionQuery) (*ChatSessionQuery, error) {
  473. if p.Filter != nil {
  474. return p.Filter(query)
  475. }
  476. return query, nil
  477. }
  478. // ChatSessionPageList is ChatSession PageList result.
  479. type ChatSessionPageList struct {
  480. List []*ChatSession `json:"list"`
  481. PageDetails *PageDetails `json:"pageDetails"`
  482. }
  483. func (cs *ChatSessionQuery) Page(
  484. ctx context.Context, pageNum uint64, pageSize uint64, opts ...ChatSessionPaginateOption,
  485. ) (*ChatSessionPageList, error) {
  486. pager, err := newChatSessionPager(opts)
  487. if err != nil {
  488. return nil, err
  489. }
  490. if cs, err = pager.ApplyFilter(cs); err != nil {
  491. return nil, err
  492. }
  493. ret := &ChatSessionPageList{}
  494. ret.PageDetails = &PageDetails{
  495. Page: pageNum,
  496. Size: pageSize,
  497. }
  498. query := cs.Clone()
  499. query.ctx.Fields = nil
  500. count, err := query.Count(ctx)
  501. if err != nil {
  502. return nil, err
  503. }
  504. ret.PageDetails.Total = uint64(count)
  505. if pager.Order != nil {
  506. cs = cs.Order(pager.Order)
  507. } else {
  508. cs = cs.Order(DefaultChatSessionOrder)
  509. }
  510. cs = cs.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  511. list, err := cs.All(ctx)
  512. if err != nil {
  513. return nil, err
  514. }
  515. ret.List = list
  516. return ret, nil
  517. }
  518. type ContactPager struct {
  519. Order contact.OrderOption
  520. Filter func(*ContactQuery) (*ContactQuery, error)
  521. }
  522. // ContactPaginateOption enables pagination customization.
  523. type ContactPaginateOption func(*ContactPager)
  524. // DefaultContactOrder is the default ordering of Contact.
  525. var DefaultContactOrder = Desc(contact.FieldID)
  526. func newContactPager(opts []ContactPaginateOption) (*ContactPager, error) {
  527. pager := &ContactPager{}
  528. for _, opt := range opts {
  529. opt(pager)
  530. }
  531. if pager.Order == nil {
  532. pager.Order = DefaultContactOrder
  533. }
  534. return pager, nil
  535. }
  536. func (p *ContactPager) ApplyFilter(query *ContactQuery) (*ContactQuery, error) {
  537. if p.Filter != nil {
  538. return p.Filter(query)
  539. }
  540. return query, nil
  541. }
  542. // ContactPageList is Contact PageList result.
  543. type ContactPageList struct {
  544. List []*Contact `json:"list"`
  545. PageDetails *PageDetails `json:"pageDetails"`
  546. }
  547. func (c *ContactQuery) Page(
  548. ctx context.Context, pageNum uint64, pageSize uint64, opts ...ContactPaginateOption,
  549. ) (*ContactPageList, error) {
  550. pager, err := newContactPager(opts)
  551. if err != nil {
  552. return nil, err
  553. }
  554. if c, err = pager.ApplyFilter(c); err != nil {
  555. return nil, err
  556. }
  557. ret := &ContactPageList{}
  558. ret.PageDetails = &PageDetails{
  559. Page: pageNum,
  560. Size: pageSize,
  561. }
  562. query := c.Clone()
  563. query.ctx.Fields = nil
  564. count, err := query.Count(ctx)
  565. if err != nil {
  566. return nil, err
  567. }
  568. ret.PageDetails.Total = uint64(count)
  569. if pager.Order != nil {
  570. c = c.Order(pager.Order)
  571. } else {
  572. c = c.Order(DefaultContactOrder)
  573. }
  574. c = c.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  575. list, err := c.All(ctx)
  576. if err != nil {
  577. return nil, err
  578. }
  579. ret.List = list
  580. return ret, nil
  581. }
  582. type EmployeePager struct {
  583. Order employee.OrderOption
  584. Filter func(*EmployeeQuery) (*EmployeeQuery, error)
  585. }
  586. // EmployeePaginateOption enables pagination customization.
  587. type EmployeePaginateOption func(*EmployeePager)
  588. // DefaultEmployeeOrder is the default ordering of Employee.
  589. var DefaultEmployeeOrder = Desc(employee.FieldID)
  590. func newEmployeePager(opts []EmployeePaginateOption) (*EmployeePager, error) {
  591. pager := &EmployeePager{}
  592. for _, opt := range opts {
  593. opt(pager)
  594. }
  595. if pager.Order == nil {
  596. pager.Order = DefaultEmployeeOrder
  597. }
  598. return pager, nil
  599. }
  600. func (p *EmployeePager) ApplyFilter(query *EmployeeQuery) (*EmployeeQuery, error) {
  601. if p.Filter != nil {
  602. return p.Filter(query)
  603. }
  604. return query, nil
  605. }
  606. // EmployeePageList is Employee PageList result.
  607. type EmployeePageList struct {
  608. List []*Employee `json:"list"`
  609. PageDetails *PageDetails `json:"pageDetails"`
  610. }
  611. func (e *EmployeeQuery) Page(
  612. ctx context.Context, pageNum uint64, pageSize uint64, opts ...EmployeePaginateOption,
  613. ) (*EmployeePageList, error) {
  614. pager, err := newEmployeePager(opts)
  615. if err != nil {
  616. return nil, err
  617. }
  618. if e, err = pager.ApplyFilter(e); err != nil {
  619. return nil, err
  620. }
  621. ret := &EmployeePageList{}
  622. ret.PageDetails = &PageDetails{
  623. Page: pageNum,
  624. Size: pageSize,
  625. }
  626. query := e.Clone()
  627. query.ctx.Fields = nil
  628. count, err := query.Count(ctx)
  629. if err != nil {
  630. return nil, err
  631. }
  632. ret.PageDetails.Total = uint64(count)
  633. if pager.Order != nil {
  634. e = e.Order(pager.Order)
  635. } else {
  636. e = e.Order(DefaultEmployeeOrder)
  637. }
  638. e = e.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  639. list, err := e.All(ctx)
  640. if err != nil {
  641. return nil, err
  642. }
  643. ret.List = list
  644. return ret, nil
  645. }
  646. type EmployeeConfigPager struct {
  647. Order employeeconfig.OrderOption
  648. Filter func(*EmployeeConfigQuery) (*EmployeeConfigQuery, error)
  649. }
  650. // EmployeeConfigPaginateOption enables pagination customization.
  651. type EmployeeConfigPaginateOption func(*EmployeeConfigPager)
  652. // DefaultEmployeeConfigOrder is the default ordering of EmployeeConfig.
  653. var DefaultEmployeeConfigOrder = Desc(employeeconfig.FieldID)
  654. func newEmployeeConfigPager(opts []EmployeeConfigPaginateOption) (*EmployeeConfigPager, error) {
  655. pager := &EmployeeConfigPager{}
  656. for _, opt := range opts {
  657. opt(pager)
  658. }
  659. if pager.Order == nil {
  660. pager.Order = DefaultEmployeeConfigOrder
  661. }
  662. return pager, nil
  663. }
  664. func (p *EmployeeConfigPager) ApplyFilter(query *EmployeeConfigQuery) (*EmployeeConfigQuery, error) {
  665. if p.Filter != nil {
  666. return p.Filter(query)
  667. }
  668. return query, nil
  669. }
  670. // EmployeeConfigPageList is EmployeeConfig PageList result.
  671. type EmployeeConfigPageList struct {
  672. List []*EmployeeConfig `json:"list"`
  673. PageDetails *PageDetails `json:"pageDetails"`
  674. }
  675. func (ec *EmployeeConfigQuery) Page(
  676. ctx context.Context, pageNum uint64, pageSize uint64, opts ...EmployeeConfigPaginateOption,
  677. ) (*EmployeeConfigPageList, error) {
  678. pager, err := newEmployeeConfigPager(opts)
  679. if err != nil {
  680. return nil, err
  681. }
  682. if ec, err = pager.ApplyFilter(ec); err != nil {
  683. return nil, err
  684. }
  685. ret := &EmployeeConfigPageList{}
  686. ret.PageDetails = &PageDetails{
  687. Page: pageNum,
  688. Size: pageSize,
  689. }
  690. query := ec.Clone()
  691. query.ctx.Fields = nil
  692. count, err := query.Count(ctx)
  693. if err != nil {
  694. return nil, err
  695. }
  696. ret.PageDetails.Total = uint64(count)
  697. if pager.Order != nil {
  698. ec = ec.Order(pager.Order)
  699. } else {
  700. ec = ec.Order(DefaultEmployeeConfigOrder)
  701. }
  702. ec = ec.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  703. list, err := ec.All(ctx)
  704. if err != nil {
  705. return nil, err
  706. }
  707. ret.List = list
  708. return ret, nil
  709. }
  710. type LabelPager struct {
  711. Order label.OrderOption
  712. Filter func(*LabelQuery) (*LabelQuery, error)
  713. }
  714. // LabelPaginateOption enables pagination customization.
  715. type LabelPaginateOption func(*LabelPager)
  716. // DefaultLabelOrder is the default ordering of Label.
  717. var DefaultLabelOrder = Desc(label.FieldID)
  718. func newLabelPager(opts []LabelPaginateOption) (*LabelPager, error) {
  719. pager := &LabelPager{}
  720. for _, opt := range opts {
  721. opt(pager)
  722. }
  723. if pager.Order == nil {
  724. pager.Order = DefaultLabelOrder
  725. }
  726. return pager, nil
  727. }
  728. func (p *LabelPager) ApplyFilter(query *LabelQuery) (*LabelQuery, error) {
  729. if p.Filter != nil {
  730. return p.Filter(query)
  731. }
  732. return query, nil
  733. }
  734. // LabelPageList is Label PageList result.
  735. type LabelPageList struct {
  736. List []*Label `json:"list"`
  737. PageDetails *PageDetails `json:"pageDetails"`
  738. }
  739. func (l *LabelQuery) Page(
  740. ctx context.Context, pageNum uint64, pageSize uint64, opts ...LabelPaginateOption,
  741. ) (*LabelPageList, error) {
  742. pager, err := newLabelPager(opts)
  743. if err != nil {
  744. return nil, err
  745. }
  746. if l, err = pager.ApplyFilter(l); err != nil {
  747. return nil, err
  748. }
  749. ret := &LabelPageList{}
  750. ret.PageDetails = &PageDetails{
  751. Page: pageNum,
  752. Size: pageSize,
  753. }
  754. query := l.Clone()
  755. query.ctx.Fields = nil
  756. count, err := query.Count(ctx)
  757. if err != nil {
  758. return nil, err
  759. }
  760. ret.PageDetails.Total = uint64(count)
  761. if pager.Order != nil {
  762. l = l.Order(pager.Order)
  763. } else {
  764. l = l.Order(DefaultLabelOrder)
  765. }
  766. l = l.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  767. list, err := l.All(ctx)
  768. if err != nil {
  769. return nil, err
  770. }
  771. ret.List = list
  772. return ret, nil
  773. }
  774. type LabelRelationshipPager struct {
  775. Order labelrelationship.OrderOption
  776. Filter func(*LabelRelationshipQuery) (*LabelRelationshipQuery, error)
  777. }
  778. // LabelRelationshipPaginateOption enables pagination customization.
  779. type LabelRelationshipPaginateOption func(*LabelRelationshipPager)
  780. // DefaultLabelRelationshipOrder is the default ordering of LabelRelationship.
  781. var DefaultLabelRelationshipOrder = Desc(labelrelationship.FieldID)
  782. func newLabelRelationshipPager(opts []LabelRelationshipPaginateOption) (*LabelRelationshipPager, error) {
  783. pager := &LabelRelationshipPager{}
  784. for _, opt := range opts {
  785. opt(pager)
  786. }
  787. if pager.Order == nil {
  788. pager.Order = DefaultLabelRelationshipOrder
  789. }
  790. return pager, nil
  791. }
  792. func (p *LabelRelationshipPager) ApplyFilter(query *LabelRelationshipQuery) (*LabelRelationshipQuery, error) {
  793. if p.Filter != nil {
  794. return p.Filter(query)
  795. }
  796. return query, nil
  797. }
  798. // LabelRelationshipPageList is LabelRelationship PageList result.
  799. type LabelRelationshipPageList struct {
  800. List []*LabelRelationship `json:"list"`
  801. PageDetails *PageDetails `json:"pageDetails"`
  802. }
  803. func (lr *LabelRelationshipQuery) Page(
  804. ctx context.Context, pageNum uint64, pageSize uint64, opts ...LabelRelationshipPaginateOption,
  805. ) (*LabelRelationshipPageList, error) {
  806. pager, err := newLabelRelationshipPager(opts)
  807. if err != nil {
  808. return nil, err
  809. }
  810. if lr, err = pager.ApplyFilter(lr); err != nil {
  811. return nil, err
  812. }
  813. ret := &LabelRelationshipPageList{}
  814. ret.PageDetails = &PageDetails{
  815. Page: pageNum,
  816. Size: pageSize,
  817. }
  818. query := lr.Clone()
  819. query.ctx.Fields = nil
  820. count, err := query.Count(ctx)
  821. if err != nil {
  822. return nil, err
  823. }
  824. ret.PageDetails.Total = uint64(count)
  825. if pager.Order != nil {
  826. lr = lr.Order(pager.Order)
  827. } else {
  828. lr = lr.Order(DefaultLabelRelationshipOrder)
  829. }
  830. lr = lr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  831. list, err := lr.All(ctx)
  832. if err != nil {
  833. return nil, err
  834. }
  835. ret.List = list
  836. return ret, nil
  837. }
  838. type MessagePager struct {
  839. Order message.OrderOption
  840. Filter func(*MessageQuery) (*MessageQuery, error)
  841. }
  842. // MessagePaginateOption enables pagination customization.
  843. type MessagePaginateOption func(*MessagePager)
  844. // DefaultMessageOrder is the default ordering of Message.
  845. var DefaultMessageOrder = Desc(message.FieldID)
  846. func newMessagePager(opts []MessagePaginateOption) (*MessagePager, error) {
  847. pager := &MessagePager{}
  848. for _, opt := range opts {
  849. opt(pager)
  850. }
  851. if pager.Order == nil {
  852. pager.Order = DefaultMessageOrder
  853. }
  854. return pager, nil
  855. }
  856. func (p *MessagePager) ApplyFilter(query *MessageQuery) (*MessageQuery, error) {
  857. if p.Filter != nil {
  858. return p.Filter(query)
  859. }
  860. return query, nil
  861. }
  862. // MessagePageList is Message PageList result.
  863. type MessagePageList struct {
  864. List []*Message `json:"list"`
  865. PageDetails *PageDetails `json:"pageDetails"`
  866. }
  867. func (m *MessageQuery) Page(
  868. ctx context.Context, pageNum uint64, pageSize uint64, opts ...MessagePaginateOption,
  869. ) (*MessagePageList, error) {
  870. pager, err := newMessagePager(opts)
  871. if err != nil {
  872. return nil, err
  873. }
  874. if m, err = pager.ApplyFilter(m); err != nil {
  875. return nil, err
  876. }
  877. ret := &MessagePageList{}
  878. ret.PageDetails = &PageDetails{
  879. Page: pageNum,
  880. Size: pageSize,
  881. }
  882. query := m.Clone()
  883. query.ctx.Fields = nil
  884. count, err := query.Count(ctx)
  885. if err != nil {
  886. return nil, err
  887. }
  888. ret.PageDetails.Total = uint64(count)
  889. if pager.Order != nil {
  890. m = m.Order(pager.Order)
  891. } else {
  892. m = m.Order(DefaultMessageOrder)
  893. }
  894. m = m.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  895. list, err := m.All(ctx)
  896. if err != nil {
  897. return nil, err
  898. }
  899. ret.List = list
  900. return ret, nil
  901. }
  902. type MessageRecordsPager struct {
  903. Order messagerecords.OrderOption
  904. Filter func(*MessageRecordsQuery) (*MessageRecordsQuery, error)
  905. }
  906. // MessageRecordsPaginateOption enables pagination customization.
  907. type MessageRecordsPaginateOption func(*MessageRecordsPager)
  908. // DefaultMessageRecordsOrder is the default ordering of MessageRecords.
  909. var DefaultMessageRecordsOrder = Desc(messagerecords.FieldID)
  910. func newMessageRecordsPager(opts []MessageRecordsPaginateOption) (*MessageRecordsPager, error) {
  911. pager := &MessageRecordsPager{}
  912. for _, opt := range opts {
  913. opt(pager)
  914. }
  915. if pager.Order == nil {
  916. pager.Order = DefaultMessageRecordsOrder
  917. }
  918. return pager, nil
  919. }
  920. func (p *MessageRecordsPager) ApplyFilter(query *MessageRecordsQuery) (*MessageRecordsQuery, error) {
  921. if p.Filter != nil {
  922. return p.Filter(query)
  923. }
  924. return query, nil
  925. }
  926. // MessageRecordsPageList is MessageRecords PageList result.
  927. type MessageRecordsPageList struct {
  928. List []*MessageRecords `json:"list"`
  929. PageDetails *PageDetails `json:"pageDetails"`
  930. }
  931. func (mr *MessageRecordsQuery) Page(
  932. ctx context.Context, pageNum uint64, pageSize uint64, opts ...MessageRecordsPaginateOption,
  933. ) (*MessageRecordsPageList, error) {
  934. pager, err := newMessageRecordsPager(opts)
  935. if err != nil {
  936. return nil, err
  937. }
  938. if mr, err = pager.ApplyFilter(mr); err != nil {
  939. return nil, err
  940. }
  941. ret := &MessageRecordsPageList{}
  942. ret.PageDetails = &PageDetails{
  943. Page: pageNum,
  944. Size: pageSize,
  945. }
  946. query := mr.Clone()
  947. query.ctx.Fields = nil
  948. count, err := query.Count(ctx)
  949. if err != nil {
  950. return nil, err
  951. }
  952. ret.PageDetails.Total = uint64(count)
  953. if pager.Order != nil {
  954. mr = mr.Order(pager.Order)
  955. } else {
  956. mr = mr.Order(DefaultMessageRecordsOrder)
  957. }
  958. mr = mr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  959. list, err := mr.All(ctx)
  960. if err != nil {
  961. return nil, err
  962. }
  963. ret.List = list
  964. return ret, nil
  965. }
  966. type MsgPager struct {
  967. Order msg.OrderOption
  968. Filter func(*MsgQuery) (*MsgQuery, error)
  969. }
  970. // MsgPaginateOption enables pagination customization.
  971. type MsgPaginateOption func(*MsgPager)
  972. // DefaultMsgOrder is the default ordering of Msg.
  973. var DefaultMsgOrder = Desc(msg.FieldID)
  974. func newMsgPager(opts []MsgPaginateOption) (*MsgPager, error) {
  975. pager := &MsgPager{}
  976. for _, opt := range opts {
  977. opt(pager)
  978. }
  979. if pager.Order == nil {
  980. pager.Order = DefaultMsgOrder
  981. }
  982. return pager, nil
  983. }
  984. func (p *MsgPager) ApplyFilter(query *MsgQuery) (*MsgQuery, error) {
  985. if p.Filter != nil {
  986. return p.Filter(query)
  987. }
  988. return query, nil
  989. }
  990. // MsgPageList is Msg PageList result.
  991. type MsgPageList struct {
  992. List []*Msg `json:"list"`
  993. PageDetails *PageDetails `json:"pageDetails"`
  994. }
  995. func (m *MsgQuery) Page(
  996. ctx context.Context, pageNum uint64, pageSize uint64, opts ...MsgPaginateOption,
  997. ) (*MsgPageList, error) {
  998. pager, err := newMsgPager(opts)
  999. if err != nil {
  1000. return nil, err
  1001. }
  1002. if m, err = pager.ApplyFilter(m); err != nil {
  1003. return nil, err
  1004. }
  1005. ret := &MsgPageList{}
  1006. ret.PageDetails = &PageDetails{
  1007. Page: pageNum,
  1008. Size: pageSize,
  1009. }
  1010. query := m.Clone()
  1011. query.ctx.Fields = nil
  1012. count, err := query.Count(ctx)
  1013. if err != nil {
  1014. return nil, err
  1015. }
  1016. ret.PageDetails.Total = uint64(count)
  1017. if pager.Order != nil {
  1018. m = m.Order(pager.Order)
  1019. } else {
  1020. m = m.Order(DefaultMsgOrder)
  1021. }
  1022. m = m.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1023. list, err := m.All(ctx)
  1024. if err != nil {
  1025. return nil, err
  1026. }
  1027. ret.List = list
  1028. return ret, nil
  1029. }
  1030. type ServerPager struct {
  1031. Order server.OrderOption
  1032. Filter func(*ServerQuery) (*ServerQuery, error)
  1033. }
  1034. // ServerPaginateOption enables pagination customization.
  1035. type ServerPaginateOption func(*ServerPager)
  1036. // DefaultServerOrder is the default ordering of Server.
  1037. var DefaultServerOrder = Desc(server.FieldID)
  1038. func newServerPager(opts []ServerPaginateOption) (*ServerPager, error) {
  1039. pager := &ServerPager{}
  1040. for _, opt := range opts {
  1041. opt(pager)
  1042. }
  1043. if pager.Order == nil {
  1044. pager.Order = DefaultServerOrder
  1045. }
  1046. return pager, nil
  1047. }
  1048. func (p *ServerPager) ApplyFilter(query *ServerQuery) (*ServerQuery, error) {
  1049. if p.Filter != nil {
  1050. return p.Filter(query)
  1051. }
  1052. return query, nil
  1053. }
  1054. // ServerPageList is Server PageList result.
  1055. type ServerPageList struct {
  1056. List []*Server `json:"list"`
  1057. PageDetails *PageDetails `json:"pageDetails"`
  1058. }
  1059. func (s *ServerQuery) Page(
  1060. ctx context.Context, pageNum uint64, pageSize uint64, opts ...ServerPaginateOption,
  1061. ) (*ServerPageList, error) {
  1062. pager, err := newServerPager(opts)
  1063. if err != nil {
  1064. return nil, err
  1065. }
  1066. if s, err = pager.ApplyFilter(s); err != nil {
  1067. return nil, err
  1068. }
  1069. ret := &ServerPageList{}
  1070. ret.PageDetails = &PageDetails{
  1071. Page: pageNum,
  1072. Size: pageSize,
  1073. }
  1074. query := s.Clone()
  1075. query.ctx.Fields = nil
  1076. count, err := query.Count(ctx)
  1077. if err != nil {
  1078. return nil, err
  1079. }
  1080. ret.PageDetails.Total = uint64(count)
  1081. if pager.Order != nil {
  1082. s = s.Order(pager.Order)
  1083. } else {
  1084. s = s.Order(DefaultServerOrder)
  1085. }
  1086. s = s.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1087. list, err := s.All(ctx)
  1088. if err != nil {
  1089. return nil, err
  1090. }
  1091. ret.List = list
  1092. return ret, nil
  1093. }
  1094. type SopNodePager struct {
  1095. Order sopnode.OrderOption
  1096. Filter func(*SopNodeQuery) (*SopNodeQuery, error)
  1097. }
  1098. // SopNodePaginateOption enables pagination customization.
  1099. type SopNodePaginateOption func(*SopNodePager)
  1100. // DefaultSopNodeOrder is the default ordering of SopNode.
  1101. var DefaultSopNodeOrder = Desc(sopnode.FieldID)
  1102. func newSopNodePager(opts []SopNodePaginateOption) (*SopNodePager, error) {
  1103. pager := &SopNodePager{}
  1104. for _, opt := range opts {
  1105. opt(pager)
  1106. }
  1107. if pager.Order == nil {
  1108. pager.Order = DefaultSopNodeOrder
  1109. }
  1110. return pager, nil
  1111. }
  1112. func (p *SopNodePager) ApplyFilter(query *SopNodeQuery) (*SopNodeQuery, error) {
  1113. if p.Filter != nil {
  1114. return p.Filter(query)
  1115. }
  1116. return query, nil
  1117. }
  1118. // SopNodePageList is SopNode PageList result.
  1119. type SopNodePageList struct {
  1120. List []*SopNode `json:"list"`
  1121. PageDetails *PageDetails `json:"pageDetails"`
  1122. }
  1123. func (sn *SopNodeQuery) Page(
  1124. ctx context.Context, pageNum uint64, pageSize uint64, opts ...SopNodePaginateOption,
  1125. ) (*SopNodePageList, error) {
  1126. pager, err := newSopNodePager(opts)
  1127. if err != nil {
  1128. return nil, err
  1129. }
  1130. if sn, err = pager.ApplyFilter(sn); err != nil {
  1131. return nil, err
  1132. }
  1133. ret := &SopNodePageList{}
  1134. ret.PageDetails = &PageDetails{
  1135. Page: pageNum,
  1136. Size: pageSize,
  1137. }
  1138. query := sn.Clone()
  1139. query.ctx.Fields = nil
  1140. count, err := query.Count(ctx)
  1141. if err != nil {
  1142. return nil, err
  1143. }
  1144. ret.PageDetails.Total = uint64(count)
  1145. if pager.Order != nil {
  1146. sn = sn.Order(pager.Order)
  1147. } else {
  1148. sn = sn.Order(DefaultSopNodeOrder)
  1149. }
  1150. sn = sn.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1151. list, err := sn.All(ctx)
  1152. if err != nil {
  1153. return nil, err
  1154. }
  1155. ret.List = list
  1156. return ret, nil
  1157. }
  1158. type SopStagePager struct {
  1159. Order sopstage.OrderOption
  1160. Filter func(*SopStageQuery) (*SopStageQuery, error)
  1161. }
  1162. // SopStagePaginateOption enables pagination customization.
  1163. type SopStagePaginateOption func(*SopStagePager)
  1164. // DefaultSopStageOrder is the default ordering of SopStage.
  1165. var DefaultSopStageOrder = Desc(sopstage.FieldID)
  1166. func newSopStagePager(opts []SopStagePaginateOption) (*SopStagePager, error) {
  1167. pager := &SopStagePager{}
  1168. for _, opt := range opts {
  1169. opt(pager)
  1170. }
  1171. if pager.Order == nil {
  1172. pager.Order = DefaultSopStageOrder
  1173. }
  1174. return pager, nil
  1175. }
  1176. func (p *SopStagePager) ApplyFilter(query *SopStageQuery) (*SopStageQuery, error) {
  1177. if p.Filter != nil {
  1178. return p.Filter(query)
  1179. }
  1180. return query, nil
  1181. }
  1182. // SopStagePageList is SopStage PageList result.
  1183. type SopStagePageList struct {
  1184. List []*SopStage `json:"list"`
  1185. PageDetails *PageDetails `json:"pageDetails"`
  1186. }
  1187. func (ss *SopStageQuery) Page(
  1188. ctx context.Context, pageNum uint64, pageSize uint64, opts ...SopStagePaginateOption,
  1189. ) (*SopStagePageList, error) {
  1190. pager, err := newSopStagePager(opts)
  1191. if err != nil {
  1192. return nil, err
  1193. }
  1194. if ss, err = pager.ApplyFilter(ss); err != nil {
  1195. return nil, err
  1196. }
  1197. ret := &SopStagePageList{}
  1198. ret.PageDetails = &PageDetails{
  1199. Page: pageNum,
  1200. Size: pageSize,
  1201. }
  1202. query := ss.Clone()
  1203. query.ctx.Fields = nil
  1204. count, err := query.Count(ctx)
  1205. if err != nil {
  1206. return nil, err
  1207. }
  1208. ret.PageDetails.Total = uint64(count)
  1209. if pager.Order != nil {
  1210. ss = ss.Order(pager.Order)
  1211. } else {
  1212. ss = ss.Order(DefaultSopStageOrder)
  1213. }
  1214. ss = ss.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1215. list, err := ss.All(ctx)
  1216. if err != nil {
  1217. return nil, err
  1218. }
  1219. ret.List = list
  1220. return ret, nil
  1221. }
  1222. type SopTaskPager struct {
  1223. Order soptask.OrderOption
  1224. Filter func(*SopTaskQuery) (*SopTaskQuery, error)
  1225. }
  1226. // SopTaskPaginateOption enables pagination customization.
  1227. type SopTaskPaginateOption func(*SopTaskPager)
  1228. // DefaultSopTaskOrder is the default ordering of SopTask.
  1229. var DefaultSopTaskOrder = Desc(soptask.FieldID)
  1230. func newSopTaskPager(opts []SopTaskPaginateOption) (*SopTaskPager, error) {
  1231. pager := &SopTaskPager{}
  1232. for _, opt := range opts {
  1233. opt(pager)
  1234. }
  1235. if pager.Order == nil {
  1236. pager.Order = DefaultSopTaskOrder
  1237. }
  1238. return pager, nil
  1239. }
  1240. func (p *SopTaskPager) ApplyFilter(query *SopTaskQuery) (*SopTaskQuery, error) {
  1241. if p.Filter != nil {
  1242. return p.Filter(query)
  1243. }
  1244. return query, nil
  1245. }
  1246. // SopTaskPageList is SopTask PageList result.
  1247. type SopTaskPageList struct {
  1248. List []*SopTask `json:"list"`
  1249. PageDetails *PageDetails `json:"pageDetails"`
  1250. }
  1251. func (st *SopTaskQuery) Page(
  1252. ctx context.Context, pageNum uint64, pageSize uint64, opts ...SopTaskPaginateOption,
  1253. ) (*SopTaskPageList, error) {
  1254. pager, err := newSopTaskPager(opts)
  1255. if err != nil {
  1256. return nil, err
  1257. }
  1258. if st, err = pager.ApplyFilter(st); err != nil {
  1259. return nil, err
  1260. }
  1261. ret := &SopTaskPageList{}
  1262. ret.PageDetails = &PageDetails{
  1263. Page: pageNum,
  1264. Size: pageSize,
  1265. }
  1266. query := st.Clone()
  1267. query.ctx.Fields = nil
  1268. count, err := query.Count(ctx)
  1269. if err != nil {
  1270. return nil, err
  1271. }
  1272. ret.PageDetails.Total = uint64(count)
  1273. if pager.Order != nil {
  1274. st = st.Order(pager.Order)
  1275. } else {
  1276. st = st.Order(DefaultSopTaskOrder)
  1277. }
  1278. st = st.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1279. list, err := st.All(ctx)
  1280. if err != nil {
  1281. return nil, err
  1282. }
  1283. ret.List = list
  1284. return ret, nil
  1285. }
  1286. type TokenPager struct {
  1287. Order token.OrderOption
  1288. Filter func(*TokenQuery) (*TokenQuery, error)
  1289. }
  1290. // TokenPaginateOption enables pagination customization.
  1291. type TokenPaginateOption func(*TokenPager)
  1292. // DefaultTokenOrder is the default ordering of Token.
  1293. var DefaultTokenOrder = Desc(token.FieldID)
  1294. func newTokenPager(opts []TokenPaginateOption) (*TokenPager, error) {
  1295. pager := &TokenPager{}
  1296. for _, opt := range opts {
  1297. opt(pager)
  1298. }
  1299. if pager.Order == nil {
  1300. pager.Order = DefaultTokenOrder
  1301. }
  1302. return pager, nil
  1303. }
  1304. func (p *TokenPager) ApplyFilter(query *TokenQuery) (*TokenQuery, error) {
  1305. if p.Filter != nil {
  1306. return p.Filter(query)
  1307. }
  1308. return query, nil
  1309. }
  1310. // TokenPageList is Token PageList result.
  1311. type TokenPageList struct {
  1312. List []*Token `json:"list"`
  1313. PageDetails *PageDetails `json:"pageDetails"`
  1314. }
  1315. func (t *TokenQuery) Page(
  1316. ctx context.Context, pageNum uint64, pageSize uint64, opts ...TokenPaginateOption,
  1317. ) (*TokenPageList, error) {
  1318. pager, err := newTokenPager(opts)
  1319. if err != nil {
  1320. return nil, err
  1321. }
  1322. if t, err = pager.ApplyFilter(t); err != nil {
  1323. return nil, err
  1324. }
  1325. ret := &TokenPageList{}
  1326. ret.PageDetails = &PageDetails{
  1327. Page: pageNum,
  1328. Size: pageSize,
  1329. }
  1330. query := t.Clone()
  1331. query.ctx.Fields = nil
  1332. count, err := query.Count(ctx)
  1333. if err != nil {
  1334. return nil, err
  1335. }
  1336. ret.PageDetails.Total = uint64(count)
  1337. if pager.Order != nil {
  1338. t = t.Order(pager.Order)
  1339. } else {
  1340. t = t.Order(DefaultTokenOrder)
  1341. }
  1342. t = t.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1343. list, err := t.All(ctx)
  1344. if err != nil {
  1345. return nil, err
  1346. }
  1347. ret.List = list
  1348. return ret, nil
  1349. }
  1350. type TutorialPager struct {
  1351. Order tutorial.OrderOption
  1352. Filter func(*TutorialQuery) (*TutorialQuery, error)
  1353. }
  1354. // TutorialPaginateOption enables pagination customization.
  1355. type TutorialPaginateOption func(*TutorialPager)
  1356. // DefaultTutorialOrder is the default ordering of Tutorial.
  1357. var DefaultTutorialOrder = Desc(tutorial.FieldID)
  1358. func newTutorialPager(opts []TutorialPaginateOption) (*TutorialPager, error) {
  1359. pager := &TutorialPager{}
  1360. for _, opt := range opts {
  1361. opt(pager)
  1362. }
  1363. if pager.Order == nil {
  1364. pager.Order = DefaultTutorialOrder
  1365. }
  1366. return pager, nil
  1367. }
  1368. func (p *TutorialPager) ApplyFilter(query *TutorialQuery) (*TutorialQuery, error) {
  1369. if p.Filter != nil {
  1370. return p.Filter(query)
  1371. }
  1372. return query, nil
  1373. }
  1374. // TutorialPageList is Tutorial PageList result.
  1375. type TutorialPageList struct {
  1376. List []*Tutorial `json:"list"`
  1377. PageDetails *PageDetails `json:"pageDetails"`
  1378. }
  1379. func (t *TutorialQuery) Page(
  1380. ctx context.Context, pageNum uint64, pageSize uint64, opts ...TutorialPaginateOption,
  1381. ) (*TutorialPageList, error) {
  1382. pager, err := newTutorialPager(opts)
  1383. if err != nil {
  1384. return nil, err
  1385. }
  1386. if t, err = pager.ApplyFilter(t); err != nil {
  1387. return nil, err
  1388. }
  1389. ret := &TutorialPageList{}
  1390. ret.PageDetails = &PageDetails{
  1391. Page: pageNum,
  1392. Size: pageSize,
  1393. }
  1394. query := t.Clone()
  1395. query.ctx.Fields = nil
  1396. count, err := query.Count(ctx)
  1397. if err != nil {
  1398. return nil, err
  1399. }
  1400. ret.PageDetails.Total = uint64(count)
  1401. if pager.Order != nil {
  1402. t = t.Order(pager.Order)
  1403. } else {
  1404. t = t.Order(DefaultTutorialOrder)
  1405. }
  1406. t = t.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1407. list, err := t.All(ctx)
  1408. if err != nil {
  1409. return nil, err
  1410. }
  1411. ret.List = list
  1412. return ret, nil
  1413. }
  1414. type WorkExperiencePager struct {
  1415. Order workexperience.OrderOption
  1416. Filter func(*WorkExperienceQuery) (*WorkExperienceQuery, error)
  1417. }
  1418. // WorkExperiencePaginateOption enables pagination customization.
  1419. type WorkExperiencePaginateOption func(*WorkExperiencePager)
  1420. // DefaultWorkExperienceOrder is the default ordering of WorkExperience.
  1421. var DefaultWorkExperienceOrder = Desc(workexperience.FieldID)
  1422. func newWorkExperiencePager(opts []WorkExperiencePaginateOption) (*WorkExperiencePager, error) {
  1423. pager := &WorkExperiencePager{}
  1424. for _, opt := range opts {
  1425. opt(pager)
  1426. }
  1427. if pager.Order == nil {
  1428. pager.Order = DefaultWorkExperienceOrder
  1429. }
  1430. return pager, nil
  1431. }
  1432. func (p *WorkExperiencePager) ApplyFilter(query *WorkExperienceQuery) (*WorkExperienceQuery, error) {
  1433. if p.Filter != nil {
  1434. return p.Filter(query)
  1435. }
  1436. return query, nil
  1437. }
  1438. // WorkExperiencePageList is WorkExperience PageList result.
  1439. type WorkExperiencePageList struct {
  1440. List []*WorkExperience `json:"list"`
  1441. PageDetails *PageDetails `json:"pageDetails"`
  1442. }
  1443. func (we *WorkExperienceQuery) Page(
  1444. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WorkExperiencePaginateOption,
  1445. ) (*WorkExperiencePageList, error) {
  1446. pager, err := newWorkExperiencePager(opts)
  1447. if err != nil {
  1448. return nil, err
  1449. }
  1450. if we, err = pager.ApplyFilter(we); err != nil {
  1451. return nil, err
  1452. }
  1453. ret := &WorkExperiencePageList{}
  1454. ret.PageDetails = &PageDetails{
  1455. Page: pageNum,
  1456. Size: pageSize,
  1457. }
  1458. query := we.Clone()
  1459. query.ctx.Fields = nil
  1460. count, err := query.Count(ctx)
  1461. if err != nil {
  1462. return nil, err
  1463. }
  1464. ret.PageDetails.Total = uint64(count)
  1465. if pager.Order != nil {
  1466. we = we.Order(pager.Order)
  1467. } else {
  1468. we = we.Order(DefaultWorkExperienceOrder)
  1469. }
  1470. we = we.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1471. list, err := we.All(ctx)
  1472. if err != nil {
  1473. return nil, err
  1474. }
  1475. ret.List = list
  1476. return ret, nil
  1477. }
  1478. type WxPager struct {
  1479. Order wx.OrderOption
  1480. Filter func(*WxQuery) (*WxQuery, error)
  1481. }
  1482. // WxPaginateOption enables pagination customization.
  1483. type WxPaginateOption func(*WxPager)
  1484. // DefaultWxOrder is the default ordering of Wx.
  1485. var DefaultWxOrder = Desc(wx.FieldID)
  1486. func newWxPager(opts []WxPaginateOption) (*WxPager, error) {
  1487. pager := &WxPager{}
  1488. for _, opt := range opts {
  1489. opt(pager)
  1490. }
  1491. if pager.Order == nil {
  1492. pager.Order = DefaultWxOrder
  1493. }
  1494. return pager, nil
  1495. }
  1496. func (p *WxPager) ApplyFilter(query *WxQuery) (*WxQuery, error) {
  1497. if p.Filter != nil {
  1498. return p.Filter(query)
  1499. }
  1500. return query, nil
  1501. }
  1502. // WxPageList is Wx PageList result.
  1503. type WxPageList struct {
  1504. List []*Wx `json:"list"`
  1505. PageDetails *PageDetails `json:"pageDetails"`
  1506. }
  1507. func (w *WxQuery) Page(
  1508. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxPaginateOption,
  1509. ) (*WxPageList, error) {
  1510. pager, err := newWxPager(opts)
  1511. if err != nil {
  1512. return nil, err
  1513. }
  1514. if w, err = pager.ApplyFilter(w); err != nil {
  1515. return nil, err
  1516. }
  1517. ret := &WxPageList{}
  1518. ret.PageDetails = &PageDetails{
  1519. Page: pageNum,
  1520. Size: pageSize,
  1521. }
  1522. query := w.Clone()
  1523. query.ctx.Fields = nil
  1524. count, err := query.Count(ctx)
  1525. if err != nil {
  1526. return nil, err
  1527. }
  1528. ret.PageDetails.Total = uint64(count)
  1529. if pager.Order != nil {
  1530. w = w.Order(pager.Order)
  1531. } else {
  1532. w = w.Order(DefaultWxOrder)
  1533. }
  1534. w = w.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1535. list, err := w.All(ctx)
  1536. if err != nil {
  1537. return nil, err
  1538. }
  1539. ret.List = list
  1540. return ret, nil
  1541. }
  1542. type WxCardPager struct {
  1543. Order wxcard.OrderOption
  1544. Filter func(*WxCardQuery) (*WxCardQuery, error)
  1545. }
  1546. // WxCardPaginateOption enables pagination customization.
  1547. type WxCardPaginateOption func(*WxCardPager)
  1548. // DefaultWxCardOrder is the default ordering of WxCard.
  1549. var DefaultWxCardOrder = Desc(wxcard.FieldID)
  1550. func newWxCardPager(opts []WxCardPaginateOption) (*WxCardPager, error) {
  1551. pager := &WxCardPager{}
  1552. for _, opt := range opts {
  1553. opt(pager)
  1554. }
  1555. if pager.Order == nil {
  1556. pager.Order = DefaultWxCardOrder
  1557. }
  1558. return pager, nil
  1559. }
  1560. func (p *WxCardPager) ApplyFilter(query *WxCardQuery) (*WxCardQuery, error) {
  1561. if p.Filter != nil {
  1562. return p.Filter(query)
  1563. }
  1564. return query, nil
  1565. }
  1566. // WxCardPageList is WxCard PageList result.
  1567. type WxCardPageList struct {
  1568. List []*WxCard `json:"list"`
  1569. PageDetails *PageDetails `json:"pageDetails"`
  1570. }
  1571. func (wc *WxCardQuery) Page(
  1572. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxCardPaginateOption,
  1573. ) (*WxCardPageList, error) {
  1574. pager, err := newWxCardPager(opts)
  1575. if err != nil {
  1576. return nil, err
  1577. }
  1578. if wc, err = pager.ApplyFilter(wc); err != nil {
  1579. return nil, err
  1580. }
  1581. ret := &WxCardPageList{}
  1582. ret.PageDetails = &PageDetails{
  1583. Page: pageNum,
  1584. Size: pageSize,
  1585. }
  1586. query := wc.Clone()
  1587. query.ctx.Fields = nil
  1588. count, err := query.Count(ctx)
  1589. if err != nil {
  1590. return nil, err
  1591. }
  1592. ret.PageDetails.Total = uint64(count)
  1593. if pager.Order != nil {
  1594. wc = wc.Order(pager.Order)
  1595. } else {
  1596. wc = wc.Order(DefaultWxCardOrder)
  1597. }
  1598. wc = wc.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1599. list, err := wc.All(ctx)
  1600. if err != nil {
  1601. return nil, err
  1602. }
  1603. ret.List = list
  1604. return ret, nil
  1605. }
  1606. type WxCardUserPager struct {
  1607. Order wxcarduser.OrderOption
  1608. Filter func(*WxCardUserQuery) (*WxCardUserQuery, error)
  1609. }
  1610. // WxCardUserPaginateOption enables pagination customization.
  1611. type WxCardUserPaginateOption func(*WxCardUserPager)
  1612. // DefaultWxCardUserOrder is the default ordering of WxCardUser.
  1613. var DefaultWxCardUserOrder = Desc(wxcarduser.FieldID)
  1614. func newWxCardUserPager(opts []WxCardUserPaginateOption) (*WxCardUserPager, error) {
  1615. pager := &WxCardUserPager{}
  1616. for _, opt := range opts {
  1617. opt(pager)
  1618. }
  1619. if pager.Order == nil {
  1620. pager.Order = DefaultWxCardUserOrder
  1621. }
  1622. return pager, nil
  1623. }
  1624. func (p *WxCardUserPager) ApplyFilter(query *WxCardUserQuery) (*WxCardUserQuery, error) {
  1625. if p.Filter != nil {
  1626. return p.Filter(query)
  1627. }
  1628. return query, nil
  1629. }
  1630. // WxCardUserPageList is WxCardUser PageList result.
  1631. type WxCardUserPageList struct {
  1632. List []*WxCardUser `json:"list"`
  1633. PageDetails *PageDetails `json:"pageDetails"`
  1634. }
  1635. func (wcu *WxCardUserQuery) Page(
  1636. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxCardUserPaginateOption,
  1637. ) (*WxCardUserPageList, error) {
  1638. pager, err := newWxCardUserPager(opts)
  1639. if err != nil {
  1640. return nil, err
  1641. }
  1642. if wcu, err = pager.ApplyFilter(wcu); err != nil {
  1643. return nil, err
  1644. }
  1645. ret := &WxCardUserPageList{}
  1646. ret.PageDetails = &PageDetails{
  1647. Page: pageNum,
  1648. Size: pageSize,
  1649. }
  1650. query := wcu.Clone()
  1651. query.ctx.Fields = nil
  1652. count, err := query.Count(ctx)
  1653. if err != nil {
  1654. return nil, err
  1655. }
  1656. ret.PageDetails.Total = uint64(count)
  1657. if pager.Order != nil {
  1658. wcu = wcu.Order(pager.Order)
  1659. } else {
  1660. wcu = wcu.Order(DefaultWxCardUserOrder)
  1661. }
  1662. wcu = wcu.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1663. list, err := wcu.All(ctx)
  1664. if err != nil {
  1665. return nil, err
  1666. }
  1667. ret.List = list
  1668. return ret, nil
  1669. }
  1670. type WxCardVisitPager struct {
  1671. Order wxcardvisit.OrderOption
  1672. Filter func(*WxCardVisitQuery) (*WxCardVisitQuery, error)
  1673. }
  1674. // WxCardVisitPaginateOption enables pagination customization.
  1675. type WxCardVisitPaginateOption func(*WxCardVisitPager)
  1676. // DefaultWxCardVisitOrder is the default ordering of WxCardVisit.
  1677. var DefaultWxCardVisitOrder = Desc(wxcardvisit.FieldID)
  1678. func newWxCardVisitPager(opts []WxCardVisitPaginateOption) (*WxCardVisitPager, error) {
  1679. pager := &WxCardVisitPager{}
  1680. for _, opt := range opts {
  1681. opt(pager)
  1682. }
  1683. if pager.Order == nil {
  1684. pager.Order = DefaultWxCardVisitOrder
  1685. }
  1686. return pager, nil
  1687. }
  1688. func (p *WxCardVisitPager) ApplyFilter(query *WxCardVisitQuery) (*WxCardVisitQuery, error) {
  1689. if p.Filter != nil {
  1690. return p.Filter(query)
  1691. }
  1692. return query, nil
  1693. }
  1694. // WxCardVisitPageList is WxCardVisit PageList result.
  1695. type WxCardVisitPageList struct {
  1696. List []*WxCardVisit `json:"list"`
  1697. PageDetails *PageDetails `json:"pageDetails"`
  1698. }
  1699. func (wcv *WxCardVisitQuery) Page(
  1700. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxCardVisitPaginateOption,
  1701. ) (*WxCardVisitPageList, error) {
  1702. pager, err := newWxCardVisitPager(opts)
  1703. if err != nil {
  1704. return nil, err
  1705. }
  1706. if wcv, err = pager.ApplyFilter(wcv); err != nil {
  1707. return nil, err
  1708. }
  1709. ret := &WxCardVisitPageList{}
  1710. ret.PageDetails = &PageDetails{
  1711. Page: pageNum,
  1712. Size: pageSize,
  1713. }
  1714. query := wcv.Clone()
  1715. query.ctx.Fields = nil
  1716. count, err := query.Count(ctx)
  1717. if err != nil {
  1718. return nil, err
  1719. }
  1720. ret.PageDetails.Total = uint64(count)
  1721. if pager.Order != nil {
  1722. wcv = wcv.Order(pager.Order)
  1723. } else {
  1724. wcv = wcv.Order(DefaultWxCardVisitOrder)
  1725. }
  1726. wcv = wcv.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1727. list, err := wcv.All(ctx)
  1728. if err != nil {
  1729. return nil, err
  1730. }
  1731. ret.List = list
  1732. return ret, nil
  1733. }