pagination.go 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088
  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/allocagent"
  10. "wechat-api/ent/batchmsg"
  11. "wechat-api/ent/category"
  12. "wechat-api/ent/chatrecords"
  13. "wechat-api/ent/chatsession"
  14. "wechat-api/ent/contact"
  15. "wechat-api/ent/creditbalance"
  16. "wechat-api/ent/creditusage"
  17. "wechat-api/ent/employee"
  18. "wechat-api/ent/employeeconfig"
  19. "wechat-api/ent/label"
  20. "wechat-api/ent/labelrelationship"
  21. "wechat-api/ent/message"
  22. "wechat-api/ent/messagerecords"
  23. "wechat-api/ent/msg"
  24. "wechat-api/ent/payrecharge"
  25. "wechat-api/ent/server"
  26. "wechat-api/ent/sopnode"
  27. "wechat-api/ent/sopstage"
  28. "wechat-api/ent/soptask"
  29. "wechat-api/ent/token"
  30. "wechat-api/ent/tutorial"
  31. "wechat-api/ent/usagedetail"
  32. "wechat-api/ent/usagestatisticday"
  33. "wechat-api/ent/usagestatistichour"
  34. "wechat-api/ent/usagestatisticmonth"
  35. "wechat-api/ent/usagetotal"
  36. "wechat-api/ent/workexperience"
  37. "wechat-api/ent/wpchatroom"
  38. "wechat-api/ent/wpchatroommember"
  39. "wechat-api/ent/wx"
  40. "wechat-api/ent/wxcard"
  41. "wechat-api/ent/wxcarduser"
  42. "wechat-api/ent/wxcardvisit"
  43. )
  44. const errInvalidPage = "INVALID_PAGE"
  45. const (
  46. listField = "list"
  47. pageNumField = "pageNum"
  48. pageSizeField = "pageSize"
  49. )
  50. type PageDetails struct {
  51. Page uint64 `json:"page"`
  52. Size uint64 `json:"size"`
  53. Total uint64 `json:"total"`
  54. }
  55. // OrderDirection defines the directions in which to order a list of items.
  56. type OrderDirection string
  57. const (
  58. // OrderDirectionAsc specifies an ascending order.
  59. OrderDirectionAsc OrderDirection = "ASC"
  60. // OrderDirectionDesc specifies a descending order.
  61. OrderDirectionDesc OrderDirection = "DESC"
  62. )
  63. // Validate the order direction value.
  64. func (o OrderDirection) Validate() error {
  65. if o != OrderDirectionAsc && o != OrderDirectionDesc {
  66. return fmt.Errorf("%s is not a valid OrderDirection", o)
  67. }
  68. return nil
  69. }
  70. // String implements fmt.Stringer interface.
  71. func (o OrderDirection) String() string {
  72. return string(o)
  73. }
  74. func (o OrderDirection) reverse() OrderDirection {
  75. if o == OrderDirectionDesc {
  76. return OrderDirectionAsc
  77. }
  78. return OrderDirectionDesc
  79. }
  80. const errInvalidPagination = "INVALID_PAGINATION"
  81. type AgentPager struct {
  82. Order agent.OrderOption
  83. Filter func(*AgentQuery) (*AgentQuery, error)
  84. }
  85. // AgentPaginateOption enables pagination customization.
  86. type AgentPaginateOption func(*AgentPager)
  87. // DefaultAgentOrder is the default ordering of Agent.
  88. var DefaultAgentOrder = Desc(agent.FieldID)
  89. func newAgentPager(opts []AgentPaginateOption) (*AgentPager, error) {
  90. pager := &AgentPager{}
  91. for _, opt := range opts {
  92. opt(pager)
  93. }
  94. if pager.Order == nil {
  95. pager.Order = DefaultAgentOrder
  96. }
  97. return pager, nil
  98. }
  99. func (p *AgentPager) ApplyFilter(query *AgentQuery) (*AgentQuery, error) {
  100. if p.Filter != nil {
  101. return p.Filter(query)
  102. }
  103. return query, nil
  104. }
  105. // AgentPageList is Agent PageList result.
  106. type AgentPageList struct {
  107. List []*Agent `json:"list"`
  108. PageDetails *PageDetails `json:"pageDetails"`
  109. }
  110. func (a *AgentQuery) Page(
  111. ctx context.Context, pageNum uint64, pageSize uint64, opts ...AgentPaginateOption,
  112. ) (*AgentPageList, error) {
  113. pager, err := newAgentPager(opts)
  114. if err != nil {
  115. return nil, err
  116. }
  117. if a, err = pager.ApplyFilter(a); err != nil {
  118. return nil, err
  119. }
  120. ret := &AgentPageList{}
  121. ret.PageDetails = &PageDetails{
  122. Page: pageNum,
  123. Size: pageSize,
  124. }
  125. query := a.Clone()
  126. query.ctx.Fields = nil
  127. count, err := query.Count(ctx)
  128. if err != nil {
  129. return nil, err
  130. }
  131. ret.PageDetails.Total = uint64(count)
  132. if pager.Order != nil {
  133. a = a.Order(pager.Order)
  134. } else {
  135. a = a.Order(DefaultAgentOrder)
  136. }
  137. a = a.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  138. list, err := a.All(ctx)
  139. if err != nil {
  140. return nil, err
  141. }
  142. ret.List = list
  143. return ret, nil
  144. }
  145. type AgentBasePager struct {
  146. Order agentbase.OrderOption
  147. Filter func(*AgentBaseQuery) (*AgentBaseQuery, error)
  148. }
  149. // AgentBasePaginateOption enables pagination customization.
  150. type AgentBasePaginateOption func(*AgentBasePager)
  151. // DefaultAgentBaseOrder is the default ordering of AgentBase.
  152. var DefaultAgentBaseOrder = Desc(agentbase.FieldID)
  153. func newAgentBasePager(opts []AgentBasePaginateOption) (*AgentBasePager, error) {
  154. pager := &AgentBasePager{}
  155. for _, opt := range opts {
  156. opt(pager)
  157. }
  158. if pager.Order == nil {
  159. pager.Order = DefaultAgentBaseOrder
  160. }
  161. return pager, nil
  162. }
  163. func (p *AgentBasePager) ApplyFilter(query *AgentBaseQuery) (*AgentBaseQuery, error) {
  164. if p.Filter != nil {
  165. return p.Filter(query)
  166. }
  167. return query, nil
  168. }
  169. // AgentBasePageList is AgentBase PageList result.
  170. type AgentBasePageList struct {
  171. List []*AgentBase `json:"list"`
  172. PageDetails *PageDetails `json:"pageDetails"`
  173. }
  174. func (ab *AgentBaseQuery) Page(
  175. ctx context.Context, pageNum uint64, pageSize uint64, opts ...AgentBasePaginateOption,
  176. ) (*AgentBasePageList, error) {
  177. pager, err := newAgentBasePager(opts)
  178. if err != nil {
  179. return nil, err
  180. }
  181. if ab, err = pager.ApplyFilter(ab); err != nil {
  182. return nil, err
  183. }
  184. ret := &AgentBasePageList{}
  185. ret.PageDetails = &PageDetails{
  186. Page: pageNum,
  187. Size: pageSize,
  188. }
  189. query := ab.Clone()
  190. query.ctx.Fields = nil
  191. count, err := query.Count(ctx)
  192. if err != nil {
  193. return nil, err
  194. }
  195. ret.PageDetails.Total = uint64(count)
  196. if pager.Order != nil {
  197. ab = ab.Order(pager.Order)
  198. } else {
  199. ab = ab.Order(DefaultAgentBaseOrder)
  200. }
  201. ab = ab.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  202. list, err := ab.All(ctx)
  203. if err != nil {
  204. return nil, err
  205. }
  206. ret.List = list
  207. return ret, nil
  208. }
  209. type AliyunAvatarPager struct {
  210. Order aliyunavatar.OrderOption
  211. Filter func(*AliyunAvatarQuery) (*AliyunAvatarQuery, error)
  212. }
  213. // AliyunAvatarPaginateOption enables pagination customization.
  214. type AliyunAvatarPaginateOption func(*AliyunAvatarPager)
  215. // DefaultAliyunAvatarOrder is the default ordering of AliyunAvatar.
  216. var DefaultAliyunAvatarOrder = Desc(aliyunavatar.FieldID)
  217. func newAliyunAvatarPager(opts []AliyunAvatarPaginateOption) (*AliyunAvatarPager, error) {
  218. pager := &AliyunAvatarPager{}
  219. for _, opt := range opts {
  220. opt(pager)
  221. }
  222. if pager.Order == nil {
  223. pager.Order = DefaultAliyunAvatarOrder
  224. }
  225. return pager, nil
  226. }
  227. func (p *AliyunAvatarPager) ApplyFilter(query *AliyunAvatarQuery) (*AliyunAvatarQuery, error) {
  228. if p.Filter != nil {
  229. return p.Filter(query)
  230. }
  231. return query, nil
  232. }
  233. // AliyunAvatarPageList is AliyunAvatar PageList result.
  234. type AliyunAvatarPageList struct {
  235. List []*AliyunAvatar `json:"list"`
  236. PageDetails *PageDetails `json:"pageDetails"`
  237. }
  238. func (aa *AliyunAvatarQuery) Page(
  239. ctx context.Context, pageNum uint64, pageSize uint64, opts ...AliyunAvatarPaginateOption,
  240. ) (*AliyunAvatarPageList, error) {
  241. pager, err := newAliyunAvatarPager(opts)
  242. if err != nil {
  243. return nil, err
  244. }
  245. if aa, err = pager.ApplyFilter(aa); err != nil {
  246. return nil, err
  247. }
  248. ret := &AliyunAvatarPageList{}
  249. ret.PageDetails = &PageDetails{
  250. Page: pageNum,
  251. Size: pageSize,
  252. }
  253. query := aa.Clone()
  254. query.ctx.Fields = nil
  255. count, err := query.Count(ctx)
  256. if err != nil {
  257. return nil, err
  258. }
  259. ret.PageDetails.Total = uint64(count)
  260. if pager.Order != nil {
  261. aa = aa.Order(pager.Order)
  262. } else {
  263. aa = aa.Order(DefaultAliyunAvatarOrder)
  264. }
  265. aa = aa.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  266. list, err := aa.All(ctx)
  267. if err != nil {
  268. return nil, err
  269. }
  270. ret.List = list
  271. return ret, nil
  272. }
  273. type AllocAgentPager struct {
  274. Order allocagent.OrderOption
  275. Filter func(*AllocAgentQuery) (*AllocAgentQuery, error)
  276. }
  277. // AllocAgentPaginateOption enables pagination customization.
  278. type AllocAgentPaginateOption func(*AllocAgentPager)
  279. // DefaultAllocAgentOrder is the default ordering of AllocAgent.
  280. var DefaultAllocAgentOrder = Desc(allocagent.FieldID)
  281. func newAllocAgentPager(opts []AllocAgentPaginateOption) (*AllocAgentPager, error) {
  282. pager := &AllocAgentPager{}
  283. for _, opt := range opts {
  284. opt(pager)
  285. }
  286. if pager.Order == nil {
  287. pager.Order = DefaultAllocAgentOrder
  288. }
  289. return pager, nil
  290. }
  291. func (p *AllocAgentPager) ApplyFilter(query *AllocAgentQuery) (*AllocAgentQuery, error) {
  292. if p.Filter != nil {
  293. return p.Filter(query)
  294. }
  295. return query, nil
  296. }
  297. // AllocAgentPageList is AllocAgent PageList result.
  298. type AllocAgentPageList struct {
  299. List []*AllocAgent `json:"list"`
  300. PageDetails *PageDetails `json:"pageDetails"`
  301. }
  302. func (aa *AllocAgentQuery) Page(
  303. ctx context.Context, pageNum uint64, pageSize uint64, opts ...AllocAgentPaginateOption,
  304. ) (*AllocAgentPageList, error) {
  305. pager, err := newAllocAgentPager(opts)
  306. if err != nil {
  307. return nil, err
  308. }
  309. if aa, err = pager.ApplyFilter(aa); err != nil {
  310. return nil, err
  311. }
  312. ret := &AllocAgentPageList{}
  313. ret.PageDetails = &PageDetails{
  314. Page: pageNum,
  315. Size: pageSize,
  316. }
  317. query := aa.Clone()
  318. query.ctx.Fields = nil
  319. count, err := query.Count(ctx)
  320. if err != nil {
  321. return nil, err
  322. }
  323. ret.PageDetails.Total = uint64(count)
  324. if pager.Order != nil {
  325. aa = aa.Order(pager.Order)
  326. } else {
  327. aa = aa.Order(DefaultAllocAgentOrder)
  328. }
  329. aa = aa.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  330. list, err := aa.All(ctx)
  331. if err != nil {
  332. return nil, err
  333. }
  334. ret.List = list
  335. return ret, nil
  336. }
  337. type BatchMsgPager struct {
  338. Order batchmsg.OrderOption
  339. Filter func(*BatchMsgQuery) (*BatchMsgQuery, error)
  340. }
  341. // BatchMsgPaginateOption enables pagination customization.
  342. type BatchMsgPaginateOption func(*BatchMsgPager)
  343. // DefaultBatchMsgOrder is the default ordering of BatchMsg.
  344. var DefaultBatchMsgOrder = Desc(batchmsg.FieldID)
  345. func newBatchMsgPager(opts []BatchMsgPaginateOption) (*BatchMsgPager, error) {
  346. pager := &BatchMsgPager{}
  347. for _, opt := range opts {
  348. opt(pager)
  349. }
  350. if pager.Order == nil {
  351. pager.Order = DefaultBatchMsgOrder
  352. }
  353. return pager, nil
  354. }
  355. func (p *BatchMsgPager) ApplyFilter(query *BatchMsgQuery) (*BatchMsgQuery, error) {
  356. if p.Filter != nil {
  357. return p.Filter(query)
  358. }
  359. return query, nil
  360. }
  361. // BatchMsgPageList is BatchMsg PageList result.
  362. type BatchMsgPageList struct {
  363. List []*BatchMsg `json:"list"`
  364. PageDetails *PageDetails `json:"pageDetails"`
  365. }
  366. func (bm *BatchMsgQuery) Page(
  367. ctx context.Context, pageNum uint64, pageSize uint64, opts ...BatchMsgPaginateOption,
  368. ) (*BatchMsgPageList, error) {
  369. pager, err := newBatchMsgPager(opts)
  370. if err != nil {
  371. return nil, err
  372. }
  373. if bm, err = pager.ApplyFilter(bm); err != nil {
  374. return nil, err
  375. }
  376. ret := &BatchMsgPageList{}
  377. ret.PageDetails = &PageDetails{
  378. Page: pageNum,
  379. Size: pageSize,
  380. }
  381. query := bm.Clone()
  382. query.ctx.Fields = nil
  383. count, err := query.Count(ctx)
  384. if err != nil {
  385. return nil, err
  386. }
  387. ret.PageDetails.Total = uint64(count)
  388. if pager.Order != nil {
  389. bm = bm.Order(pager.Order)
  390. } else {
  391. bm = bm.Order(DefaultBatchMsgOrder)
  392. }
  393. bm = bm.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  394. list, err := bm.All(ctx)
  395. if err != nil {
  396. return nil, err
  397. }
  398. ret.List = list
  399. return ret, nil
  400. }
  401. type CategoryPager struct {
  402. Order category.OrderOption
  403. Filter func(*CategoryQuery) (*CategoryQuery, error)
  404. }
  405. // CategoryPaginateOption enables pagination customization.
  406. type CategoryPaginateOption func(*CategoryPager)
  407. // DefaultCategoryOrder is the default ordering of Category.
  408. var DefaultCategoryOrder = Desc(category.FieldID)
  409. func newCategoryPager(opts []CategoryPaginateOption) (*CategoryPager, error) {
  410. pager := &CategoryPager{}
  411. for _, opt := range opts {
  412. opt(pager)
  413. }
  414. if pager.Order == nil {
  415. pager.Order = DefaultCategoryOrder
  416. }
  417. return pager, nil
  418. }
  419. func (p *CategoryPager) ApplyFilter(query *CategoryQuery) (*CategoryQuery, error) {
  420. if p.Filter != nil {
  421. return p.Filter(query)
  422. }
  423. return query, nil
  424. }
  425. // CategoryPageList is Category PageList result.
  426. type CategoryPageList struct {
  427. List []*Category `json:"list"`
  428. PageDetails *PageDetails `json:"pageDetails"`
  429. }
  430. func (c *CategoryQuery) Page(
  431. ctx context.Context, pageNum uint64, pageSize uint64, opts ...CategoryPaginateOption,
  432. ) (*CategoryPageList, error) {
  433. pager, err := newCategoryPager(opts)
  434. if err != nil {
  435. return nil, err
  436. }
  437. if c, err = pager.ApplyFilter(c); err != nil {
  438. return nil, err
  439. }
  440. ret := &CategoryPageList{}
  441. ret.PageDetails = &PageDetails{
  442. Page: pageNum,
  443. Size: pageSize,
  444. }
  445. query := c.Clone()
  446. query.ctx.Fields = nil
  447. count, err := query.Count(ctx)
  448. if err != nil {
  449. return nil, err
  450. }
  451. ret.PageDetails.Total = uint64(count)
  452. if pager.Order != nil {
  453. c = c.Order(pager.Order)
  454. } else {
  455. c = c.Order(DefaultCategoryOrder)
  456. }
  457. c = c.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  458. list, err := c.All(ctx)
  459. if err != nil {
  460. return nil, err
  461. }
  462. ret.List = list
  463. return ret, nil
  464. }
  465. type ChatRecordsPager struct {
  466. Order chatrecords.OrderOption
  467. Filter func(*ChatRecordsQuery) (*ChatRecordsQuery, error)
  468. }
  469. // ChatRecordsPaginateOption enables pagination customization.
  470. type ChatRecordsPaginateOption func(*ChatRecordsPager)
  471. // DefaultChatRecordsOrder is the default ordering of ChatRecords.
  472. var DefaultChatRecordsOrder = Desc(chatrecords.FieldID)
  473. func newChatRecordsPager(opts []ChatRecordsPaginateOption) (*ChatRecordsPager, error) {
  474. pager := &ChatRecordsPager{}
  475. for _, opt := range opts {
  476. opt(pager)
  477. }
  478. if pager.Order == nil {
  479. pager.Order = DefaultChatRecordsOrder
  480. }
  481. return pager, nil
  482. }
  483. func (p *ChatRecordsPager) ApplyFilter(query *ChatRecordsQuery) (*ChatRecordsQuery, error) {
  484. if p.Filter != nil {
  485. return p.Filter(query)
  486. }
  487. return query, nil
  488. }
  489. // ChatRecordsPageList is ChatRecords PageList result.
  490. type ChatRecordsPageList struct {
  491. List []*ChatRecords `json:"list"`
  492. PageDetails *PageDetails `json:"pageDetails"`
  493. }
  494. func (cr *ChatRecordsQuery) Page(
  495. ctx context.Context, pageNum uint64, pageSize uint64, opts ...ChatRecordsPaginateOption,
  496. ) (*ChatRecordsPageList, error) {
  497. pager, err := newChatRecordsPager(opts)
  498. if err != nil {
  499. return nil, err
  500. }
  501. if cr, err = pager.ApplyFilter(cr); err != nil {
  502. return nil, err
  503. }
  504. ret := &ChatRecordsPageList{}
  505. ret.PageDetails = &PageDetails{
  506. Page: pageNum,
  507. Size: pageSize,
  508. }
  509. query := cr.Clone()
  510. query.ctx.Fields = nil
  511. count, err := query.Count(ctx)
  512. if err != nil {
  513. return nil, err
  514. }
  515. ret.PageDetails.Total = uint64(count)
  516. if pager.Order != nil {
  517. cr = cr.Order(pager.Order)
  518. } else {
  519. cr = cr.Order(DefaultChatRecordsOrder)
  520. }
  521. cr = cr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  522. list, err := cr.All(ctx)
  523. if err != nil {
  524. return nil, err
  525. }
  526. ret.List = list
  527. return ret, nil
  528. }
  529. type ChatSessionPager struct {
  530. Order chatsession.OrderOption
  531. Filter func(*ChatSessionQuery) (*ChatSessionQuery, error)
  532. }
  533. // ChatSessionPaginateOption enables pagination customization.
  534. type ChatSessionPaginateOption func(*ChatSessionPager)
  535. // DefaultChatSessionOrder is the default ordering of ChatSession.
  536. var DefaultChatSessionOrder = Desc(chatsession.FieldID)
  537. func newChatSessionPager(opts []ChatSessionPaginateOption) (*ChatSessionPager, error) {
  538. pager := &ChatSessionPager{}
  539. for _, opt := range opts {
  540. opt(pager)
  541. }
  542. if pager.Order == nil {
  543. pager.Order = DefaultChatSessionOrder
  544. }
  545. return pager, nil
  546. }
  547. func (p *ChatSessionPager) ApplyFilter(query *ChatSessionQuery) (*ChatSessionQuery, error) {
  548. if p.Filter != nil {
  549. return p.Filter(query)
  550. }
  551. return query, nil
  552. }
  553. // ChatSessionPageList is ChatSession PageList result.
  554. type ChatSessionPageList struct {
  555. List []*ChatSession `json:"list"`
  556. PageDetails *PageDetails `json:"pageDetails"`
  557. }
  558. func (cs *ChatSessionQuery) Page(
  559. ctx context.Context, pageNum uint64, pageSize uint64, opts ...ChatSessionPaginateOption,
  560. ) (*ChatSessionPageList, error) {
  561. pager, err := newChatSessionPager(opts)
  562. if err != nil {
  563. return nil, err
  564. }
  565. if cs, err = pager.ApplyFilter(cs); err != nil {
  566. return nil, err
  567. }
  568. ret := &ChatSessionPageList{}
  569. ret.PageDetails = &PageDetails{
  570. Page: pageNum,
  571. Size: pageSize,
  572. }
  573. query := cs.Clone()
  574. query.ctx.Fields = nil
  575. count, err := query.Count(ctx)
  576. if err != nil {
  577. return nil, err
  578. }
  579. ret.PageDetails.Total = uint64(count)
  580. if pager.Order != nil {
  581. cs = cs.Order(pager.Order)
  582. } else {
  583. cs = cs.Order(DefaultChatSessionOrder)
  584. }
  585. cs = cs.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  586. list, err := cs.All(ctx)
  587. if err != nil {
  588. return nil, err
  589. }
  590. ret.List = list
  591. return ret, nil
  592. }
  593. type ContactPager struct {
  594. Order contact.OrderOption
  595. Filter func(*ContactQuery) (*ContactQuery, error)
  596. }
  597. // ContactPaginateOption enables pagination customization.
  598. type ContactPaginateOption func(*ContactPager)
  599. // DefaultContactOrder is the default ordering of Contact.
  600. var DefaultContactOrder = Desc(contact.FieldID)
  601. func newContactPager(opts []ContactPaginateOption) (*ContactPager, error) {
  602. pager := &ContactPager{}
  603. for _, opt := range opts {
  604. opt(pager)
  605. }
  606. if pager.Order == nil {
  607. pager.Order = DefaultContactOrder
  608. }
  609. return pager, nil
  610. }
  611. func (p *ContactPager) ApplyFilter(query *ContactQuery) (*ContactQuery, error) {
  612. if p.Filter != nil {
  613. return p.Filter(query)
  614. }
  615. return query, nil
  616. }
  617. // ContactPageList is Contact PageList result.
  618. type ContactPageList struct {
  619. List []*Contact `json:"list"`
  620. PageDetails *PageDetails `json:"pageDetails"`
  621. }
  622. func (c *ContactQuery) Page(
  623. ctx context.Context, pageNum uint64, pageSize uint64, opts ...ContactPaginateOption,
  624. ) (*ContactPageList, error) {
  625. pager, err := newContactPager(opts)
  626. if err != nil {
  627. return nil, err
  628. }
  629. if c, err = pager.ApplyFilter(c); err != nil {
  630. return nil, err
  631. }
  632. ret := &ContactPageList{}
  633. ret.PageDetails = &PageDetails{
  634. Page: pageNum,
  635. Size: pageSize,
  636. }
  637. query := c.Clone()
  638. query.ctx.Fields = nil
  639. count, err := query.Count(ctx)
  640. if err != nil {
  641. return nil, err
  642. }
  643. ret.PageDetails.Total = uint64(count)
  644. if pager.Order != nil {
  645. c = c.Order(pager.Order)
  646. } else {
  647. c = c.Order(DefaultContactOrder)
  648. }
  649. c = c.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  650. list, err := c.All(ctx)
  651. if err != nil {
  652. return nil, err
  653. }
  654. ret.List = list
  655. return ret, nil
  656. }
  657. type CreditBalancePager struct {
  658. Order creditbalance.OrderOption
  659. Filter func(*CreditBalanceQuery) (*CreditBalanceQuery, error)
  660. }
  661. // CreditBalancePaginateOption enables pagination customization.
  662. type CreditBalancePaginateOption func(*CreditBalancePager)
  663. // DefaultCreditBalanceOrder is the default ordering of CreditBalance.
  664. var DefaultCreditBalanceOrder = Desc(creditbalance.FieldID)
  665. func newCreditBalancePager(opts []CreditBalancePaginateOption) (*CreditBalancePager, error) {
  666. pager := &CreditBalancePager{}
  667. for _, opt := range opts {
  668. opt(pager)
  669. }
  670. if pager.Order == nil {
  671. pager.Order = DefaultCreditBalanceOrder
  672. }
  673. return pager, nil
  674. }
  675. func (p *CreditBalancePager) ApplyFilter(query *CreditBalanceQuery) (*CreditBalanceQuery, error) {
  676. if p.Filter != nil {
  677. return p.Filter(query)
  678. }
  679. return query, nil
  680. }
  681. // CreditBalancePageList is CreditBalance PageList result.
  682. type CreditBalancePageList struct {
  683. List []*CreditBalance `json:"list"`
  684. PageDetails *PageDetails `json:"pageDetails"`
  685. }
  686. func (cb *CreditBalanceQuery) Page(
  687. ctx context.Context, pageNum uint64, pageSize uint64, opts ...CreditBalancePaginateOption,
  688. ) (*CreditBalancePageList, error) {
  689. pager, err := newCreditBalancePager(opts)
  690. if err != nil {
  691. return nil, err
  692. }
  693. if cb, err = pager.ApplyFilter(cb); err != nil {
  694. return nil, err
  695. }
  696. ret := &CreditBalancePageList{}
  697. ret.PageDetails = &PageDetails{
  698. Page: pageNum,
  699. Size: pageSize,
  700. }
  701. query := cb.Clone()
  702. query.ctx.Fields = nil
  703. count, err := query.Count(ctx)
  704. if err != nil {
  705. return nil, err
  706. }
  707. ret.PageDetails.Total = uint64(count)
  708. if pager.Order != nil {
  709. cb = cb.Order(pager.Order)
  710. } else {
  711. cb = cb.Order(DefaultCreditBalanceOrder)
  712. }
  713. cb = cb.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  714. list, err := cb.All(ctx)
  715. if err != nil {
  716. return nil, err
  717. }
  718. ret.List = list
  719. return ret, nil
  720. }
  721. type CreditUsagePager struct {
  722. Order creditusage.OrderOption
  723. Filter func(*CreditUsageQuery) (*CreditUsageQuery, error)
  724. }
  725. // CreditUsagePaginateOption enables pagination customization.
  726. type CreditUsagePaginateOption func(*CreditUsagePager)
  727. // DefaultCreditUsageOrder is the default ordering of CreditUsage.
  728. var DefaultCreditUsageOrder = Desc(creditusage.FieldID)
  729. func newCreditUsagePager(opts []CreditUsagePaginateOption) (*CreditUsagePager, error) {
  730. pager := &CreditUsagePager{}
  731. for _, opt := range opts {
  732. opt(pager)
  733. }
  734. if pager.Order == nil {
  735. pager.Order = DefaultCreditUsageOrder
  736. }
  737. return pager, nil
  738. }
  739. func (p *CreditUsagePager) ApplyFilter(query *CreditUsageQuery) (*CreditUsageQuery, error) {
  740. if p.Filter != nil {
  741. return p.Filter(query)
  742. }
  743. return query, nil
  744. }
  745. // CreditUsagePageList is CreditUsage PageList result.
  746. type CreditUsagePageList struct {
  747. List []*CreditUsage `json:"list"`
  748. PageDetails *PageDetails `json:"pageDetails"`
  749. }
  750. func (cu *CreditUsageQuery) Page(
  751. ctx context.Context, pageNum uint64, pageSize uint64, opts ...CreditUsagePaginateOption,
  752. ) (*CreditUsagePageList, error) {
  753. pager, err := newCreditUsagePager(opts)
  754. if err != nil {
  755. return nil, err
  756. }
  757. if cu, err = pager.ApplyFilter(cu); err != nil {
  758. return nil, err
  759. }
  760. ret := &CreditUsagePageList{}
  761. ret.PageDetails = &PageDetails{
  762. Page: pageNum,
  763. Size: pageSize,
  764. }
  765. query := cu.Clone()
  766. query.ctx.Fields = nil
  767. count, err := query.Count(ctx)
  768. if err != nil {
  769. return nil, err
  770. }
  771. ret.PageDetails.Total = uint64(count)
  772. if pager.Order != nil {
  773. cu = cu.Order(pager.Order)
  774. } else {
  775. cu = cu.Order(DefaultCreditUsageOrder)
  776. }
  777. cu = cu.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  778. list, err := cu.All(ctx)
  779. if err != nil {
  780. return nil, err
  781. }
  782. ret.List = list
  783. return ret, nil
  784. }
  785. type EmployeePager struct {
  786. Order employee.OrderOption
  787. Filter func(*EmployeeQuery) (*EmployeeQuery, error)
  788. }
  789. // EmployeePaginateOption enables pagination customization.
  790. type EmployeePaginateOption func(*EmployeePager)
  791. // DefaultEmployeeOrder is the default ordering of Employee.
  792. var DefaultEmployeeOrder = Desc(employee.FieldID)
  793. func newEmployeePager(opts []EmployeePaginateOption) (*EmployeePager, error) {
  794. pager := &EmployeePager{}
  795. for _, opt := range opts {
  796. opt(pager)
  797. }
  798. if pager.Order == nil {
  799. pager.Order = DefaultEmployeeOrder
  800. }
  801. return pager, nil
  802. }
  803. func (p *EmployeePager) ApplyFilter(query *EmployeeQuery) (*EmployeeQuery, error) {
  804. if p.Filter != nil {
  805. return p.Filter(query)
  806. }
  807. return query, nil
  808. }
  809. // EmployeePageList is Employee PageList result.
  810. type EmployeePageList struct {
  811. List []*Employee `json:"list"`
  812. PageDetails *PageDetails `json:"pageDetails"`
  813. }
  814. func (e *EmployeeQuery) Page(
  815. ctx context.Context, pageNum uint64, pageSize uint64, opts ...EmployeePaginateOption,
  816. ) (*EmployeePageList, error) {
  817. pager, err := newEmployeePager(opts)
  818. if err != nil {
  819. return nil, err
  820. }
  821. if e, err = pager.ApplyFilter(e); err != nil {
  822. return nil, err
  823. }
  824. ret := &EmployeePageList{}
  825. ret.PageDetails = &PageDetails{
  826. Page: pageNum,
  827. Size: pageSize,
  828. }
  829. query := e.Clone()
  830. query.ctx.Fields = nil
  831. count, err := query.Count(ctx)
  832. if err != nil {
  833. return nil, err
  834. }
  835. ret.PageDetails.Total = uint64(count)
  836. if pager.Order != nil {
  837. e = e.Order(pager.Order)
  838. } else {
  839. e = e.Order(DefaultEmployeeOrder)
  840. }
  841. e = e.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  842. list, err := e.All(ctx)
  843. if err != nil {
  844. return nil, err
  845. }
  846. ret.List = list
  847. return ret, nil
  848. }
  849. type EmployeeConfigPager struct {
  850. Order employeeconfig.OrderOption
  851. Filter func(*EmployeeConfigQuery) (*EmployeeConfigQuery, error)
  852. }
  853. // EmployeeConfigPaginateOption enables pagination customization.
  854. type EmployeeConfigPaginateOption func(*EmployeeConfigPager)
  855. // DefaultEmployeeConfigOrder is the default ordering of EmployeeConfig.
  856. var DefaultEmployeeConfigOrder = Desc(employeeconfig.FieldID)
  857. func newEmployeeConfigPager(opts []EmployeeConfigPaginateOption) (*EmployeeConfigPager, error) {
  858. pager := &EmployeeConfigPager{}
  859. for _, opt := range opts {
  860. opt(pager)
  861. }
  862. if pager.Order == nil {
  863. pager.Order = DefaultEmployeeConfigOrder
  864. }
  865. return pager, nil
  866. }
  867. func (p *EmployeeConfigPager) ApplyFilter(query *EmployeeConfigQuery) (*EmployeeConfigQuery, error) {
  868. if p.Filter != nil {
  869. return p.Filter(query)
  870. }
  871. return query, nil
  872. }
  873. // EmployeeConfigPageList is EmployeeConfig PageList result.
  874. type EmployeeConfigPageList struct {
  875. List []*EmployeeConfig `json:"list"`
  876. PageDetails *PageDetails `json:"pageDetails"`
  877. }
  878. func (ec *EmployeeConfigQuery) Page(
  879. ctx context.Context, pageNum uint64, pageSize uint64, opts ...EmployeeConfigPaginateOption,
  880. ) (*EmployeeConfigPageList, error) {
  881. pager, err := newEmployeeConfigPager(opts)
  882. if err != nil {
  883. return nil, err
  884. }
  885. if ec, err = pager.ApplyFilter(ec); err != nil {
  886. return nil, err
  887. }
  888. ret := &EmployeeConfigPageList{}
  889. ret.PageDetails = &PageDetails{
  890. Page: pageNum,
  891. Size: pageSize,
  892. }
  893. query := ec.Clone()
  894. query.ctx.Fields = nil
  895. count, err := query.Count(ctx)
  896. if err != nil {
  897. return nil, err
  898. }
  899. ret.PageDetails.Total = uint64(count)
  900. if pager.Order != nil {
  901. ec = ec.Order(pager.Order)
  902. } else {
  903. ec = ec.Order(DefaultEmployeeConfigOrder)
  904. }
  905. ec = ec.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  906. list, err := ec.All(ctx)
  907. if err != nil {
  908. return nil, err
  909. }
  910. ret.List = list
  911. return ret, nil
  912. }
  913. type LabelPager struct {
  914. Order label.OrderOption
  915. Filter func(*LabelQuery) (*LabelQuery, error)
  916. }
  917. // LabelPaginateOption enables pagination customization.
  918. type LabelPaginateOption func(*LabelPager)
  919. // DefaultLabelOrder is the default ordering of Label.
  920. var DefaultLabelOrder = Desc(label.FieldID)
  921. func newLabelPager(opts []LabelPaginateOption) (*LabelPager, error) {
  922. pager := &LabelPager{}
  923. for _, opt := range opts {
  924. opt(pager)
  925. }
  926. if pager.Order == nil {
  927. pager.Order = DefaultLabelOrder
  928. }
  929. return pager, nil
  930. }
  931. func (p *LabelPager) ApplyFilter(query *LabelQuery) (*LabelQuery, error) {
  932. if p.Filter != nil {
  933. return p.Filter(query)
  934. }
  935. return query, nil
  936. }
  937. // LabelPageList is Label PageList result.
  938. type LabelPageList struct {
  939. List []*Label `json:"list"`
  940. PageDetails *PageDetails `json:"pageDetails"`
  941. }
  942. func (l *LabelQuery) Page(
  943. ctx context.Context, pageNum uint64, pageSize uint64, opts ...LabelPaginateOption,
  944. ) (*LabelPageList, error) {
  945. pager, err := newLabelPager(opts)
  946. if err != nil {
  947. return nil, err
  948. }
  949. if l, err = pager.ApplyFilter(l); err != nil {
  950. return nil, err
  951. }
  952. ret := &LabelPageList{}
  953. ret.PageDetails = &PageDetails{
  954. Page: pageNum,
  955. Size: pageSize,
  956. }
  957. query := l.Clone()
  958. query.ctx.Fields = nil
  959. count, err := query.Count(ctx)
  960. if err != nil {
  961. return nil, err
  962. }
  963. ret.PageDetails.Total = uint64(count)
  964. if pager.Order != nil {
  965. l = l.Order(pager.Order)
  966. } else {
  967. l = l.Order(DefaultLabelOrder)
  968. }
  969. l = l.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  970. list, err := l.All(ctx)
  971. if err != nil {
  972. return nil, err
  973. }
  974. ret.List = list
  975. return ret, nil
  976. }
  977. type LabelRelationshipPager struct {
  978. Order labelrelationship.OrderOption
  979. Filter func(*LabelRelationshipQuery) (*LabelRelationshipQuery, error)
  980. }
  981. // LabelRelationshipPaginateOption enables pagination customization.
  982. type LabelRelationshipPaginateOption func(*LabelRelationshipPager)
  983. // DefaultLabelRelationshipOrder is the default ordering of LabelRelationship.
  984. var DefaultLabelRelationshipOrder = Desc(labelrelationship.FieldID)
  985. func newLabelRelationshipPager(opts []LabelRelationshipPaginateOption) (*LabelRelationshipPager, error) {
  986. pager := &LabelRelationshipPager{}
  987. for _, opt := range opts {
  988. opt(pager)
  989. }
  990. if pager.Order == nil {
  991. pager.Order = DefaultLabelRelationshipOrder
  992. }
  993. return pager, nil
  994. }
  995. func (p *LabelRelationshipPager) ApplyFilter(query *LabelRelationshipQuery) (*LabelRelationshipQuery, error) {
  996. if p.Filter != nil {
  997. return p.Filter(query)
  998. }
  999. return query, nil
  1000. }
  1001. // LabelRelationshipPageList is LabelRelationship PageList result.
  1002. type LabelRelationshipPageList struct {
  1003. List []*LabelRelationship `json:"list"`
  1004. PageDetails *PageDetails `json:"pageDetails"`
  1005. }
  1006. func (lr *LabelRelationshipQuery) Page(
  1007. ctx context.Context, pageNum uint64, pageSize uint64, opts ...LabelRelationshipPaginateOption,
  1008. ) (*LabelRelationshipPageList, error) {
  1009. pager, err := newLabelRelationshipPager(opts)
  1010. if err != nil {
  1011. return nil, err
  1012. }
  1013. if lr, err = pager.ApplyFilter(lr); err != nil {
  1014. return nil, err
  1015. }
  1016. ret := &LabelRelationshipPageList{}
  1017. ret.PageDetails = &PageDetails{
  1018. Page: pageNum,
  1019. Size: pageSize,
  1020. }
  1021. query := lr.Clone()
  1022. query.ctx.Fields = nil
  1023. count, err := query.Count(ctx)
  1024. if err != nil {
  1025. return nil, err
  1026. }
  1027. ret.PageDetails.Total = uint64(count)
  1028. if pager.Order != nil {
  1029. lr = lr.Order(pager.Order)
  1030. } else {
  1031. lr = lr.Order(DefaultLabelRelationshipOrder)
  1032. }
  1033. lr = lr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1034. list, err := lr.All(ctx)
  1035. if err != nil {
  1036. return nil, err
  1037. }
  1038. ret.List = list
  1039. return ret, nil
  1040. }
  1041. type MessagePager struct {
  1042. Order message.OrderOption
  1043. Filter func(*MessageQuery) (*MessageQuery, error)
  1044. }
  1045. // MessagePaginateOption enables pagination customization.
  1046. type MessagePaginateOption func(*MessagePager)
  1047. // DefaultMessageOrder is the default ordering of Message.
  1048. var DefaultMessageOrder = Desc(message.FieldID)
  1049. func newMessagePager(opts []MessagePaginateOption) (*MessagePager, error) {
  1050. pager := &MessagePager{}
  1051. for _, opt := range opts {
  1052. opt(pager)
  1053. }
  1054. if pager.Order == nil {
  1055. pager.Order = DefaultMessageOrder
  1056. }
  1057. return pager, nil
  1058. }
  1059. func (p *MessagePager) ApplyFilter(query *MessageQuery) (*MessageQuery, error) {
  1060. if p.Filter != nil {
  1061. return p.Filter(query)
  1062. }
  1063. return query, nil
  1064. }
  1065. // MessagePageList is Message PageList result.
  1066. type MessagePageList struct {
  1067. List []*Message `json:"list"`
  1068. PageDetails *PageDetails `json:"pageDetails"`
  1069. }
  1070. func (m *MessageQuery) Page(
  1071. ctx context.Context, pageNum uint64, pageSize uint64, opts ...MessagePaginateOption,
  1072. ) (*MessagePageList, error) {
  1073. pager, err := newMessagePager(opts)
  1074. if err != nil {
  1075. return nil, err
  1076. }
  1077. if m, err = pager.ApplyFilter(m); err != nil {
  1078. return nil, err
  1079. }
  1080. ret := &MessagePageList{}
  1081. ret.PageDetails = &PageDetails{
  1082. Page: pageNum,
  1083. Size: pageSize,
  1084. }
  1085. query := m.Clone()
  1086. query.ctx.Fields = nil
  1087. count, err := query.Count(ctx)
  1088. if err != nil {
  1089. return nil, err
  1090. }
  1091. ret.PageDetails.Total = uint64(count)
  1092. if pager.Order != nil {
  1093. m = m.Order(pager.Order)
  1094. } else {
  1095. m = m.Order(DefaultMessageOrder)
  1096. }
  1097. m = m.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1098. list, err := m.All(ctx)
  1099. if err != nil {
  1100. return nil, err
  1101. }
  1102. ret.List = list
  1103. return ret, nil
  1104. }
  1105. type MessageRecordsPager struct {
  1106. Order messagerecords.OrderOption
  1107. Filter func(*MessageRecordsQuery) (*MessageRecordsQuery, error)
  1108. }
  1109. // MessageRecordsPaginateOption enables pagination customization.
  1110. type MessageRecordsPaginateOption func(*MessageRecordsPager)
  1111. // DefaultMessageRecordsOrder is the default ordering of MessageRecords.
  1112. var DefaultMessageRecordsOrder = Desc(messagerecords.FieldID)
  1113. func newMessageRecordsPager(opts []MessageRecordsPaginateOption) (*MessageRecordsPager, error) {
  1114. pager := &MessageRecordsPager{}
  1115. for _, opt := range opts {
  1116. opt(pager)
  1117. }
  1118. if pager.Order == nil {
  1119. pager.Order = DefaultMessageRecordsOrder
  1120. }
  1121. return pager, nil
  1122. }
  1123. func (p *MessageRecordsPager) ApplyFilter(query *MessageRecordsQuery) (*MessageRecordsQuery, error) {
  1124. if p.Filter != nil {
  1125. return p.Filter(query)
  1126. }
  1127. return query, nil
  1128. }
  1129. // MessageRecordsPageList is MessageRecords PageList result.
  1130. type MessageRecordsPageList struct {
  1131. List []*MessageRecords `json:"list"`
  1132. PageDetails *PageDetails `json:"pageDetails"`
  1133. }
  1134. func (mr *MessageRecordsQuery) Page(
  1135. ctx context.Context, pageNum uint64, pageSize uint64, opts ...MessageRecordsPaginateOption,
  1136. ) (*MessageRecordsPageList, error) {
  1137. pager, err := newMessageRecordsPager(opts)
  1138. if err != nil {
  1139. return nil, err
  1140. }
  1141. if mr, err = pager.ApplyFilter(mr); err != nil {
  1142. return nil, err
  1143. }
  1144. ret := &MessageRecordsPageList{}
  1145. ret.PageDetails = &PageDetails{
  1146. Page: pageNum,
  1147. Size: pageSize,
  1148. }
  1149. query := mr.Clone()
  1150. query.ctx.Fields = nil
  1151. count, err := query.Count(ctx)
  1152. if err != nil {
  1153. return nil, err
  1154. }
  1155. ret.PageDetails.Total = uint64(count)
  1156. if pager.Order != nil {
  1157. mr = mr.Order(pager.Order)
  1158. } else {
  1159. mr = mr.Order(DefaultMessageRecordsOrder)
  1160. }
  1161. mr = mr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1162. list, err := mr.All(ctx)
  1163. if err != nil {
  1164. return nil, err
  1165. }
  1166. ret.List = list
  1167. return ret, nil
  1168. }
  1169. type MsgPager struct {
  1170. Order msg.OrderOption
  1171. Filter func(*MsgQuery) (*MsgQuery, error)
  1172. }
  1173. // MsgPaginateOption enables pagination customization.
  1174. type MsgPaginateOption func(*MsgPager)
  1175. // DefaultMsgOrder is the default ordering of Msg.
  1176. var DefaultMsgOrder = Desc(msg.FieldID)
  1177. func newMsgPager(opts []MsgPaginateOption) (*MsgPager, error) {
  1178. pager := &MsgPager{}
  1179. for _, opt := range opts {
  1180. opt(pager)
  1181. }
  1182. if pager.Order == nil {
  1183. pager.Order = DefaultMsgOrder
  1184. }
  1185. return pager, nil
  1186. }
  1187. func (p *MsgPager) ApplyFilter(query *MsgQuery) (*MsgQuery, error) {
  1188. if p.Filter != nil {
  1189. return p.Filter(query)
  1190. }
  1191. return query, nil
  1192. }
  1193. // MsgPageList is Msg PageList result.
  1194. type MsgPageList struct {
  1195. List []*Msg `json:"list"`
  1196. PageDetails *PageDetails `json:"pageDetails"`
  1197. }
  1198. func (m *MsgQuery) Page(
  1199. ctx context.Context, pageNum uint64, pageSize uint64, opts ...MsgPaginateOption,
  1200. ) (*MsgPageList, error) {
  1201. pager, err := newMsgPager(opts)
  1202. if err != nil {
  1203. return nil, err
  1204. }
  1205. if m, err = pager.ApplyFilter(m); err != nil {
  1206. return nil, err
  1207. }
  1208. ret := &MsgPageList{}
  1209. ret.PageDetails = &PageDetails{
  1210. Page: pageNum,
  1211. Size: pageSize,
  1212. }
  1213. query := m.Clone()
  1214. query.ctx.Fields = nil
  1215. count, err := query.Count(ctx)
  1216. if err != nil {
  1217. return nil, err
  1218. }
  1219. ret.PageDetails.Total = uint64(count)
  1220. if pager.Order != nil {
  1221. m = m.Order(pager.Order)
  1222. } else {
  1223. m = m.Order(DefaultMsgOrder)
  1224. }
  1225. m = m.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1226. list, err := m.All(ctx)
  1227. if err != nil {
  1228. return nil, err
  1229. }
  1230. ret.List = list
  1231. return ret, nil
  1232. }
  1233. type PayRechargePager struct {
  1234. Order payrecharge.OrderOption
  1235. Filter func(*PayRechargeQuery) (*PayRechargeQuery, error)
  1236. }
  1237. // PayRechargePaginateOption enables pagination customization.
  1238. type PayRechargePaginateOption func(*PayRechargePager)
  1239. // DefaultPayRechargeOrder is the default ordering of PayRecharge.
  1240. var DefaultPayRechargeOrder = Desc(payrecharge.FieldID)
  1241. func newPayRechargePager(opts []PayRechargePaginateOption) (*PayRechargePager, error) {
  1242. pager := &PayRechargePager{}
  1243. for _, opt := range opts {
  1244. opt(pager)
  1245. }
  1246. if pager.Order == nil {
  1247. pager.Order = DefaultPayRechargeOrder
  1248. }
  1249. return pager, nil
  1250. }
  1251. func (p *PayRechargePager) ApplyFilter(query *PayRechargeQuery) (*PayRechargeQuery, error) {
  1252. if p.Filter != nil {
  1253. return p.Filter(query)
  1254. }
  1255. return query, nil
  1256. }
  1257. // PayRechargePageList is PayRecharge PageList result.
  1258. type PayRechargePageList struct {
  1259. List []*PayRecharge `json:"list"`
  1260. PageDetails *PageDetails `json:"pageDetails"`
  1261. }
  1262. func (pr *PayRechargeQuery) Page(
  1263. ctx context.Context, pageNum uint64, pageSize uint64, opts ...PayRechargePaginateOption,
  1264. ) (*PayRechargePageList, error) {
  1265. pager, err := newPayRechargePager(opts)
  1266. if err != nil {
  1267. return nil, err
  1268. }
  1269. if pr, err = pager.ApplyFilter(pr); err != nil {
  1270. return nil, err
  1271. }
  1272. ret := &PayRechargePageList{}
  1273. ret.PageDetails = &PageDetails{
  1274. Page: pageNum,
  1275. Size: pageSize,
  1276. }
  1277. query := pr.Clone()
  1278. query.ctx.Fields = nil
  1279. count, err := query.Count(ctx)
  1280. if err != nil {
  1281. return nil, err
  1282. }
  1283. ret.PageDetails.Total = uint64(count)
  1284. if pager.Order != nil {
  1285. pr = pr.Order(pager.Order)
  1286. } else {
  1287. pr = pr.Order(DefaultPayRechargeOrder)
  1288. }
  1289. pr = pr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1290. list, err := pr.All(ctx)
  1291. if err != nil {
  1292. return nil, err
  1293. }
  1294. ret.List = list
  1295. return ret, nil
  1296. }
  1297. type ServerPager struct {
  1298. Order server.OrderOption
  1299. Filter func(*ServerQuery) (*ServerQuery, error)
  1300. }
  1301. // ServerPaginateOption enables pagination customization.
  1302. type ServerPaginateOption func(*ServerPager)
  1303. // DefaultServerOrder is the default ordering of Server.
  1304. var DefaultServerOrder = Desc(server.FieldID)
  1305. func newServerPager(opts []ServerPaginateOption) (*ServerPager, error) {
  1306. pager := &ServerPager{}
  1307. for _, opt := range opts {
  1308. opt(pager)
  1309. }
  1310. if pager.Order == nil {
  1311. pager.Order = DefaultServerOrder
  1312. }
  1313. return pager, nil
  1314. }
  1315. func (p *ServerPager) ApplyFilter(query *ServerQuery) (*ServerQuery, error) {
  1316. if p.Filter != nil {
  1317. return p.Filter(query)
  1318. }
  1319. return query, nil
  1320. }
  1321. // ServerPageList is Server PageList result.
  1322. type ServerPageList struct {
  1323. List []*Server `json:"list"`
  1324. PageDetails *PageDetails `json:"pageDetails"`
  1325. }
  1326. func (s *ServerQuery) Page(
  1327. ctx context.Context, pageNum uint64, pageSize uint64, opts ...ServerPaginateOption,
  1328. ) (*ServerPageList, error) {
  1329. pager, err := newServerPager(opts)
  1330. if err != nil {
  1331. return nil, err
  1332. }
  1333. if s, err = pager.ApplyFilter(s); err != nil {
  1334. return nil, err
  1335. }
  1336. ret := &ServerPageList{}
  1337. ret.PageDetails = &PageDetails{
  1338. Page: pageNum,
  1339. Size: pageSize,
  1340. }
  1341. query := s.Clone()
  1342. query.ctx.Fields = nil
  1343. count, err := query.Count(ctx)
  1344. if err != nil {
  1345. return nil, err
  1346. }
  1347. ret.PageDetails.Total = uint64(count)
  1348. if pager.Order != nil {
  1349. s = s.Order(pager.Order)
  1350. } else {
  1351. s = s.Order(DefaultServerOrder)
  1352. }
  1353. s = s.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1354. list, err := s.All(ctx)
  1355. if err != nil {
  1356. return nil, err
  1357. }
  1358. ret.List = list
  1359. return ret, nil
  1360. }
  1361. type SopNodePager struct {
  1362. Order sopnode.OrderOption
  1363. Filter func(*SopNodeQuery) (*SopNodeQuery, error)
  1364. }
  1365. // SopNodePaginateOption enables pagination customization.
  1366. type SopNodePaginateOption func(*SopNodePager)
  1367. // DefaultSopNodeOrder is the default ordering of SopNode.
  1368. var DefaultSopNodeOrder = Desc(sopnode.FieldID)
  1369. func newSopNodePager(opts []SopNodePaginateOption) (*SopNodePager, error) {
  1370. pager := &SopNodePager{}
  1371. for _, opt := range opts {
  1372. opt(pager)
  1373. }
  1374. if pager.Order == nil {
  1375. pager.Order = DefaultSopNodeOrder
  1376. }
  1377. return pager, nil
  1378. }
  1379. func (p *SopNodePager) ApplyFilter(query *SopNodeQuery) (*SopNodeQuery, error) {
  1380. if p.Filter != nil {
  1381. return p.Filter(query)
  1382. }
  1383. return query, nil
  1384. }
  1385. // SopNodePageList is SopNode PageList result.
  1386. type SopNodePageList struct {
  1387. List []*SopNode `json:"list"`
  1388. PageDetails *PageDetails `json:"pageDetails"`
  1389. }
  1390. func (sn *SopNodeQuery) Page(
  1391. ctx context.Context, pageNum uint64, pageSize uint64, opts ...SopNodePaginateOption,
  1392. ) (*SopNodePageList, error) {
  1393. pager, err := newSopNodePager(opts)
  1394. if err != nil {
  1395. return nil, err
  1396. }
  1397. if sn, err = pager.ApplyFilter(sn); err != nil {
  1398. return nil, err
  1399. }
  1400. ret := &SopNodePageList{}
  1401. ret.PageDetails = &PageDetails{
  1402. Page: pageNum,
  1403. Size: pageSize,
  1404. }
  1405. query := sn.Clone()
  1406. query.ctx.Fields = nil
  1407. count, err := query.Count(ctx)
  1408. if err != nil {
  1409. return nil, err
  1410. }
  1411. ret.PageDetails.Total = uint64(count)
  1412. if pager.Order != nil {
  1413. sn = sn.Order(pager.Order)
  1414. } else {
  1415. sn = sn.Order(DefaultSopNodeOrder)
  1416. }
  1417. sn = sn.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1418. list, err := sn.All(ctx)
  1419. if err != nil {
  1420. return nil, err
  1421. }
  1422. ret.List = list
  1423. return ret, nil
  1424. }
  1425. type SopStagePager struct {
  1426. Order sopstage.OrderOption
  1427. Filter func(*SopStageQuery) (*SopStageQuery, error)
  1428. }
  1429. // SopStagePaginateOption enables pagination customization.
  1430. type SopStagePaginateOption func(*SopStagePager)
  1431. // DefaultSopStageOrder is the default ordering of SopStage.
  1432. var DefaultSopStageOrder = Desc(sopstage.FieldID)
  1433. func newSopStagePager(opts []SopStagePaginateOption) (*SopStagePager, error) {
  1434. pager := &SopStagePager{}
  1435. for _, opt := range opts {
  1436. opt(pager)
  1437. }
  1438. if pager.Order == nil {
  1439. pager.Order = DefaultSopStageOrder
  1440. }
  1441. return pager, nil
  1442. }
  1443. func (p *SopStagePager) ApplyFilter(query *SopStageQuery) (*SopStageQuery, error) {
  1444. if p.Filter != nil {
  1445. return p.Filter(query)
  1446. }
  1447. return query, nil
  1448. }
  1449. // SopStagePageList is SopStage PageList result.
  1450. type SopStagePageList struct {
  1451. List []*SopStage `json:"list"`
  1452. PageDetails *PageDetails `json:"pageDetails"`
  1453. }
  1454. func (ss *SopStageQuery) Page(
  1455. ctx context.Context, pageNum uint64, pageSize uint64, opts ...SopStagePaginateOption,
  1456. ) (*SopStagePageList, error) {
  1457. pager, err := newSopStagePager(opts)
  1458. if err != nil {
  1459. return nil, err
  1460. }
  1461. if ss, err = pager.ApplyFilter(ss); err != nil {
  1462. return nil, err
  1463. }
  1464. ret := &SopStagePageList{}
  1465. ret.PageDetails = &PageDetails{
  1466. Page: pageNum,
  1467. Size: pageSize,
  1468. }
  1469. query := ss.Clone()
  1470. query.ctx.Fields = nil
  1471. count, err := query.Count(ctx)
  1472. if err != nil {
  1473. return nil, err
  1474. }
  1475. ret.PageDetails.Total = uint64(count)
  1476. if pager.Order != nil {
  1477. ss = ss.Order(pager.Order)
  1478. } else {
  1479. ss = ss.Order(DefaultSopStageOrder)
  1480. }
  1481. ss = ss.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1482. list, err := ss.All(ctx)
  1483. if err != nil {
  1484. return nil, err
  1485. }
  1486. ret.List = list
  1487. return ret, nil
  1488. }
  1489. type SopTaskPager struct {
  1490. Order soptask.OrderOption
  1491. Filter func(*SopTaskQuery) (*SopTaskQuery, error)
  1492. }
  1493. // SopTaskPaginateOption enables pagination customization.
  1494. type SopTaskPaginateOption func(*SopTaskPager)
  1495. // DefaultSopTaskOrder is the default ordering of SopTask.
  1496. var DefaultSopTaskOrder = Desc(soptask.FieldID)
  1497. func newSopTaskPager(opts []SopTaskPaginateOption) (*SopTaskPager, error) {
  1498. pager := &SopTaskPager{}
  1499. for _, opt := range opts {
  1500. opt(pager)
  1501. }
  1502. if pager.Order == nil {
  1503. pager.Order = DefaultSopTaskOrder
  1504. }
  1505. return pager, nil
  1506. }
  1507. func (p *SopTaskPager) ApplyFilter(query *SopTaskQuery) (*SopTaskQuery, error) {
  1508. if p.Filter != nil {
  1509. return p.Filter(query)
  1510. }
  1511. return query, nil
  1512. }
  1513. // SopTaskPageList is SopTask PageList result.
  1514. type SopTaskPageList struct {
  1515. List []*SopTask `json:"list"`
  1516. PageDetails *PageDetails `json:"pageDetails"`
  1517. }
  1518. func (st *SopTaskQuery) Page(
  1519. ctx context.Context, pageNum uint64, pageSize uint64, opts ...SopTaskPaginateOption,
  1520. ) (*SopTaskPageList, error) {
  1521. pager, err := newSopTaskPager(opts)
  1522. if err != nil {
  1523. return nil, err
  1524. }
  1525. if st, err = pager.ApplyFilter(st); err != nil {
  1526. return nil, err
  1527. }
  1528. ret := &SopTaskPageList{}
  1529. ret.PageDetails = &PageDetails{
  1530. Page: pageNum,
  1531. Size: pageSize,
  1532. }
  1533. query := st.Clone()
  1534. query.ctx.Fields = nil
  1535. count, err := query.Count(ctx)
  1536. if err != nil {
  1537. return nil, err
  1538. }
  1539. ret.PageDetails.Total = uint64(count)
  1540. if pager.Order != nil {
  1541. st = st.Order(pager.Order)
  1542. } else {
  1543. st = st.Order(DefaultSopTaskOrder)
  1544. }
  1545. st = st.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1546. list, err := st.All(ctx)
  1547. if err != nil {
  1548. return nil, err
  1549. }
  1550. ret.List = list
  1551. return ret, nil
  1552. }
  1553. type TokenPager struct {
  1554. Order token.OrderOption
  1555. Filter func(*TokenQuery) (*TokenQuery, error)
  1556. }
  1557. // TokenPaginateOption enables pagination customization.
  1558. type TokenPaginateOption func(*TokenPager)
  1559. // DefaultTokenOrder is the default ordering of Token.
  1560. var DefaultTokenOrder = Desc(token.FieldID)
  1561. func newTokenPager(opts []TokenPaginateOption) (*TokenPager, error) {
  1562. pager := &TokenPager{}
  1563. for _, opt := range opts {
  1564. opt(pager)
  1565. }
  1566. if pager.Order == nil {
  1567. pager.Order = DefaultTokenOrder
  1568. }
  1569. return pager, nil
  1570. }
  1571. func (p *TokenPager) ApplyFilter(query *TokenQuery) (*TokenQuery, error) {
  1572. if p.Filter != nil {
  1573. return p.Filter(query)
  1574. }
  1575. return query, nil
  1576. }
  1577. // TokenPageList is Token PageList result.
  1578. type TokenPageList struct {
  1579. List []*Token `json:"list"`
  1580. PageDetails *PageDetails `json:"pageDetails"`
  1581. }
  1582. func (t *TokenQuery) Page(
  1583. ctx context.Context, pageNum uint64, pageSize uint64, opts ...TokenPaginateOption,
  1584. ) (*TokenPageList, error) {
  1585. pager, err := newTokenPager(opts)
  1586. if err != nil {
  1587. return nil, err
  1588. }
  1589. if t, err = pager.ApplyFilter(t); err != nil {
  1590. return nil, err
  1591. }
  1592. ret := &TokenPageList{}
  1593. ret.PageDetails = &PageDetails{
  1594. Page: pageNum,
  1595. Size: pageSize,
  1596. }
  1597. query := t.Clone()
  1598. query.ctx.Fields = nil
  1599. count, err := query.Count(ctx)
  1600. if err != nil {
  1601. return nil, err
  1602. }
  1603. ret.PageDetails.Total = uint64(count)
  1604. if pager.Order != nil {
  1605. t = t.Order(pager.Order)
  1606. } else {
  1607. t = t.Order(DefaultTokenOrder)
  1608. }
  1609. t = t.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1610. list, err := t.All(ctx)
  1611. if err != nil {
  1612. return nil, err
  1613. }
  1614. ret.List = list
  1615. return ret, nil
  1616. }
  1617. type TutorialPager struct {
  1618. Order tutorial.OrderOption
  1619. Filter func(*TutorialQuery) (*TutorialQuery, error)
  1620. }
  1621. // TutorialPaginateOption enables pagination customization.
  1622. type TutorialPaginateOption func(*TutorialPager)
  1623. // DefaultTutorialOrder is the default ordering of Tutorial.
  1624. var DefaultTutorialOrder = Desc(tutorial.FieldID)
  1625. func newTutorialPager(opts []TutorialPaginateOption) (*TutorialPager, error) {
  1626. pager := &TutorialPager{}
  1627. for _, opt := range opts {
  1628. opt(pager)
  1629. }
  1630. if pager.Order == nil {
  1631. pager.Order = DefaultTutorialOrder
  1632. }
  1633. return pager, nil
  1634. }
  1635. func (p *TutorialPager) ApplyFilter(query *TutorialQuery) (*TutorialQuery, error) {
  1636. if p.Filter != nil {
  1637. return p.Filter(query)
  1638. }
  1639. return query, nil
  1640. }
  1641. // TutorialPageList is Tutorial PageList result.
  1642. type TutorialPageList struct {
  1643. List []*Tutorial `json:"list"`
  1644. PageDetails *PageDetails `json:"pageDetails"`
  1645. }
  1646. func (t *TutorialQuery) Page(
  1647. ctx context.Context, pageNum uint64, pageSize uint64, opts ...TutorialPaginateOption,
  1648. ) (*TutorialPageList, error) {
  1649. pager, err := newTutorialPager(opts)
  1650. if err != nil {
  1651. return nil, err
  1652. }
  1653. if t, err = pager.ApplyFilter(t); err != nil {
  1654. return nil, err
  1655. }
  1656. ret := &TutorialPageList{}
  1657. ret.PageDetails = &PageDetails{
  1658. Page: pageNum,
  1659. Size: pageSize,
  1660. }
  1661. query := t.Clone()
  1662. query.ctx.Fields = nil
  1663. count, err := query.Count(ctx)
  1664. if err != nil {
  1665. return nil, err
  1666. }
  1667. ret.PageDetails.Total = uint64(count)
  1668. if pager.Order != nil {
  1669. t = t.Order(pager.Order)
  1670. } else {
  1671. t = t.Order(DefaultTutorialOrder)
  1672. }
  1673. t = t.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1674. list, err := t.All(ctx)
  1675. if err != nil {
  1676. return nil, err
  1677. }
  1678. ret.List = list
  1679. return ret, nil
  1680. }
  1681. type UsageDetailPager struct {
  1682. Order usagedetail.OrderOption
  1683. Filter func(*UsageDetailQuery) (*UsageDetailQuery, error)
  1684. }
  1685. // UsageDetailPaginateOption enables pagination customization.
  1686. type UsageDetailPaginateOption func(*UsageDetailPager)
  1687. // DefaultUsageDetailOrder is the default ordering of UsageDetail.
  1688. var DefaultUsageDetailOrder = Desc(usagedetail.FieldID)
  1689. func newUsageDetailPager(opts []UsageDetailPaginateOption) (*UsageDetailPager, error) {
  1690. pager := &UsageDetailPager{}
  1691. for _, opt := range opts {
  1692. opt(pager)
  1693. }
  1694. if pager.Order == nil {
  1695. pager.Order = DefaultUsageDetailOrder
  1696. }
  1697. return pager, nil
  1698. }
  1699. func (p *UsageDetailPager) ApplyFilter(query *UsageDetailQuery) (*UsageDetailQuery, error) {
  1700. if p.Filter != nil {
  1701. return p.Filter(query)
  1702. }
  1703. return query, nil
  1704. }
  1705. // UsageDetailPageList is UsageDetail PageList result.
  1706. type UsageDetailPageList struct {
  1707. List []*UsageDetail `json:"list"`
  1708. PageDetails *PageDetails `json:"pageDetails"`
  1709. }
  1710. func (ud *UsageDetailQuery) Page(
  1711. ctx context.Context, pageNum uint64, pageSize uint64, opts ...UsageDetailPaginateOption,
  1712. ) (*UsageDetailPageList, error) {
  1713. pager, err := newUsageDetailPager(opts)
  1714. if err != nil {
  1715. return nil, err
  1716. }
  1717. if ud, err = pager.ApplyFilter(ud); err != nil {
  1718. return nil, err
  1719. }
  1720. ret := &UsageDetailPageList{}
  1721. ret.PageDetails = &PageDetails{
  1722. Page: pageNum,
  1723. Size: pageSize,
  1724. }
  1725. query := ud.Clone()
  1726. query.ctx.Fields = nil
  1727. count, err := query.Count(ctx)
  1728. if err != nil {
  1729. return nil, err
  1730. }
  1731. ret.PageDetails.Total = uint64(count)
  1732. if pager.Order != nil {
  1733. ud = ud.Order(pager.Order)
  1734. } else {
  1735. ud = ud.Order(DefaultUsageDetailOrder)
  1736. }
  1737. ud = ud.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1738. list, err := ud.All(ctx)
  1739. if err != nil {
  1740. return nil, err
  1741. }
  1742. ret.List = list
  1743. return ret, nil
  1744. }
  1745. type UsageStatisticDayPager struct {
  1746. Order usagestatisticday.OrderOption
  1747. Filter func(*UsageStatisticDayQuery) (*UsageStatisticDayQuery, error)
  1748. }
  1749. // UsageStatisticDayPaginateOption enables pagination customization.
  1750. type UsageStatisticDayPaginateOption func(*UsageStatisticDayPager)
  1751. // DefaultUsageStatisticDayOrder is the default ordering of UsageStatisticDay.
  1752. var DefaultUsageStatisticDayOrder = Desc(usagestatisticday.FieldID)
  1753. func newUsageStatisticDayPager(opts []UsageStatisticDayPaginateOption) (*UsageStatisticDayPager, error) {
  1754. pager := &UsageStatisticDayPager{}
  1755. for _, opt := range opts {
  1756. opt(pager)
  1757. }
  1758. if pager.Order == nil {
  1759. pager.Order = DefaultUsageStatisticDayOrder
  1760. }
  1761. return pager, nil
  1762. }
  1763. func (p *UsageStatisticDayPager) ApplyFilter(query *UsageStatisticDayQuery) (*UsageStatisticDayQuery, error) {
  1764. if p.Filter != nil {
  1765. return p.Filter(query)
  1766. }
  1767. return query, nil
  1768. }
  1769. // UsageStatisticDayPageList is UsageStatisticDay PageList result.
  1770. type UsageStatisticDayPageList struct {
  1771. List []*UsageStatisticDay `json:"list"`
  1772. PageDetails *PageDetails `json:"pageDetails"`
  1773. }
  1774. func (usd *UsageStatisticDayQuery) Page(
  1775. ctx context.Context, pageNum uint64, pageSize uint64, opts ...UsageStatisticDayPaginateOption,
  1776. ) (*UsageStatisticDayPageList, error) {
  1777. pager, err := newUsageStatisticDayPager(opts)
  1778. if err != nil {
  1779. return nil, err
  1780. }
  1781. if usd, err = pager.ApplyFilter(usd); err != nil {
  1782. return nil, err
  1783. }
  1784. ret := &UsageStatisticDayPageList{}
  1785. ret.PageDetails = &PageDetails{
  1786. Page: pageNum,
  1787. Size: pageSize,
  1788. }
  1789. query := usd.Clone()
  1790. query.ctx.Fields = nil
  1791. count, err := query.Count(ctx)
  1792. if err != nil {
  1793. return nil, err
  1794. }
  1795. ret.PageDetails.Total = uint64(count)
  1796. if pager.Order != nil {
  1797. usd = usd.Order(pager.Order)
  1798. } else {
  1799. usd = usd.Order(DefaultUsageStatisticDayOrder)
  1800. }
  1801. usd = usd.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1802. list, err := usd.All(ctx)
  1803. if err != nil {
  1804. return nil, err
  1805. }
  1806. ret.List = list
  1807. return ret, nil
  1808. }
  1809. type UsageStatisticHourPager struct {
  1810. Order usagestatistichour.OrderOption
  1811. Filter func(*UsageStatisticHourQuery) (*UsageStatisticHourQuery, error)
  1812. }
  1813. // UsageStatisticHourPaginateOption enables pagination customization.
  1814. type UsageStatisticHourPaginateOption func(*UsageStatisticHourPager)
  1815. // DefaultUsageStatisticHourOrder is the default ordering of UsageStatisticHour.
  1816. var DefaultUsageStatisticHourOrder = Desc(usagestatistichour.FieldID)
  1817. func newUsageStatisticHourPager(opts []UsageStatisticHourPaginateOption) (*UsageStatisticHourPager, error) {
  1818. pager := &UsageStatisticHourPager{}
  1819. for _, opt := range opts {
  1820. opt(pager)
  1821. }
  1822. if pager.Order == nil {
  1823. pager.Order = DefaultUsageStatisticHourOrder
  1824. }
  1825. return pager, nil
  1826. }
  1827. func (p *UsageStatisticHourPager) ApplyFilter(query *UsageStatisticHourQuery) (*UsageStatisticHourQuery, error) {
  1828. if p.Filter != nil {
  1829. return p.Filter(query)
  1830. }
  1831. return query, nil
  1832. }
  1833. // UsageStatisticHourPageList is UsageStatisticHour PageList result.
  1834. type UsageStatisticHourPageList struct {
  1835. List []*UsageStatisticHour `json:"list"`
  1836. PageDetails *PageDetails `json:"pageDetails"`
  1837. }
  1838. func (ush *UsageStatisticHourQuery) Page(
  1839. ctx context.Context, pageNum uint64, pageSize uint64, opts ...UsageStatisticHourPaginateOption,
  1840. ) (*UsageStatisticHourPageList, error) {
  1841. pager, err := newUsageStatisticHourPager(opts)
  1842. if err != nil {
  1843. return nil, err
  1844. }
  1845. if ush, err = pager.ApplyFilter(ush); err != nil {
  1846. return nil, err
  1847. }
  1848. ret := &UsageStatisticHourPageList{}
  1849. ret.PageDetails = &PageDetails{
  1850. Page: pageNum,
  1851. Size: pageSize,
  1852. }
  1853. query := ush.Clone()
  1854. query.ctx.Fields = nil
  1855. count, err := query.Count(ctx)
  1856. if err != nil {
  1857. return nil, err
  1858. }
  1859. ret.PageDetails.Total = uint64(count)
  1860. if pager.Order != nil {
  1861. ush = ush.Order(pager.Order)
  1862. } else {
  1863. ush = ush.Order(DefaultUsageStatisticHourOrder)
  1864. }
  1865. ush = ush.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1866. list, err := ush.All(ctx)
  1867. if err != nil {
  1868. return nil, err
  1869. }
  1870. ret.List = list
  1871. return ret, nil
  1872. }
  1873. type UsageStatisticMonthPager struct {
  1874. Order usagestatisticmonth.OrderOption
  1875. Filter func(*UsageStatisticMonthQuery) (*UsageStatisticMonthQuery, error)
  1876. }
  1877. // UsageStatisticMonthPaginateOption enables pagination customization.
  1878. type UsageStatisticMonthPaginateOption func(*UsageStatisticMonthPager)
  1879. // DefaultUsageStatisticMonthOrder is the default ordering of UsageStatisticMonth.
  1880. var DefaultUsageStatisticMonthOrder = Desc(usagestatisticmonth.FieldID)
  1881. func newUsageStatisticMonthPager(opts []UsageStatisticMonthPaginateOption) (*UsageStatisticMonthPager, error) {
  1882. pager := &UsageStatisticMonthPager{}
  1883. for _, opt := range opts {
  1884. opt(pager)
  1885. }
  1886. if pager.Order == nil {
  1887. pager.Order = DefaultUsageStatisticMonthOrder
  1888. }
  1889. return pager, nil
  1890. }
  1891. func (p *UsageStatisticMonthPager) ApplyFilter(query *UsageStatisticMonthQuery) (*UsageStatisticMonthQuery, error) {
  1892. if p.Filter != nil {
  1893. return p.Filter(query)
  1894. }
  1895. return query, nil
  1896. }
  1897. // UsageStatisticMonthPageList is UsageStatisticMonth PageList result.
  1898. type UsageStatisticMonthPageList struct {
  1899. List []*UsageStatisticMonth `json:"list"`
  1900. PageDetails *PageDetails `json:"pageDetails"`
  1901. }
  1902. func (usm *UsageStatisticMonthQuery) Page(
  1903. ctx context.Context, pageNum uint64, pageSize uint64, opts ...UsageStatisticMonthPaginateOption,
  1904. ) (*UsageStatisticMonthPageList, error) {
  1905. pager, err := newUsageStatisticMonthPager(opts)
  1906. if err != nil {
  1907. return nil, err
  1908. }
  1909. if usm, err = pager.ApplyFilter(usm); err != nil {
  1910. return nil, err
  1911. }
  1912. ret := &UsageStatisticMonthPageList{}
  1913. ret.PageDetails = &PageDetails{
  1914. Page: pageNum,
  1915. Size: pageSize,
  1916. }
  1917. query := usm.Clone()
  1918. query.ctx.Fields = nil
  1919. count, err := query.Count(ctx)
  1920. if err != nil {
  1921. return nil, err
  1922. }
  1923. ret.PageDetails.Total = uint64(count)
  1924. if pager.Order != nil {
  1925. usm = usm.Order(pager.Order)
  1926. } else {
  1927. usm = usm.Order(DefaultUsageStatisticMonthOrder)
  1928. }
  1929. usm = usm.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1930. list, err := usm.All(ctx)
  1931. if err != nil {
  1932. return nil, err
  1933. }
  1934. ret.List = list
  1935. return ret, nil
  1936. }
  1937. type UsageTotalPager struct {
  1938. Order usagetotal.OrderOption
  1939. Filter func(*UsageTotalQuery) (*UsageTotalQuery, error)
  1940. }
  1941. // UsageTotalPaginateOption enables pagination customization.
  1942. type UsageTotalPaginateOption func(*UsageTotalPager)
  1943. // DefaultUsageTotalOrder is the default ordering of UsageTotal.
  1944. var DefaultUsageTotalOrder = Desc(usagetotal.FieldID)
  1945. func newUsageTotalPager(opts []UsageTotalPaginateOption) (*UsageTotalPager, error) {
  1946. pager := &UsageTotalPager{}
  1947. for _, opt := range opts {
  1948. opt(pager)
  1949. }
  1950. if pager.Order == nil {
  1951. pager.Order = DefaultUsageTotalOrder
  1952. }
  1953. return pager, nil
  1954. }
  1955. func (p *UsageTotalPager) ApplyFilter(query *UsageTotalQuery) (*UsageTotalQuery, error) {
  1956. if p.Filter != nil {
  1957. return p.Filter(query)
  1958. }
  1959. return query, nil
  1960. }
  1961. // UsageTotalPageList is UsageTotal PageList result.
  1962. type UsageTotalPageList struct {
  1963. List []*UsageTotal `json:"list"`
  1964. PageDetails *PageDetails `json:"pageDetails"`
  1965. }
  1966. func (ut *UsageTotalQuery) Page(
  1967. ctx context.Context, pageNum uint64, pageSize uint64, opts ...UsageTotalPaginateOption,
  1968. ) (*UsageTotalPageList, error) {
  1969. pager, err := newUsageTotalPager(opts)
  1970. if err != nil {
  1971. return nil, err
  1972. }
  1973. if ut, err = pager.ApplyFilter(ut); err != nil {
  1974. return nil, err
  1975. }
  1976. ret := &UsageTotalPageList{}
  1977. ret.PageDetails = &PageDetails{
  1978. Page: pageNum,
  1979. Size: pageSize,
  1980. }
  1981. query := ut.Clone()
  1982. query.ctx.Fields = nil
  1983. count, err := query.Count(ctx)
  1984. if err != nil {
  1985. return nil, err
  1986. }
  1987. ret.PageDetails.Total = uint64(count)
  1988. if pager.Order != nil {
  1989. ut = ut.Order(pager.Order)
  1990. } else {
  1991. ut = ut.Order(DefaultUsageTotalOrder)
  1992. }
  1993. ut = ut.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  1994. list, err := ut.All(ctx)
  1995. if err != nil {
  1996. return nil, err
  1997. }
  1998. ret.List = list
  1999. return ret, nil
  2000. }
  2001. type WorkExperiencePager struct {
  2002. Order workexperience.OrderOption
  2003. Filter func(*WorkExperienceQuery) (*WorkExperienceQuery, error)
  2004. }
  2005. // WorkExperiencePaginateOption enables pagination customization.
  2006. type WorkExperiencePaginateOption func(*WorkExperiencePager)
  2007. // DefaultWorkExperienceOrder is the default ordering of WorkExperience.
  2008. var DefaultWorkExperienceOrder = Desc(workexperience.FieldID)
  2009. func newWorkExperiencePager(opts []WorkExperiencePaginateOption) (*WorkExperiencePager, error) {
  2010. pager := &WorkExperiencePager{}
  2011. for _, opt := range opts {
  2012. opt(pager)
  2013. }
  2014. if pager.Order == nil {
  2015. pager.Order = DefaultWorkExperienceOrder
  2016. }
  2017. return pager, nil
  2018. }
  2019. func (p *WorkExperiencePager) ApplyFilter(query *WorkExperienceQuery) (*WorkExperienceQuery, error) {
  2020. if p.Filter != nil {
  2021. return p.Filter(query)
  2022. }
  2023. return query, nil
  2024. }
  2025. // WorkExperiencePageList is WorkExperience PageList result.
  2026. type WorkExperiencePageList struct {
  2027. List []*WorkExperience `json:"list"`
  2028. PageDetails *PageDetails `json:"pageDetails"`
  2029. }
  2030. func (we *WorkExperienceQuery) Page(
  2031. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WorkExperiencePaginateOption,
  2032. ) (*WorkExperiencePageList, error) {
  2033. pager, err := newWorkExperiencePager(opts)
  2034. if err != nil {
  2035. return nil, err
  2036. }
  2037. if we, err = pager.ApplyFilter(we); err != nil {
  2038. return nil, err
  2039. }
  2040. ret := &WorkExperiencePageList{}
  2041. ret.PageDetails = &PageDetails{
  2042. Page: pageNum,
  2043. Size: pageSize,
  2044. }
  2045. query := we.Clone()
  2046. query.ctx.Fields = nil
  2047. count, err := query.Count(ctx)
  2048. if err != nil {
  2049. return nil, err
  2050. }
  2051. ret.PageDetails.Total = uint64(count)
  2052. if pager.Order != nil {
  2053. we = we.Order(pager.Order)
  2054. } else {
  2055. we = we.Order(DefaultWorkExperienceOrder)
  2056. }
  2057. we = we.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  2058. list, err := we.All(ctx)
  2059. if err != nil {
  2060. return nil, err
  2061. }
  2062. ret.List = list
  2063. return ret, nil
  2064. }
  2065. type WpChatroomPager struct {
  2066. Order wpchatroom.OrderOption
  2067. Filter func(*WpChatroomQuery) (*WpChatroomQuery, error)
  2068. }
  2069. // WpChatroomPaginateOption enables pagination customization.
  2070. type WpChatroomPaginateOption func(*WpChatroomPager)
  2071. // DefaultWpChatroomOrder is the default ordering of WpChatroom.
  2072. var DefaultWpChatroomOrder = Desc(wpchatroom.FieldID)
  2073. func newWpChatroomPager(opts []WpChatroomPaginateOption) (*WpChatroomPager, error) {
  2074. pager := &WpChatroomPager{}
  2075. for _, opt := range opts {
  2076. opt(pager)
  2077. }
  2078. if pager.Order == nil {
  2079. pager.Order = DefaultWpChatroomOrder
  2080. }
  2081. return pager, nil
  2082. }
  2083. func (p *WpChatroomPager) ApplyFilter(query *WpChatroomQuery) (*WpChatroomQuery, error) {
  2084. if p.Filter != nil {
  2085. return p.Filter(query)
  2086. }
  2087. return query, nil
  2088. }
  2089. // WpChatroomPageList is WpChatroom PageList result.
  2090. type WpChatroomPageList struct {
  2091. List []*WpChatroom `json:"list"`
  2092. PageDetails *PageDetails `json:"pageDetails"`
  2093. }
  2094. func (wc *WpChatroomQuery) Page(
  2095. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WpChatroomPaginateOption,
  2096. ) (*WpChatroomPageList, error) {
  2097. pager, err := newWpChatroomPager(opts)
  2098. if err != nil {
  2099. return nil, err
  2100. }
  2101. if wc, err = pager.ApplyFilter(wc); err != nil {
  2102. return nil, err
  2103. }
  2104. ret := &WpChatroomPageList{}
  2105. ret.PageDetails = &PageDetails{
  2106. Page: pageNum,
  2107. Size: pageSize,
  2108. }
  2109. query := wc.Clone()
  2110. query.ctx.Fields = nil
  2111. count, err := query.Count(ctx)
  2112. if err != nil {
  2113. return nil, err
  2114. }
  2115. ret.PageDetails.Total = uint64(count)
  2116. if pager.Order != nil {
  2117. wc = wc.Order(pager.Order)
  2118. } else {
  2119. wc = wc.Order(DefaultWpChatroomOrder)
  2120. }
  2121. wc = wc.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  2122. list, err := wc.All(ctx)
  2123. if err != nil {
  2124. return nil, err
  2125. }
  2126. ret.List = list
  2127. return ret, nil
  2128. }
  2129. type WpChatroomMemberPager struct {
  2130. Order wpchatroommember.OrderOption
  2131. Filter func(*WpChatroomMemberQuery) (*WpChatroomMemberQuery, error)
  2132. }
  2133. // WpChatroomMemberPaginateOption enables pagination customization.
  2134. type WpChatroomMemberPaginateOption func(*WpChatroomMemberPager)
  2135. // DefaultWpChatroomMemberOrder is the default ordering of WpChatroomMember.
  2136. var DefaultWpChatroomMemberOrder = Desc(wpchatroommember.FieldID)
  2137. func newWpChatroomMemberPager(opts []WpChatroomMemberPaginateOption) (*WpChatroomMemberPager, error) {
  2138. pager := &WpChatroomMemberPager{}
  2139. for _, opt := range opts {
  2140. opt(pager)
  2141. }
  2142. if pager.Order == nil {
  2143. pager.Order = DefaultWpChatroomMemberOrder
  2144. }
  2145. return pager, nil
  2146. }
  2147. func (p *WpChatroomMemberPager) ApplyFilter(query *WpChatroomMemberQuery) (*WpChatroomMemberQuery, error) {
  2148. if p.Filter != nil {
  2149. return p.Filter(query)
  2150. }
  2151. return query, nil
  2152. }
  2153. // WpChatroomMemberPageList is WpChatroomMember PageList result.
  2154. type WpChatroomMemberPageList struct {
  2155. List []*WpChatroomMember `json:"list"`
  2156. PageDetails *PageDetails `json:"pageDetails"`
  2157. }
  2158. func (wcm *WpChatroomMemberQuery) Page(
  2159. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WpChatroomMemberPaginateOption,
  2160. ) (*WpChatroomMemberPageList, error) {
  2161. pager, err := newWpChatroomMemberPager(opts)
  2162. if err != nil {
  2163. return nil, err
  2164. }
  2165. if wcm, err = pager.ApplyFilter(wcm); err != nil {
  2166. return nil, err
  2167. }
  2168. ret := &WpChatroomMemberPageList{}
  2169. ret.PageDetails = &PageDetails{
  2170. Page: pageNum,
  2171. Size: pageSize,
  2172. }
  2173. query := wcm.Clone()
  2174. query.ctx.Fields = nil
  2175. count, err := query.Count(ctx)
  2176. if err != nil {
  2177. return nil, err
  2178. }
  2179. ret.PageDetails.Total = uint64(count)
  2180. if pager.Order != nil {
  2181. wcm = wcm.Order(pager.Order)
  2182. } else {
  2183. wcm = wcm.Order(DefaultWpChatroomMemberOrder)
  2184. }
  2185. wcm = wcm.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  2186. list, err := wcm.All(ctx)
  2187. if err != nil {
  2188. return nil, err
  2189. }
  2190. ret.List = list
  2191. return ret, nil
  2192. }
  2193. type WxPager struct {
  2194. Order wx.OrderOption
  2195. Filter func(*WxQuery) (*WxQuery, error)
  2196. }
  2197. // WxPaginateOption enables pagination customization.
  2198. type WxPaginateOption func(*WxPager)
  2199. // DefaultWxOrder is the default ordering of Wx.
  2200. var DefaultWxOrder = Desc(wx.FieldID)
  2201. func newWxPager(opts []WxPaginateOption) (*WxPager, error) {
  2202. pager := &WxPager{}
  2203. for _, opt := range opts {
  2204. opt(pager)
  2205. }
  2206. if pager.Order == nil {
  2207. pager.Order = DefaultWxOrder
  2208. }
  2209. return pager, nil
  2210. }
  2211. func (p *WxPager) ApplyFilter(query *WxQuery) (*WxQuery, error) {
  2212. if p.Filter != nil {
  2213. return p.Filter(query)
  2214. }
  2215. return query, nil
  2216. }
  2217. // WxPageList is Wx PageList result.
  2218. type WxPageList struct {
  2219. List []*Wx `json:"list"`
  2220. PageDetails *PageDetails `json:"pageDetails"`
  2221. }
  2222. func (w *WxQuery) Page(
  2223. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxPaginateOption,
  2224. ) (*WxPageList, error) {
  2225. pager, err := newWxPager(opts)
  2226. if err != nil {
  2227. return nil, err
  2228. }
  2229. if w, err = pager.ApplyFilter(w); err != nil {
  2230. return nil, err
  2231. }
  2232. ret := &WxPageList{}
  2233. ret.PageDetails = &PageDetails{
  2234. Page: pageNum,
  2235. Size: pageSize,
  2236. }
  2237. query := w.Clone()
  2238. query.ctx.Fields = nil
  2239. count, err := query.Count(ctx)
  2240. if err != nil {
  2241. return nil, err
  2242. }
  2243. ret.PageDetails.Total = uint64(count)
  2244. if pager.Order != nil {
  2245. w = w.Order(pager.Order)
  2246. } else {
  2247. w = w.Order(DefaultWxOrder)
  2248. }
  2249. w = w.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  2250. list, err := w.All(ctx)
  2251. if err != nil {
  2252. return nil, err
  2253. }
  2254. ret.List = list
  2255. return ret, nil
  2256. }
  2257. type WxCardPager struct {
  2258. Order wxcard.OrderOption
  2259. Filter func(*WxCardQuery) (*WxCardQuery, error)
  2260. }
  2261. // WxCardPaginateOption enables pagination customization.
  2262. type WxCardPaginateOption func(*WxCardPager)
  2263. // DefaultWxCardOrder is the default ordering of WxCard.
  2264. var DefaultWxCardOrder = Desc(wxcard.FieldID)
  2265. func newWxCardPager(opts []WxCardPaginateOption) (*WxCardPager, error) {
  2266. pager := &WxCardPager{}
  2267. for _, opt := range opts {
  2268. opt(pager)
  2269. }
  2270. if pager.Order == nil {
  2271. pager.Order = DefaultWxCardOrder
  2272. }
  2273. return pager, nil
  2274. }
  2275. func (p *WxCardPager) ApplyFilter(query *WxCardQuery) (*WxCardQuery, error) {
  2276. if p.Filter != nil {
  2277. return p.Filter(query)
  2278. }
  2279. return query, nil
  2280. }
  2281. // WxCardPageList is WxCard PageList result.
  2282. type WxCardPageList struct {
  2283. List []*WxCard `json:"list"`
  2284. PageDetails *PageDetails `json:"pageDetails"`
  2285. }
  2286. func (wc *WxCardQuery) Page(
  2287. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxCardPaginateOption,
  2288. ) (*WxCardPageList, error) {
  2289. pager, err := newWxCardPager(opts)
  2290. if err != nil {
  2291. return nil, err
  2292. }
  2293. if wc, err = pager.ApplyFilter(wc); err != nil {
  2294. return nil, err
  2295. }
  2296. ret := &WxCardPageList{}
  2297. ret.PageDetails = &PageDetails{
  2298. Page: pageNum,
  2299. Size: pageSize,
  2300. }
  2301. query := wc.Clone()
  2302. query.ctx.Fields = nil
  2303. count, err := query.Count(ctx)
  2304. if err != nil {
  2305. return nil, err
  2306. }
  2307. ret.PageDetails.Total = uint64(count)
  2308. if pager.Order != nil {
  2309. wc = wc.Order(pager.Order)
  2310. } else {
  2311. wc = wc.Order(DefaultWxCardOrder)
  2312. }
  2313. wc = wc.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  2314. list, err := wc.All(ctx)
  2315. if err != nil {
  2316. return nil, err
  2317. }
  2318. ret.List = list
  2319. return ret, nil
  2320. }
  2321. type WxCardUserPager struct {
  2322. Order wxcarduser.OrderOption
  2323. Filter func(*WxCardUserQuery) (*WxCardUserQuery, error)
  2324. }
  2325. // WxCardUserPaginateOption enables pagination customization.
  2326. type WxCardUserPaginateOption func(*WxCardUserPager)
  2327. // DefaultWxCardUserOrder is the default ordering of WxCardUser.
  2328. var DefaultWxCardUserOrder = Desc(wxcarduser.FieldID)
  2329. func newWxCardUserPager(opts []WxCardUserPaginateOption) (*WxCardUserPager, error) {
  2330. pager := &WxCardUserPager{}
  2331. for _, opt := range opts {
  2332. opt(pager)
  2333. }
  2334. if pager.Order == nil {
  2335. pager.Order = DefaultWxCardUserOrder
  2336. }
  2337. return pager, nil
  2338. }
  2339. func (p *WxCardUserPager) ApplyFilter(query *WxCardUserQuery) (*WxCardUserQuery, error) {
  2340. if p.Filter != nil {
  2341. return p.Filter(query)
  2342. }
  2343. return query, nil
  2344. }
  2345. // WxCardUserPageList is WxCardUser PageList result.
  2346. type WxCardUserPageList struct {
  2347. List []*WxCardUser `json:"list"`
  2348. PageDetails *PageDetails `json:"pageDetails"`
  2349. }
  2350. func (wcu *WxCardUserQuery) Page(
  2351. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxCardUserPaginateOption,
  2352. ) (*WxCardUserPageList, error) {
  2353. pager, err := newWxCardUserPager(opts)
  2354. if err != nil {
  2355. return nil, err
  2356. }
  2357. if wcu, err = pager.ApplyFilter(wcu); err != nil {
  2358. return nil, err
  2359. }
  2360. ret := &WxCardUserPageList{}
  2361. ret.PageDetails = &PageDetails{
  2362. Page: pageNum,
  2363. Size: pageSize,
  2364. }
  2365. query := wcu.Clone()
  2366. query.ctx.Fields = nil
  2367. count, err := query.Count(ctx)
  2368. if err != nil {
  2369. return nil, err
  2370. }
  2371. ret.PageDetails.Total = uint64(count)
  2372. if pager.Order != nil {
  2373. wcu = wcu.Order(pager.Order)
  2374. } else {
  2375. wcu = wcu.Order(DefaultWxCardUserOrder)
  2376. }
  2377. wcu = wcu.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  2378. list, err := wcu.All(ctx)
  2379. if err != nil {
  2380. return nil, err
  2381. }
  2382. ret.List = list
  2383. return ret, nil
  2384. }
  2385. type WxCardVisitPager struct {
  2386. Order wxcardvisit.OrderOption
  2387. Filter func(*WxCardVisitQuery) (*WxCardVisitQuery, error)
  2388. }
  2389. // WxCardVisitPaginateOption enables pagination customization.
  2390. type WxCardVisitPaginateOption func(*WxCardVisitPager)
  2391. // DefaultWxCardVisitOrder is the default ordering of WxCardVisit.
  2392. var DefaultWxCardVisitOrder = Desc(wxcardvisit.FieldID)
  2393. func newWxCardVisitPager(opts []WxCardVisitPaginateOption) (*WxCardVisitPager, error) {
  2394. pager := &WxCardVisitPager{}
  2395. for _, opt := range opts {
  2396. opt(pager)
  2397. }
  2398. if pager.Order == nil {
  2399. pager.Order = DefaultWxCardVisitOrder
  2400. }
  2401. return pager, nil
  2402. }
  2403. func (p *WxCardVisitPager) ApplyFilter(query *WxCardVisitQuery) (*WxCardVisitQuery, error) {
  2404. if p.Filter != nil {
  2405. return p.Filter(query)
  2406. }
  2407. return query, nil
  2408. }
  2409. // WxCardVisitPageList is WxCardVisit PageList result.
  2410. type WxCardVisitPageList struct {
  2411. List []*WxCardVisit `json:"list"`
  2412. PageDetails *PageDetails `json:"pageDetails"`
  2413. }
  2414. func (wcv *WxCardVisitQuery) Page(
  2415. ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxCardVisitPaginateOption,
  2416. ) (*WxCardVisitPageList, error) {
  2417. pager, err := newWxCardVisitPager(opts)
  2418. if err != nil {
  2419. return nil, err
  2420. }
  2421. if wcv, err = pager.ApplyFilter(wcv); err != nil {
  2422. return nil, err
  2423. }
  2424. ret := &WxCardVisitPageList{}
  2425. ret.PageDetails = &PageDetails{
  2426. Page: pageNum,
  2427. Size: pageSize,
  2428. }
  2429. query := wcv.Clone()
  2430. query.ctx.Fields = nil
  2431. count, err := query.Count(ctx)
  2432. if err != nil {
  2433. return nil, err
  2434. }
  2435. ret.PageDetails.Total = uint64(count)
  2436. if pager.Order != nil {
  2437. wcv = wcv.Order(pager.Order)
  2438. } else {
  2439. wcv = wcv.Order(DefaultWxCardVisitOrder)
  2440. }
  2441. wcv = wcv.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
  2442. list, err := wcv.All(ctx)
  2443. if err != nil {
  2444. return nil, err
  2445. }
  2446. ret.List = list
  2447. return ret, nil
  2448. }