Refactor model cursor to use orderBy
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -55,7 +55,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (c Control) CursorKey() page.CursorKey {
|
||||
func (c Control) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(c.ID, c.CreatedAt)
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ type (
|
||||
Evidences []*Evidence
|
||||
)
|
||||
|
||||
func (e Evidence) CursorKey() page.CursorKey {
|
||||
func (e Evidence) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(e.ID, e.CreatedAt)
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (f Framework) CursorKey() page.CursorKey {
|
||||
func (f Framework) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(f.ID, f.CreatedAt)
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ WHERE
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||
args := pgx.NamedArgs{"organization_id": organizationID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
@@ -38,6 +39,10 @@ type (
|
||||
Organizations []*Organization
|
||||
)
|
||||
|
||||
func (o Organization) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(o.ID, o.CreatedAt)
|
||||
}
|
||||
|
||||
func (o *Organization) LoadByID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
|
||||
@@ -50,7 +50,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (p People) CursorKey() page.CursorKey {
|
||||
func (p People) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(p.ID, p.CreatedAt)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (p Policy) CursorKey() page.CursorKey {
|
||||
func (p Policy) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(p.ID, p.CreatedAt)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ type (
|
||||
SessionData struct{}
|
||||
)
|
||||
|
||||
func (s Session) CursorKey() page.CursorKey {
|
||||
func (s Session) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(s.ID, s.CreatedAt)
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (t Task) CursorKey() page.CursorKey {
|
||||
func (t Task) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(t.ID, t.CreatedAt)
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ func (e ErrUserAlreadyExists) Error() string {
|
||||
return e.message
|
||||
}
|
||||
|
||||
func (u User) CursorKey() page.CursorKey {
|
||||
func (u User) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(u.ID, u.CreatedAt)
|
||||
}
|
||||
|
||||
|
||||
@@ -63,8 +63,17 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (v Vendor) CursorKey() page.CursorKey {
|
||||
return page.NewCursorKey(v.ID, v.CreatedAt)
|
||||
func (v Vendor) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case page.OrderFieldCreatedAt:
|
||||
return page.NewCursorKey(v.ID, v.CreatedAt)
|
||||
case page.OrderFieldUpdatedAt:
|
||||
return page.NewCursorKey(v.ID, v.UpdatedAt)
|
||||
case page.OrderFieldName:
|
||||
return page.NewCursorKey(v.ID, v.Name)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unknown order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (v *Vendor) LoadByID(
|
||||
@@ -229,7 +238,6 @@ WHERE
|
||||
AND organization_id = @organization_id
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||
|
||||
Reference in New Issue
Block a user