pagination.go 70 KB

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