pagination.go 28 KB

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