Course Overview
Locked video preview

Paid video

Please purchase the course to watch.

Building the home view

Seed data & page based pagination

Here is a summary of the video transcript:

  • Seeding Initial Data
    The video demonstrates how to create seed data using a command directory with a dedicated main.go entry point. Seed articles are inserted through the model layer to ensure data validity, enabling the blog to display realistic content for development and UI work.

  • Motivation for Pagination
    Loading all articles at once can harm performance and user experience. Pagination is introduced to limit the number of articles displayed per page, improving efficiency and scalability.

  • Page-Based vs Cursor-Based Pagination
    Two pagination strategies are explained: page-based and cursor-based. Page-based uses page numbers with SQL OFFSET and LIMIT, while cursor-based uses record pointers for large datasets; the implementation focuses on the simpler page-based approach.

  • SQL Layer Implementation
    A new query retrieves published articles using ORDER BY, OFFSET, and LIMIT. An additional count query calculates the total number of published articles to determine the total number of pages.

  • Model Layer Pagination Logic
    A paginated response struct is introduced containing articles, next page, and previous page. The offset is calculated from the requested page, total pages are derived using a ceiling division, and navigation values are computed accordingly.

  • Controller Integration
    The home controller reads the page query parameter from the URL and passes it to the pagination function. The returned paginated result replaces the previous non-paginated article list.

  • View Updates and Navigation Links
    The home view is updated to conditionally display “Next” and “Previous” links based on available pages. Query parameters are appended to URLs to navigate between pages.

  • Result and Next Steps
    Pagination successfully limits the homepage to nine articles per page with working navigation. Future work will focus on styling and improving the UI presentation.