about summary refs log tree commit diff stats
path: root/internal/pagination/pagination.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pagination/pagination.go')
-rw-r--r--internal/pagination/pagination.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/pagination/pagination.go b/internal/pagination/pagination.go
new file mode 100644
index 0000000..4d41587
--- /dev/null
+++ b/internal/pagination/pagination.go
@@ -0,0 +1,31 @@
+package pagination
+
+type Pagination struct {
+	total uint64
+
+	From int
+
+	Size,
+	Current,
+	Prev,
+	Next int
+
+	Needed bool
+}
+
+func New(page int, pageSize int) *Pagination {
+	return &Pagination{
+		Current: page,
+		From:    (page - 1) * pageSize,
+		Size:    pageSize,
+	}
+}
+
+func (p *Pagination) SetResults(total uint64) {
+	p.total = total
+	p.Needed = p.total > uint64(p.Size)
+	if uint64(p.Current*p.Size) <= p.total {
+		p.Next = p.Current + 1
+		p.Prev = p.Current - 1
+	}
+}