pagination.go 50 KB

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