pagination.go 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530
  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/batchmsg"
  8. "wechat-api/ent/contact"
  9. "wechat-api/ent/employee"
  10. "wechat-api/ent/employeeconfig"
  11. "wechat-api/ent/label"
  12. "wechat-api/ent/labelrelationship"
  13. "wechat-api/ent/message"
  14. "wechat-api/ent/messagerecords"
  15. "wechat-api/ent/msg"
  16. "wechat-api/ent/server"
  17. "wechat-api/ent/sopnode"
  18. "wechat-api/ent/sopstage"
  19. "wechat-api/ent/soptask"
  20. "wechat-api/ent/token"
  21. "wechat-api/ent/tutorial"
  22. "wechat-api/ent/workexperience"
  23. "wechat-api/ent/wx"
  24. )
  25. const errInvalidPage = "INVALID_PAGE"
  26. const (
  27. listField = "list"
  28. pageNumField = "pageNum"
  29. pageSizeField = "pageSize"
  30. )
  31. type PageDetails struct {
  32. Page uint64 `json:"page"`
  33. Size uint64 `json:"size"`
  34. Total uint64 `json:"total"`
  35. }
  36. // OrderDirection defines the directions in which to order a list of items.
  37. type OrderDirection string
  38. const (
  39. // OrderDirectionAsc specifies an ascending order.
  40. OrderDirectionAsc OrderDirection = "ASC"
  41. // OrderDirectionDesc specifies a descending order.
  42. OrderDirectionDesc OrderDirection = "DESC"
  43. )
  44. // Validate the order direction value.
  45. func (o OrderDirection) Validate() error {
  46. if o != OrderDirectionAsc && o != OrderDirectionDesc {
  47. return fmt.Errorf("%s is not a valid OrderDirection", o)
  48. }
  49. return nil
  50. }
  51. // String implements fmt.Stringer interface.
  52. func (o OrderDirection) String() string {
  53. return string(o)
  54. }
  55. func (o OrderDirection) reverse() OrderDirection {
  56. if o == OrderDirectionDesc {
  57. return OrderDirectionAsc
  58. }
  59. return OrderDirectionDesc
  60. }
  61. const errInvalidPagination = "INVALID_PAGINATION"
  62. type AgentPager struct {
  63. Order agent.OrderOption
  64. Filter func(*AgentQuery) (*AgentQuery, error)
  65. }
  66. // AgentPaginateOption enables pagination customization.
  67. type AgentPaginateOption func(*AgentPager)
  68. // DefaultAgentOrder is the default ordering of Agent.
  69. var DefaultAgentOrder = Desc(agent.FieldID)
  70. func newAgentPager(opts []AgentPaginateOption) (*AgentPager, error) {
  71. pager := &AgentPager{}
  72. for _, opt := range opts {
  73. opt(pager)
  74. }
  75. if pager.Order == nil {
  76. pager.Order = DefaultAgentOrder
  77. }
  78. return pager, nil
  79. }
  80. func (p *AgentPager) ApplyFilter(query *AgentQuery) (*AgentQuery, error) {
  81. if p.Filter != nil {
  82. return p.Filter(query)
  83. }
  84. return query, nil
  85. }
  86. // AgentPageList is Agent PageList result.
  87. type AgentPageList struct {
  88. List []*Agent `json:"list"`
  89. PageDetails *PageDetails `json:"pageDetails"`
  90. }
  91. func (a *AgentQuery) Page(
  92. ctx context.Context, pageNum uint64, pageSize uint64, opts ...AgentPaginateOption,
  93. ) (*AgentPageList, error) {
  94. pager, err := newAgentPager(opts)
  95. if err != nil {
  96. return nil, err
  97. }
  98. if a, err = pager.ApplyFilter(a); err != nil {
  99. return nil, err
  100. }
  101. ret := &AgentPageList{}
  102. ret.PageDetails = &PageDetails{
  103. Page: pageNum,
  104. Size: pageSize,
  105. }
  106. query := a.Clone()
  107. query.ctx.Fields = nil
  108. count, err := query.Count(ctx)
  109. if err != nil {
  110. return nil, err
  111. }
  112. ret.PageDetails.Total = uint64(count)
  113. if pager.Order != nil {
  114. a = a.Order(pager.Order)
  115. } else {
  116. a = a.Order(DefaultAgentOrder)
  117. }
  118. a = a.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  119. list, err := a.All(ctx)
  120. if err != nil {
  121. return nil, err
  122. }
  123. ret.List = list
  124. return ret, nil
  125. }
  126. type BatchMsgPager struct {
  127. Order batchmsg.OrderOption
  128. Filter func(*BatchMsgQuery) (*BatchMsgQuery, error)
  129. }
  130. // BatchMsgPaginateOption enables pagination customization.
  131. type BatchMsgPaginateOption func(*BatchMsgPager)
  132. // DefaultBatchMsgOrder is the default ordering of BatchMsg.
  133. var DefaultBatchMsgOrder = Desc(batchmsg.FieldID)
  134. func newBatchMsgPager(opts []BatchMsgPaginateOption) (*BatchMsgPager, error) {
  135. pager := &BatchMsgPager{}
  136. for _, opt := range opts {
  137. opt(pager)
  138. }
  139. if pager.Order == nil {
  140. pager.Order = DefaultBatchMsgOrder
  141. }
  142. return pager, nil
  143. }
  144. func (p *BatchMsgPager) ApplyFilter(query *BatchMsgQuery) (*BatchMsgQuery, error) {
  145. if p.Filter != nil {
  146. return p.Filter(query)
  147. }
  148. return query, nil
  149. }
  150. // BatchMsgPageList is BatchMsg PageList result.
  151. type BatchMsgPageList struct {
  152. List []*BatchMsg `json:"list"`
  153. PageDetails *PageDetails `json:"pageDetails"`
  154. }
  155. func (bm *BatchMsgQuery) Page(
  156. ctx context.Context, pageNum uint64, pageSize uint64, opts ...BatchMsgPaginateOption,
  157. ) (*BatchMsgPageList, error) {
  158. pager, err := newBatchMsgPager(opts)
  159. if err != nil {
  160. return nil, err
  161. }
  162. if bm, err = pager.ApplyFilter(bm); err != nil {
  163. return nil, err
  164. }
  165. ret := &BatchMsgPageList{}
  166. ret.PageDetails = &PageDetails{
  167. Page: pageNum,
  168. Size: pageSize,
  169. }
  170. query := bm.Clone()
  171. query.ctx.Fields = nil
  172. count, err := query.Count(ctx)
  173. if err != nil {
  174. return nil, err
  175. }
  176. ret.PageDetails.Total = uint64(count)
  177. if pager.Order != nil {
  178. bm = bm.Order(pager.Order)
  179. } else {
  180. bm = bm.Order(DefaultBatchMsgOrder)
  181. }
  182. bm = bm.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  183. list, err := bm.All(ctx)
  184. if err != nil {
  185. return nil, err
  186. }
  187. ret.List = list
  188. return ret, nil
  189. }
  190. type ContactPager struct {
  191. Order contact.OrderOption
  192. Filter func(*ContactQuery) (*ContactQuery, error)
  193. }
  194. // ContactPaginateOption enables pagination customization.
  195. type ContactPaginateOption func(*ContactPager)
  196. // DefaultContactOrder is the default ordering of Contact.
  197. var DefaultContactOrder = Desc(contact.FieldID)
  198. func newContactPager(opts []ContactPaginateOption) (*ContactPager, error) {
  199. pager := &ContactPager{}
  200. for _, opt := range opts {
  201. opt(pager)
  202. }
  203. if pager.Order == nil {
  204. pager.Order = DefaultContactOrder
  205. }
  206. return pager, nil
  207. }
  208. func (p *ContactPager) ApplyFilter(query *ContactQuery) (*ContactQuery, error) {
  209. if p.Filter != nil {
  210. return p.Filter(query)
  211. }
  212. return query, nil
  213. }
  214. // ContactPageList is Contact PageList result.
  215. type ContactPageList struct {
  216. List []*Contact `json:"list"`
  217. PageDetails *PageDetails `json:"pageDetails"`
  218. }
  219. func (c *ContactQuery) Page(
  220. ctx context.Context, pageNum uint64, pageSize uint64, opts ...ContactPaginateOption,
  221. ) (*ContactPageList, error) {
  222. pager, err := newContactPager(opts)
  223. if err != nil {
  224. return nil, err
  225. }
  226. if c, err = pager.ApplyFilter(c); err != nil {
  227. return nil, err
  228. }
  229. ret := &ContactPageList{}
  230. ret.PageDetails = &PageDetails{
  231. Page: pageNum,
  232. Size: pageSize,
  233. }
  234. query := c.Clone()
  235. query.ctx.Fields = nil
  236. count, err := query.Count(ctx)
  237. if err != nil {
  238. return nil, err
  239. }
  240. ret.PageDetails.Total = uint64(count)
  241. if pager.Order != nil {
  242. c = c.Order(pager.Order)
  243. } else {
  244. c = c.Order(DefaultContactOrder)
  245. }
  246. c = c.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  247. list, err := c.All(ctx)
  248. if err != nil {
  249. return nil, err
  250. }
  251. ret.List = list
  252. return ret, nil
  253. }
  254. type EmployeePager struct {
  255. Order employee.OrderOption
  256. Filter func(*EmployeeQuery) (*EmployeeQuery, error)
  257. }
  258. // EmployeePaginateOption enables pagination customization.
  259. type EmployeePaginateOption func(*EmployeePager)
  260. // DefaultEmployeeOrder is the default ordering of Employee.
  261. var DefaultEmployeeOrder = Desc(employee.FieldID)
  262. func newEmployeePager(opts []EmployeePaginateOption) (*EmployeePager, error) {
  263. pager := &EmployeePager{}
  264. for _, opt := range opts {
  265. opt(pager)
  266. }
  267. if pager.Order == nil {
  268. pager.Order = DefaultEmployeeOrder
  269. }
  270. return pager, nil
  271. }
  272. func (p *EmployeePager) ApplyFilter(query *EmployeeQuery) (*EmployeeQuery, error) {
  273. if p.Filter != nil {
  274. return p.Filter(query)
  275. }
  276. return query, nil
  277. }
  278. // EmployeePageList is Employee PageList result.
  279. type EmployeePageList struct {
  280. List []*Employee `json:"list"`
  281. PageDetails *PageDetails `json:"pageDetails"`
  282. }
  283. func (e *EmployeeQuery) Page(
  284. ctx context.Context, pageNum uint64, pageSize uint64, opts ...EmployeePaginateOption,
  285. ) (*EmployeePageList, error) {
  286. pager, err := newEmployeePager(opts)
  287. if err != nil {
  288. return nil, err
  289. }
  290. if e, err = pager.ApplyFilter(e); err != nil {
  291. return nil, err
  292. }
  293. ret := &EmployeePageList{}
  294. ret.PageDetails = &PageDetails{
  295. Page: pageNum,
  296. Size: pageSize,
  297. }
  298. query := e.Clone()
  299. query.ctx.Fields = nil
  300. count, err := query.Count(ctx)
  301. if err != nil {
  302. return nil, err
  303. }
  304. ret.PageDetails.Total = uint64(count)
  305. if pager.Order != nil {
  306. e = e.Order(pager.Order)
  307. } else {
  308. e = e.Order(DefaultEmployeeOrder)
  309. }
  310. e = e.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  311. list, err := e.All(ctx)
  312. if err != nil {
  313. return nil, err
  314. }
  315. ret.List = list
  316. return ret, nil
  317. }
  318. type EmployeeConfigPager struct {
  319. Order employeeconfig.OrderOption
  320. Filter func(*EmployeeConfigQuery) (*EmployeeConfigQuery, error)
  321. }
  322. // EmployeeConfigPaginateOption enables pagination customization.
  323. type EmployeeConfigPaginateOption func(*EmployeeConfigPager)
  324. // DefaultEmployeeConfigOrder is the default ordering of EmployeeConfig.
  325. var DefaultEmployeeConfigOrder = Desc(employeeconfig.FieldID)
  326. func newEmployeeConfigPager(opts []EmployeeConfigPaginateOption) (*EmployeeConfigPager, error) {
  327. pager := &EmployeeConfigPager{}
  328. for _, opt := range opts {
  329. opt(pager)
  330. }
  331. if pager.Order == nil {
  332. pager.Order = DefaultEmployeeConfigOrder
  333. }
  334. return pager, nil
  335. }
  336. func (p *EmployeeConfigPager) ApplyFilter(query *EmployeeConfigQuery) (*EmployeeConfigQuery, error) {
  337. if p.Filter != nil {
  338. return p.Filter(query)
  339. }
  340. return query, nil
  341. }
  342. // EmployeeConfigPageList is EmployeeConfig PageList result.
  343. type EmployeeConfigPageList struct {
  344. List []*EmployeeConfig `json:"list"`
  345. PageDetails *PageDetails `json:"pageDetails"`
  346. }
  347. func (ec *EmployeeConfigQuery) Page(
  348. ctx context.Context, pageNum uint64, pageSize uint64, opts ...EmployeeConfigPaginateOption,
  349. ) (*EmployeeConfigPageList, error) {
  350. pager, err := newEmployeeConfigPager(opts)
  351. if err != nil {
  352. return nil, err
  353. }
  354. if ec, err = pager.ApplyFilter(ec); err != nil {
  355. return nil, err
  356. }
  357. ret := &EmployeeConfigPageList{}
  358. ret.PageDetails = &PageDetails{
  359. Page: pageNum,
  360. Size: pageSize,
  361. }
  362. query := ec.Clone()
  363. query.ctx.Fields = nil
  364. count, err := query.Count(ctx)
  365. if err != nil {
  366. return nil, err
  367. }
  368. ret.PageDetails.Total = uint64(count)
  369. if pager.Order != nil {
  370. ec = ec.Order(pager.Order)
  371. } else {
  372. ec = ec.Order(DefaultEmployeeConfigOrder)
  373. }
  374. ec = ec.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  375. list, err := ec.All(ctx)
  376. if err != nil {
  377. return nil, err
  378. }
  379. ret.List = list
  380. return ret, nil
  381. }
  382. type LabelPager struct {
  383. Order label.OrderOption
  384. Filter func(*LabelQuery) (*LabelQuery, error)
  385. }
  386. // LabelPaginateOption enables pagination customization.
  387. type LabelPaginateOption func(*LabelPager)
  388. // DefaultLabelOrder is the default ordering of Label.
  389. var DefaultLabelOrder = Desc(label.FieldID)
  390. func newLabelPager(opts []LabelPaginateOption) (*LabelPager, error) {
  391. pager := &LabelPager{}
  392. for _, opt := range opts {
  393. opt(pager)
  394. }
  395. if pager.Order == nil {
  396. pager.Order = DefaultLabelOrder
  397. }
  398. return pager, nil
  399. }
  400. func (p *LabelPager) ApplyFilter(query *LabelQuery) (*LabelQuery, error) {
  401. if p.Filter != nil {
  402. return p.Filter(query)
  403. }
  404. return query, nil
  405. }
  406. // LabelPageList is Label PageList result.
  407. type LabelPageList struct {
  408. List []*Label `json:"list"`
  409. PageDetails *PageDetails `json:"pageDetails"`
  410. }
  411. func (l *LabelQuery) Page(
  412. ctx context.Context, pageNum uint64, pageSize uint64, opts ...LabelPaginateOption,
  413. ) (*LabelPageList, error) {
  414. pager, err := newLabelPager(opts)
  415. if err != nil {
  416. return nil, err
  417. }
  418. if l, err = pager.ApplyFilter(l); err != nil {
  419. return nil, err
  420. }
  421. ret := &LabelPageList{}
  422. ret.PageDetails = &PageDetails{
  423. Page: pageNum,
  424. Size: pageSize,
  425. }
  426. query := l.Clone()
  427. query.ctx.Fields = nil
  428. count, err := query.Count(ctx)
  429. if err != nil {
  430. return nil, err
  431. }
  432. ret.PageDetails.Total = uint64(count)
  433. if pager.Order != nil {
  434. l = l.Order(pager.Order)
  435. } else {
  436. l = l.Order(DefaultLabelOrder)
  437. }
  438. l = l.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  439. list, err := l.All(ctx)
  440. if err != nil {
  441. return nil, err
  442. }
  443. ret.List = list
  444. return ret, nil
  445. }
  446. type LabelRelationshipPager struct {
  447. Order labelrelationship.OrderOption
  448. Filter func(*LabelRelationshipQuery) (*LabelRelationshipQuery, error)
  449. }
  450. // LabelRelationshipPaginateOption enables pagination customization.
  451. type LabelRelationshipPaginateOption func(*LabelRelationshipPager)
  452. // DefaultLabelRelationshipOrder is the default ordering of LabelRelationship.
  453. var DefaultLabelRelationshipOrder = Desc(labelrelationship.FieldID)
  454. func newLabelRelationshipPager(opts []LabelRelationshipPaginateOption) (*LabelRelationshipPager, error) {
  455. pager := &LabelRelationshipPager{}
  456. for _, opt := range opts {
  457. opt(pager)
  458. }
  459. if pager.Order == nil {
  460. pager.Order = DefaultLabelRelationshipOrder
  461. }
  462. return pager, nil
  463. }
  464. func (p *LabelRelationshipPager) ApplyFilter(query *LabelRelationshipQuery) (*LabelRelationshipQuery, error) {
  465. if p.Filter != nil {
  466. return p.Filter(query)
  467. }
  468. return query, nil
  469. }
  470. // LabelRelationshipPageList is LabelRelationship PageList result.
  471. type LabelRelationshipPageList struct {
  472. List []*LabelRelationship `json:"list"`
  473. PageDetails *PageDetails `json:"pageDetails"`
  474. }
  475. func (lr *LabelRelationshipQuery) Page(
  476. ctx context.Context, pageNum uint64, pageSize uint64, opts ...LabelRelationshipPaginateOption,
  477. ) (*LabelRelationshipPageList, error) {
  478. pager, err := newLabelRelationshipPager(opts)
  479. if err != nil {
  480. return nil, err
  481. }
  482. if lr, err = pager.ApplyFilter(lr); err != nil {
  483. return nil, err
  484. }
  485. ret := &LabelRelationshipPageList{}
  486. ret.PageDetails = &PageDetails{
  487. Page: pageNum,
  488. Size: pageSize,
  489. }
  490. query := lr.Clone()
  491. query.ctx.Fields = nil
  492. count, err := query.Count(ctx)
  493. if err != nil {
  494. return nil, err
  495. }
  496. ret.PageDetails.Total = uint64(count)
  497. if pager.Order != nil {
  498. lr = lr.Order(pager.Order)
  499. } else {
  500. lr = lr.Order(DefaultLabelRelationshipOrder)
  501. }
  502. lr = lr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  503. list, err := lr.All(ctx)
  504. if err != nil {
  505. return nil, err
  506. }
  507. ret.List = list
  508. return ret, nil
  509. }
  510. type MessagePager struct {
  511. Order message.OrderOption
  512. Filter func(*MessageQuery) (*MessageQuery, error)
  513. }
  514. // MessagePaginateOption enables pagination customization.
  515. type MessagePaginateOption func(*MessagePager)
  516. // DefaultMessageOrder is the default ordering of Message.
  517. var DefaultMessageOrder = Desc(message.FieldID)
  518. func newMessagePager(opts []MessagePaginateOption) (*MessagePager, error) {
  519. pager := &MessagePager{}
  520. for _, opt := range opts {
  521. opt(pager)
  522. }
  523. if pager.Order == nil {
  524. pager.Order = DefaultMessageOrder
  525. }
  526. return pager, nil
  527. }
  528. func (p *MessagePager) ApplyFilter(query *MessageQuery) (*MessageQuery, error) {
  529. if p.Filter != nil {
  530. return p.Filter(query)
  531. }
  532. return query, nil
  533. }
  534. // MessagePageList is Message PageList result.
  535. type MessagePageList struct {
  536. List []*Message `json:"list"`
  537. PageDetails *PageDetails `json:"pageDetails"`
  538. }
  539. func (m *MessageQuery) Page(
  540. ctx context.Context, pageNum uint64, pageSize uint64, opts ...MessagePaginateOption,
  541. ) (*MessagePageList, error) {
  542. pager, err := newMessagePager(opts)
  543. if err != nil {
  544. return nil, err
  545. }
  546. if m, err = pager.ApplyFilter(m); err != nil {
  547. return nil, err
  548. }
  549. ret := &MessagePageList{}
  550. ret.PageDetails = &PageDetails{
  551. Page: pageNum,
  552. Size: pageSize,
  553. }
  554. query := m.Clone()
  555. query.ctx.Fields = nil
  556. count, err := query.Count(ctx)
  557. if err != nil {
  558. return nil, err
  559. }
  560. ret.PageDetails.Total = uint64(count)
  561. if pager.Order != nil {
  562. m = m.Order(pager.Order)
  563. } else {
  564. m = m.Order(DefaultMessageOrder)
  565. }
  566. m = m.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  567. list, err := m.All(ctx)
  568. if err != nil {
  569. return nil, err
  570. }
  571. ret.List = list
  572. return ret, nil
  573. }
  574. type MessageRecordsPager struct {
  575. Order messagerecords.OrderOption
  576. Filter func(*MessageRecordsQuery) (*MessageRecordsQuery, error)
  577. }
  578. // MessageRecordsPaginateOption enables pagination customization.
  579. type MessageRecordsPaginateOption func(*MessageRecordsPager)
  580. // DefaultMessageRecordsOrder is the default ordering of MessageRecords.
  581. var DefaultMessageRecordsOrder = Desc(messagerecords.FieldID)
  582. func newMessageRecordsPager(opts []MessageRecordsPaginateOption) (*MessageRecordsPager, error) {
  583. pager := &MessageRecordsPager{}
  584. for _, opt := range opts {
  585. opt(pager)
  586. }
  587. if pager.Order == nil {
  588. pager.Order = DefaultMessageRecordsOrder
  589. }
  590. return pager, nil
  591. }
  592. func (p *MessageRecordsPager) ApplyFilter(query *MessageRecordsQuery) (*MessageRecordsQuery, error) {
  593. if p.Filter != nil {
  594. return p.Filter(query)
  595. }
  596. return query, nil
  597. }
  598. // MessageRecordsPageList is MessageRecords PageList result.
  599. type MessageRecordsPageList struct {
  600. List []*MessageRecords `json:"list"`
  601. PageDetails *PageDetails `json:"pageDetails"`
  602. }
  603. func (mr *MessageRecordsQuery) Page(
  604. ctx context.Context, pageNum uint64, pageSize uint64, opts ...MessageRecordsPaginateOption,
  605. ) (*MessageRecordsPageList, error) {
  606. pager, err := newMessageRecordsPager(opts)
  607. if err != nil {
  608. return nil, err
  609. }
  610. if mr, err = pager.ApplyFilter(mr); err != nil {
  611. return nil, err
  612. }
  613. ret := &MessageRecordsPageList{}
  614. ret.PageDetails = &PageDetails{
  615. Page: pageNum,
  616. Size: pageSize,
  617. }
  618. query := mr.Clone()
  619. query.ctx.Fields = nil
  620. count, err := query.Count(ctx)
  621. if err != nil {
  622. return nil, err
  623. }
  624. ret.PageDetails.Total = uint64(count)
  625. if pager.Order != nil {
  626. mr = mr.Order(pager.Order)
  627. } else {
  628. mr = mr.Order(DefaultMessageRecordsOrder)
  629. }
  630. mr = mr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  631. list, err := mr.All(ctx)
  632. if err != nil {
  633. return nil, err
  634. }
  635. ret.List = list
  636. return ret, nil
  637. }
  638. type MsgPager struct {
  639. Order msg.OrderOption
  640. Filter func(*MsgQuery) (*MsgQuery, error)
  641. }
  642. // MsgPaginateOption enables pagination customization.
  643. type MsgPaginateOption func(*MsgPager)
  644. // DefaultMsgOrder is the default ordering of Msg.
  645. var DefaultMsgOrder = Desc(msg.FieldID)
  646. func newMsgPager(opts []MsgPaginateOption) (*MsgPager, error) {
  647. pager := &MsgPager{}
  648. for _, opt := range opts {
  649. opt(pager)
  650. }
  651. if pager.Order == nil {
  652. pager.Order = DefaultMsgOrder
  653. }
  654. return pager, nil
  655. }
  656. func (p *MsgPager) ApplyFilter(query *MsgQuery) (*MsgQuery, error) {
  657. if p.Filter != nil {
  658. return p.Filter(query)
  659. }
  660. return query, nil
  661. }
  662. // MsgPageList is Msg PageList result.
  663. type MsgPageList struct {
  664. List []*Msg `json:"list"`
  665. PageDetails *PageDetails `json:"pageDetails"`
  666. }
  667. func (m *MsgQuery) Page(
  668. ctx context.Context, pageNum uint64, pageSize uint64, opts ...MsgPaginateOption,
  669. ) (*MsgPageList, error) {
  670. pager, err := newMsgPager(opts)
  671. if err != nil {
  672. return nil, err
  673. }
  674. if m, err = pager.ApplyFilter(m); err != nil {
  675. return nil, err
  676. }
  677. ret := &MsgPageList{}
  678. ret.PageDetails = &PageDetails{
  679. Page: pageNum,
  680. Size: pageSize,
  681. }
  682. query := m.Clone()
  683. query.ctx.Fields = nil
  684. count, err := query.Count(ctx)
  685. if err != nil {
  686. return nil, err
  687. }
  688. ret.PageDetails.Total = uint64(count)
  689. if pager.Order != nil {
  690. m = m.Order(pager.Order)
  691. } else {
  692. m = m.Order(DefaultMsgOrder)
  693. }
  694. m = m.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  695. list, err := m.All(ctx)
  696. if err != nil {
  697. return nil, err
  698. }
  699. ret.List = list
  700. return ret, nil
  701. }
  702. type ServerPager struct {
  703. Order server.OrderOption
  704. Filter func(*ServerQuery) (*ServerQuery, error)
  705. }
  706. // ServerPaginateOption enables pagination customization.
  707. type ServerPaginateOption func(*ServerPager)
  708. // DefaultServerOrder is the default ordering of Server.
  709. var DefaultServerOrder = Desc(server.FieldID)
  710. func newServerPager(opts []ServerPaginateOption) (*ServerPager, error) {
  711. pager := &ServerPager{}
  712. for _, opt := range opts {
  713. opt(pager)
  714. }
  715. if pager.Order == nil {
  716. pager.Order = DefaultServerOrder
  717. }
  718. return pager, nil
  719. }
  720. func (p *ServerPager) ApplyFilter(query *ServerQuery) (*ServerQuery, error) {
  721. if p.Filter != nil {
  722. return p.Filter(query)
  723. }
  724. return query, nil
  725. }
  726. // ServerPageList is Server PageList result.
  727. type ServerPageList struct {
  728. List []*Server `json:"list"`
  729. PageDetails *PageDetails `json:"pageDetails"`
  730. }
  731. func (s *ServerQuery) Page(
  732. ctx context.Context, pageNum uint64, pageSize uint64, opts ...ServerPaginateOption,
  733. ) (*ServerPageList, error) {
  734. pager, err := newServerPager(opts)
  735. if err != nil {
  736. return nil, err
  737. }
  738. if s, err = pager.ApplyFilter(s); err != nil {
  739. return nil, err
  740. }
  741. ret := &ServerPageList{}
  742. ret.PageDetails = &PageDetails{
  743. Page: pageNum,
  744. Size: pageSize,
  745. }
  746. query := s.Clone()
  747. query.ctx.Fields = nil
  748. count, err := query.Count(ctx)
  749. if err != nil {
  750. return nil, err
  751. }
  752. ret.PageDetails.Total = uint64(count)
  753. if pager.Order != nil {
  754. s = s.Order(pager.Order)
  755. } else {
  756. s = s.Order(DefaultServerOrder)
  757. }
  758. s = s.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  759. list, err := s.All(ctx)
  760. if err != nil {
  761. return nil, err
  762. }
  763. ret.List = list
  764. return ret, nil
  765. }
  766. type SopNodePager struct {
  767. Order sopnode.OrderOption
  768. Filter func(*SopNodeQuery) (*SopNodeQuery, error)
  769. }
  770. // SopNodePaginateOption enables pagination customization.
  771. type SopNodePaginateOption func(*SopNodePager)
  772. // DefaultSopNodeOrder is the default ordering of SopNode.
  773. var DefaultSopNodeOrder = Desc(sopnode.FieldID)
  774. func newSopNodePager(opts []SopNodePaginateOption) (*SopNodePager, error) {
  775. pager := &SopNodePager{}
  776. for _, opt := range opts {
  777. opt(pager)
  778. }
  779. if pager.Order == nil {
  780. pager.Order = DefaultSopNodeOrder
  781. }
  782. return pager, nil
  783. }
  784. func (p *SopNodePager) ApplyFilter(query *SopNodeQuery) (*SopNodeQuery, error) {
  785. if p.Filter != nil {
  786. return p.Filter(query)
  787. }
  788. return query, nil
  789. }
  790. // SopNodePageList is SopNode PageList result.
  791. type SopNodePageList struct {
  792. List []*SopNode `json:"list"`
  793. PageDetails *PageDetails `json:"pageDetails"`
  794. }
  795. func (sn *SopNodeQuery) Page(
  796. ctx context.Context, pageNum uint64, pageSize uint64, opts ...SopNodePaginateOption,
  797. ) (*SopNodePageList, error) {
  798. pager, err := newSopNodePager(opts)
  799. if err != nil {
  800. return nil, err
  801. }
  802. if sn, err = pager.ApplyFilter(sn); err != nil {
  803. return nil, err
  804. }
  805. ret := &SopNodePageList{}
  806. ret.PageDetails = &PageDetails{
  807. Page: pageNum,
  808. Size: pageSize,
  809. }
  810. query := sn.Clone()
  811. query.ctx.Fields = nil
  812. count, err := query.Count(ctx)
  813. if err != nil {
  814. return nil, err
  815. }
  816. ret.PageDetails.Total = uint64(count)
  817. if pager.Order != nil {
  818. sn = sn.Order(pager.Order)
  819. } else {
  820. sn = sn.Order(DefaultSopNodeOrder)
  821. }
  822. sn = sn.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  823. list, err := sn.All(ctx)
  824. if err != nil {
  825. return nil, err
  826. }
  827. ret.List = list
  828. return ret, nil
  829. }
  830. type SopStagePager struct {
  831. Order sopstage.OrderOption
  832. Filter func(*SopStageQuery) (*SopStageQuery, error)
  833. }
  834. // SopStagePaginateOption enables pagination customization.
  835. type SopStagePaginateOption func(*SopStagePager)
  836. // DefaultSopStageOrder is the default ordering of SopStage.
  837. var DefaultSopStageOrder = Desc(sopstage.FieldID)
  838. func newSopStagePager(opts []SopStagePaginateOption) (*SopStagePager, error) {
  839. pager := &SopStagePager{}
  840. for _, opt := range opts {
  841. opt(pager)
  842. }
  843. if pager.Order == nil {
  844. pager.Order = DefaultSopStageOrder
  845. }
  846. return pager, nil
  847. }
  848. func (p *SopStagePager) ApplyFilter(query *SopStageQuery) (*SopStageQuery, error) {
  849. if p.Filter != nil {
  850. return p.Filter(query)
  851. }
  852. return query, nil
  853. }
  854. // SopStagePageList is SopStage PageList result.
  855. type SopStagePageList struct {
  856. List []*SopStage `json:"list"`
  857. PageDetails *PageDetails `json:"pageDetails"`
  858. }
  859. func (ss *SopStageQuery) Page(
  860. ctx context.Context, pageNum uint64, pageSize uint64, opts ...SopStagePaginateOption,
  861. ) (*SopStagePageList, error) {
  862. pager, err := newSopStagePager(opts)
  863. if err != nil {
  864. return nil, err
  865. }
  866. if ss, err = pager.ApplyFilter(ss); err != nil {
  867. return nil, err
  868. }
  869. ret := &SopStagePageList{}
  870. ret.PageDetails = &PageDetails{
  871. Page: pageNum,
  872. Size: pageSize,
  873. }
  874. query := ss.Clone()
  875. query.ctx.Fields = nil
  876. count, err := query.Count(ctx)
  877. if err != nil {
  878. return nil, err
  879. }
  880. ret.PageDetails.Total = uint64(count)
  881. if pager.Order != nil {
  882. ss = ss.Order(pager.Order)
  883. } else {
  884. ss = ss.Order(DefaultSopStageOrder)
  885. }
  886. ss = ss.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  887. list, err := ss.All(ctx)
  888. if err != nil {
  889. return nil, err
  890. }
  891. ret.List = list
  892. return ret, nil
  893. }
  894. type SopTaskPager struct {
  895. Order soptask.OrderOption
  896. Filter func(*SopTaskQuery) (*SopTaskQuery, error)
  897. }
  898. // SopTaskPaginateOption enables pagination customization.
  899. type SopTaskPaginateOption func(*SopTaskPager)
  900. // DefaultSopTaskOrder is the default ordering of SopTask.
  901. var DefaultSopTaskOrder = Desc(soptask.FieldID)
  902. func newSopTaskPager(opts []SopTaskPaginateOption) (*SopTaskPager, error) {
  903. pager := &SopTaskPager{}
  904. for _, opt := range opts {
  905. opt(pager)
  906. }
  907. if pager.Order == nil {
  908. pager.Order = DefaultSopTaskOrder
  909. }
  910. return pager, nil
  911. }
  912. func (p *SopTaskPager) ApplyFilter(query *SopTaskQuery) (*SopTaskQuery, error) {
  913. if p.Filter != nil {
  914. return p.Filter(query)
  915. }
  916. return query, nil
  917. }
  918. // SopTaskPageList is SopTask PageList result.
  919. type SopTaskPageList struct {
  920. List []*SopTask `json:"list"`
  921. PageDetails *PageDetails `json:"pageDetails"`
  922. }
  923. func (st *SopTaskQuery) Page(
  924. ctx context.Context, pageNum uint64, pageSize uint64, opts ...SopTaskPaginateOption,
  925. ) (*SopTaskPageList, error) {
  926. pager, err := newSopTaskPager(opts)
  927. if err != nil {
  928. return nil, err
  929. }
  930. if st, err = pager.ApplyFilter(st); err != nil {
  931. return nil, err
  932. }
  933. ret := &SopTaskPageList{}
  934. ret.PageDetails = &PageDetails{
  935. Page: pageNum,
  936. Size: pageSize,
  937. }
  938. query := st.Clone()
  939. query.ctx.Fields = nil
  940. count, err := query.Count(ctx)
  941. if err != nil {
  942. return nil, err
  943. }
  944. ret.PageDetails.Total = uint64(count)
  945. if pager.Order != nil {
  946. st = st.Order(pager.Order)
  947. } else {
  948. st = st.Order(DefaultSopTaskOrder)
  949. }
  950. st = st.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  951. list, err := st.All(ctx)
  952. if err != nil {
  953. return nil, err
  954. }
  955. ret.List = list
  956. return ret, nil
  957. }
  958. type TokenPager struct {
  959. Order token.OrderOption
  960. Filter func(*TokenQuery) (*TokenQuery, error)
  961. }
  962. // TokenPaginateOption enables pagination customization.
  963. type TokenPaginateOption func(*TokenPager)
  964. // DefaultTokenOrder is the default ordering of Token.
  965. var DefaultTokenOrder = Desc(token.FieldID)
  966. func newTokenPager(opts []TokenPaginateOption) (*TokenPager, error) {
  967. pager := &TokenPager{}
  968. for _, opt := range opts {
  969. opt(pager)
  970. }
  971. if pager.Order == nil {
  972. pager.Order = DefaultTokenOrder
  973. }
  974. return pager, nil
  975. }
  976. func (p *TokenPager) ApplyFilter(query *TokenQuery) (*TokenQuery, error) {
  977. if p.Filter != nil {
  978. return p.Filter(query)
  979. }
  980. return query, nil
  981. }
  982. // TokenPageList is Token PageList result.
  983. type TokenPageList struct {
  984. List []*Token `json:"list"`
  985. PageDetails *PageDetails `json:"pageDetails"`
  986. }
  987. func (t *TokenQuery) Page(
  988. ctx context.Context, pageNum uint64, pageSize uint64, opts ...TokenPaginateOption,
  989. ) (*TokenPageList, error) {
  990. pager, err := newTokenPager(opts)
  991. if err != nil {
  992. return nil, err
  993. }
  994. if t, err = pager.ApplyFilter(t); err != nil {
  995. return nil, err
  996. }
  997. ret := &TokenPageList{}
  998. ret.PageDetails = &PageDetails{
  999. Page: pageNum,
  1000. Size: pageSize,
  1001. }
  1002. query := t.Clone()
  1003. query.ctx.Fields = nil
  1004. count, err := query.Count(ctx)
  1005. if err != nil {
  1006. return nil, err
  1007. }
  1008. ret.PageDetails.Total = uint64(count)
  1009. if pager.Order != nil {
  1010. t = t.Order(pager.Order)
  1011. } else {
  1012. t = t.Order(DefaultTokenOrder)
  1013. }
  1014. t = t.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1015. list, err := t.All(ctx)
  1016. if err != nil {
  1017. return nil, err
  1018. }
  1019. ret.List = list
  1020. return ret, nil
  1021. }
  1022. type TutorialPager struct {
  1023. Order tutorial.OrderOption
  1024. Filter func(*TutorialQuery) (*TutorialQuery, error)
  1025. }
  1026. // TutorialPaginateOption enables pagination customization.
  1027. type TutorialPaginateOption func(*TutorialPager)
  1028. // DefaultTutorialOrder is the default ordering of Tutorial.
  1029. var DefaultTutorialOrder = Desc(tutorial.FieldID)
  1030. func newTutorialPager(opts []TutorialPaginateOption) (*TutorialPager, error) {
  1031. pager := &TutorialPager{}
  1032. for _, opt := range opts {
  1033. opt(pager)
  1034. }
  1035. if pager.Order == nil {
  1036. pager.Order = DefaultTutorialOrder
  1037. }
  1038. return pager, nil
  1039. }
  1040. func (p *TutorialPager) ApplyFilter(query *TutorialQuery) (*TutorialQuery, error) {
  1041. if p.Filter != nil {
  1042. return p.Filter(query)
  1043. }
  1044. return query, nil
  1045. }
  1046. // TutorialPageList is Tutorial PageList result.
  1047. type TutorialPageList struct {
  1048. List []*Tutorial `json:"list"`
  1049. PageDetails *PageDetails `json:"pageDetails"`
  1050. }
  1051. func (t *TutorialQuery) Page(
  1052. ctx context.Context, pageNum uint64, pageSize uint64, opts ...TutorialPaginateOption,
  1053. ) (*TutorialPageList, error) {
  1054. pager, err := newTutorialPager(opts)
  1055. if err != nil {
  1056. return nil, err
  1057. }
  1058. if t, err = pager.ApplyFilter(t); err != nil {
  1059. return nil, err
  1060. }
  1061. ret := &TutorialPageList{}
  1062. ret.PageDetails = &PageDetails{
  1063. Page: pageNum,
  1064. Size: pageSize,
  1065. }
  1066. query := t.Clone()
  1067. query.ctx.Fields = nil
  1068. count, err := query.Count(ctx)
  1069. if err != nil {
  1070. return nil, err
  1071. }
  1072. ret.PageDetails.Total = uint64(count)
  1073. if pager.Order != nil {
  1074. t = t.Order(pager.Order)
  1075. } else {
  1076. t = t.Order(DefaultTutorialOrder)
  1077. }
  1078. t = t.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1079. list, err := t.All(ctx)
  1080. if err != nil {
  1081. return nil, err
  1082. }
  1083. ret.List = list
  1084. return ret, nil
  1085. }
  1086. type WorkExperiencePager struct {
  1087. Order workexperience.OrderOption
  1088. Filter func(*WorkExperienceQuery) (*WorkExperienceQuery, error)
  1089. }
  1090. // WorkExperiencePaginateOption enables pagination customization.
  1091. type WorkExperiencePaginateOption func(*WorkExperiencePager)
  1092. // DefaultWorkExperienceOrder is the default ordering of WorkExperience.
  1093. var DefaultWorkExperienceOrder = Desc(workexperience.FieldID)
  1094. func newWorkExperiencePager(opts []WorkExperiencePaginateOption) (*WorkExperiencePager, error) {
  1095. pager := &WorkExperiencePager{}
  1096. for _, opt := range opts {
  1097. opt(pager)
  1098. }
  1099. if pager.Order == nil {
  1100. pager.Order = DefaultWorkExperienceOrder
  1101. }
  1102. return pager, nil
  1103. }
  1104. func (p *WorkExperiencePager) ApplyFilter(query *WorkExperienceQuery) (*WorkExperienceQuery, error) {
  1105. if p.Filter != nil {
  1106. return p.Filter(query)
  1107. }
  1108. return query, nil
  1109. }
  1110. // WorkExperiencePageList is WorkExperience PageList result.
  1111. type WorkExperiencePageList struct {
  1112. List []*WorkExperience `json:"list"`
  1113. PageDetails *PageDetails `json:"pageDetails"`
  1114. }
  1115. func (we *WorkExperienceQuery) Page(
  1116. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WorkExperiencePaginateOption,
  1117. ) (*WorkExperiencePageList, error) {
  1118. pager, err := newWorkExperiencePager(opts)
  1119. if err != nil {
  1120. return nil, err
  1121. }
  1122. if we, err = pager.ApplyFilter(we); err != nil {
  1123. return nil, err
  1124. }
  1125. ret := &WorkExperiencePageList{}
  1126. ret.PageDetails = &PageDetails{
  1127. Page: pageNum,
  1128. Size: pageSize,
  1129. }
  1130. query := we.Clone()
  1131. query.ctx.Fields = nil
  1132. count, err := query.Count(ctx)
  1133. if err != nil {
  1134. return nil, err
  1135. }
  1136. ret.PageDetails.Total = uint64(count)
  1137. if pager.Order != nil {
  1138. we = we.Order(pager.Order)
  1139. } else {
  1140. we = we.Order(DefaultWorkExperienceOrder)
  1141. }
  1142. we = we.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1143. list, err := we.All(ctx)
  1144. if err != nil {
  1145. return nil, err
  1146. }
  1147. ret.List = list
  1148. return ret, nil
  1149. }
  1150. type WxPager struct {
  1151. Order wx.OrderOption
  1152. Filter func(*WxQuery) (*WxQuery, error)
  1153. }
  1154. // WxPaginateOption enables pagination customization.
  1155. type WxPaginateOption func(*WxPager)
  1156. // DefaultWxOrder is the default ordering of Wx.
  1157. var DefaultWxOrder = Desc(wx.FieldID)
  1158. func newWxPager(opts []WxPaginateOption) (*WxPager, error) {
  1159. pager := &WxPager{}
  1160. for _, opt := range opts {
  1161. opt(pager)
  1162. }
  1163. if pager.Order == nil {
  1164. pager.Order = DefaultWxOrder
  1165. }
  1166. return pager, nil
  1167. }
  1168. func (p *WxPager) ApplyFilter(query *WxQuery) (*WxQuery, error) {
  1169. if p.Filter != nil {
  1170. return p.Filter(query)
  1171. }
  1172. return query, nil
  1173. }
  1174. // WxPageList is Wx PageList result.
  1175. type WxPageList struct {
  1176. List []*Wx `json:"list"`
  1177. PageDetails *PageDetails `json:"pageDetails"`
  1178. }
  1179. func (w *WxQuery) Page(
  1180. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxPaginateOption,
  1181. ) (*WxPageList, error) {
  1182. pager, err := newWxPager(opts)
  1183. if err != nil {
  1184. return nil, err
  1185. }
  1186. if w, err = pager.ApplyFilter(w); err != nil {
  1187. return nil, err
  1188. }
  1189. ret := &WxPageList{}
  1190. ret.PageDetails = &PageDetails{
  1191. Page: pageNum,
  1192. Size: pageSize,
  1193. }
  1194. query := w.Clone()
  1195. query.ctx.Fields = nil
  1196. count, err := query.Count(ctx)
  1197. if err != nil {
  1198. return nil, err
  1199. }
  1200. ret.PageDetails.Total = uint64(count)
  1201. if pager.Order != nil {
  1202. w = w.Order(pager.Order)
  1203. } else {
  1204. w = w.Order(DefaultWxOrder)
  1205. }
  1206. w = w.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1207. list, err := w.All(ctx)
  1208. if err != nil {
  1209. return nil, err
  1210. }
  1211. ret.List = list
  1212. return ret, nil
  1213. }