pagination.go 63 KB

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