saasitone/pkg/models/posts.go

32 lines
691 B
Go
Raw Permalink Normal View History

package models
import (
"database/sql"
"fmt"
"git.grosinger.net/tgrosinger/saasitone/pkg/page"
)
type Post struct {
Title string
Body string
}
type DBPostClient struct {
DB *sql.DB
}
// FetchAll is an mock example of fetching posts to illustrate how paging works
func (c *DBPostClient) FetchAll(pager *page.Pager) []Post {
pager.SetItems(20)
posts := make([]Post, 20)
for k := range posts {
posts[k] = Post{
Title: fmt.Sprintf("Post example #%d", k+1),
Body: fmt.Sprintf("Lorem ipsum example #%d ddolor sit amet, consectetur adipiscing elit. Nam elementum vulputate tristique.", k+1),
}
}
return posts[pager.GetOffset() : pager.GetOffset()+pager.ItemsPerPage]
}