matheusgomes28 / urchin

Headless CMS written in Golang
MIT License
70 stars 21 forks source link

Support for Pagination in Database Posts #44

Closed matheusgomes28 closed 7 months ago

matheusgomes28 commented 7 months ago

Add support for pagination in posts returned from db.GetPosts(...). This way, we can make the number of displayed posts in the index page configurable.

This can be achieved quite easily by adding LIMIT and OFFSET to the query, but we would need to capture the current offset in perhaps a GET url parameter.

ali-assar commented 7 months ago

Hi. I understood the issue and Here’s a proposed solution:

So I think, I can handle it.

matheusgomes28 commented 7 months ago

@Ali-Assar Sounds like a solid plan mate!

That's along the lines of what I was thinking about. Feel free to send the PR my way whenever you have time to complete it, happy to review it with you 😆

matheusgomes28 commented 7 months ago

I think that usually, websites have like a URL parameter to indicate which page it is, then you can deduce what limit and offset value you want to serve.

for more info on this for gin, take a look at the query parameters documentation.

To add some stuff to your plan:

downside is that there is a cache on top of the / handler, but let me know if you are struggling because I can come in and help. For now, if you just want to add a separate handler for /page/:num, that would be great

matheusgomes28 commented 7 months ago

Closed with #50