Fix pagination

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-02-12 14:18:50 -08:00
parent bbc037ad6e
commit 743ec49972
14 changed files with 71 additions and 68 deletions

View File

@@ -20,7 +20,7 @@ import (
"errors"
"time"
"go.gearno.de/crypto/uuid"
"github.com/getprobo/probo/pkg/gid"
)
type (
@@ -63,7 +63,7 @@ func CursorKeyFromBytes(b []byte) (CursorKey, error) {
return ck, nil
}
func NewCursorKey(id uuid.UUID, t time.Time) CursorKey {
func NewCursorKey(id gid.GID, t time.Time) CursorKey {
var cursorKey CursorKey
copy(cursorKey[:16], id[:])
_ = binary.PutVarint(cursorKey[16:], t.UnixMicro())
@@ -88,9 +88,8 @@ func (ck CursorKey) Timestamp() time.Time {
return time.Unix(seconds, nanoseconds)
}
func (ck CursorKey) ID() uuid.UUID {
id, _ := uuid.FromBytes(ck[:])
return id
func (ck CursorKey) ID() gid.GID {
return gid.GID(ck[:16])
}
func (ck CursorKey) MarshalText() ([]byte, error) {

View File

@@ -24,7 +24,6 @@ import (
"github.com/getprobo/probo/pkg/page"
"github.com/jackc/pgx/v5"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
)
@@ -44,7 +43,7 @@ type (
)
func (c Control) CursorKey() page.CursorKey {
return page.NewCursorKey(uuid.UUID(c.ID), c.CreatedAt)
return page.NewCursorKey(c.ID, c.CreatedAt)
}
func (c *Control) scan(r pgx.Row) error {
@@ -146,13 +145,13 @@ VALUES (
`
args := pgx.NamedArgs{
"control_id": c.ID,
"control_id": c.ID,
"framework_id": c.FrameworkID,
"name": c.Name,
"description": c.Description,
"content_ref": c.ContentRef,
"created_at": c.CreatedAt,
"updated_at": c.UpdatedAt,
"name": c.Name,
"description": c.Description,
"content_ref": c.ContentRef,
"created_at": c.CreatedAt,
"updated_at": c.UpdatedAt,
}
_, err := conn.Exec(ctx, q, args)
return err

View File

@@ -22,7 +22,6 @@ import (
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/page"
"github.com/jackc/pgx/v5"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
)
@@ -37,7 +36,7 @@ type (
)
func (cst ControlStateTransition) CursorKey() page.CursorKey {
return page.NewCursorKey(uuid.UUID(cst.ID), cst.CreatedAt)
return page.NewCursorKey(cst.ID, cst.CreatedAt)
}
func (cst *ControlStateTransition) scan(r pgx.Row) error {

View File

@@ -23,7 +23,6 @@ import (
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/page"
"github.com/jackc/pgx/v5"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
)
@@ -43,7 +42,7 @@ type (
)
func (e Evidence) CursorKey() page.CursorKey {
return page.NewCursorKey(uuid.UUID(e.ID), e.CreatedAt)
return page.NewCursorKey(e.ID, e.CreatedAt)
}
func (e *Evidence) scan(r pgx.Row) error {

View File

@@ -22,7 +22,6 @@ import (
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/page"
"github.com/jackc/pgx/v5"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
)
@@ -37,7 +36,7 @@ type (
)
func (cst EvidenceStateTransition) CursorKey() page.CursorKey {
return page.NewCursorKey(uuid.UUID(cst.ID), cst.CreatedAt)
return page.NewCursorKey(cst.ID, cst.CreatedAt)
}
func (cst *EvidenceStateTransition) scan(r pgx.Row) error {

View File

@@ -23,7 +23,6 @@ import (
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/page"
"github.com/jackc/pgx/v5"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
)
@@ -42,7 +41,7 @@ type (
)
func (f Framework) CursorKey() page.CursorKey {
return page.NewCursorKey(uuid.UUID(f.ID), f.CreatedAt)
return page.NewCursorKey(f.ID, f.CreatedAt)
}
func (f *Framework) scan(r pgx.Row) error {
@@ -177,13 +176,13 @@ VALUES (
`
args := pgx.NamedArgs{
"framework_id": f.ID,
"framework_id": f.ID,
"organization_id": f.OrganizationID,
"name": f.Name,
"description": f.Description,
"content_ref": f.ContentRef,
"created_at": f.CreatedAt,
"updated_at": f.UpdatedAt,
"name": f.Name,
"description": f.Description,
"content_ref": f.ContentRef,
"created_at": f.CreatedAt,
"updated_at": f.UpdatedAt,
}
_, err := conn.Exec(ctx, q, args)
return err

View File

@@ -23,7 +23,6 @@ import (
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/page"
"github.com/jackc/pgx/v5"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
)
@@ -43,7 +42,7 @@ type (
)
func (p People) CursorKey() page.CursorKey {
return page.NewCursorKey(uuid.UUID(p.ID), p.CreatedAt)
return page.NewCursorKey(p.ID, p.CreatedAt)
}
func (p *People) scan(r pgx.Row) error {

View File

@@ -24,7 +24,6 @@ import (
"github.com/getprobo/probo/pkg/page"
"github.com/jackc/pgx/v5"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
)
@@ -44,7 +43,7 @@ type (
)
func (t Task) CursorKey() page.CursorKey {
return page.NewCursorKey(uuid.UUID(t.ID), t.CreatedAt)
return page.NewCursorKey(t.ID, t.CreatedAt)
}
func (t *Task) scan(r pgx.Row) error {

View File

@@ -22,7 +22,6 @@ import (
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/page"
"github.com/jackc/pgx/v5"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
)
@@ -37,7 +36,7 @@ type (
)
func (tst TaskStateTransition) CursorKey() page.CursorKey {
return page.NewCursorKey(uuid.UUID(tst.ID), tst.CreatedAt)
return page.NewCursorKey(tst.ID, tst.CreatedAt)
}
func (tst *TaskStateTransition) scan(r pgx.Row) error {

View File

@@ -23,7 +23,6 @@ import (
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/page"
"github.com/jackc/pgx/v5"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
)
@@ -40,7 +39,7 @@ type (
)
func (v Vendor) CursorKey() page.CursorKey {
return page.NewCursorKey(uuid.UUID(v.ID), v.CreatedAt)
return page.NewCursorKey(v.ID, v.CreatedAt)
}
func (v *Vendor) scan(r pgx.Row) error {

View File

@@ -22,7 +22,6 @@ import (
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/page"
"github.com/jackc/pgx/v5"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
)
@@ -37,7 +36,7 @@ type (
)
func (s Session) CursorKey() page.CursorKey {
return page.NewCursorKey(uuid.UUID(s.ID), s.CreatedAt)
return page.NewCursorKey(s.ID, s.CreatedAt)
}
func (s *Session) scan(r pgx.Row) error {

View File

@@ -21,7 +21,6 @@ import (
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/page"
"github.com/jackc/pgx/v5"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
)
@@ -36,7 +35,7 @@ type (
)
func (u User) CursorKey() page.CursorKey {
return page.NewCursorKey(uuid.UUID(u.ID), u.CreatedAt)
return page.NewCursorKey(u.ID, u.CreatedAt)
}
func (u *User) scan(r pgx.Row) error {