2024-07-19 20:44:09 -07:00
|
|
|
package models
|
2024-07-13 21:20:37 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.grosinger.net/tgrosinger/saasitone/pkg/page"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Post struct {
|
|
|
|
Title string
|
|
|
|
Body string
|
|
|
|
}
|
|
|
|
|
|
|
|
type DBPostClient struct {
|
2024-07-19 20:44:09 -07:00
|
|
|
DB *sql.DB
|
2024-07-13 21:20:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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]
|
|
|
|
}
|