Use dedicated type for each order field
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -55,8 +55,13 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (c Control) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(c.ID, c.CreatedAt)
|
||||
func (c Control) CursorKey(orderBy ControlOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case ControlOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(c.ID, c.CreatedAt)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (c *Control) LoadByID(
|
||||
@@ -170,7 +175,7 @@ func (c *Controls) LoadByFrameworkID(
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
frameworkID gid.GID,
|
||||
cursor *page.Cursor,
|
||||
cursor *page.Cursor[ControlOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
|
||||
40
pkg/coredata/control_order_field.go
Normal file
40
pkg/coredata/control_order_field.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
type (
|
||||
ControlOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
ControlOrderFieldCreatedAt ControlOrderField = "CREATED_AT"
|
||||
)
|
||||
|
||||
func (p ControlOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p ControlOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p ControlOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *ControlOrderField) UnmarshalText(text []byte) error {
|
||||
*p = ControlOrderField(text)
|
||||
return nil
|
||||
}
|
||||
@@ -42,8 +42,13 @@ type (
|
||||
Evidences []*Evidence
|
||||
)
|
||||
|
||||
func (e Evidence) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(e.ID, e.CreatedAt)
|
||||
func (e Evidence) CursorKey(orderBy EvidenceOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case EvidenceOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(e.ID, e.CreatedAt)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (e Evidence) Insert(
|
||||
@@ -145,7 +150,7 @@ func (e *Evidences) LoadByTaskID(
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
taskID gid.GID,
|
||||
cursor *page.Cursor,
|
||||
cursor *page.Cursor[EvidenceOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
|
||||
40
pkg/coredata/evidence_order_field.go
Normal file
40
pkg/coredata/evidence_order_field.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
type (
|
||||
EvidenceOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
EvidenceOrderFieldCreatedAt EvidenceOrderField = "CREATED_AT"
|
||||
)
|
||||
|
||||
func (p EvidenceOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p EvidenceOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p EvidenceOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *EvidenceOrderField) UnmarshalText(text []byte) error {
|
||||
*p = EvidenceOrderField(text)
|
||||
return nil
|
||||
}
|
||||
@@ -47,8 +47,13 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (f Framework) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(f.ID, f.CreatedAt)
|
||||
func (f Framework) CursorKey(orderBy FrameworkOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case FrameworkOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(f.ID, f.CreatedAt)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (f *Frameworks) LoadByOrganizationID(
|
||||
@@ -56,7 +61,7 @@ func (f *Frameworks) LoadByOrganizationID(
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor,
|
||||
cursor *page.Cursor[FrameworkOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
|
||||
40
pkg/coredata/framework_order_field.go
Normal file
40
pkg/coredata/framework_order_field.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
type (
|
||||
FrameworkOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
FrameworkOrderFieldCreatedAt FrameworkOrderField = "CREATED_AT"
|
||||
)
|
||||
|
||||
func (p FrameworkOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p FrameworkOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p FrameworkOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *FrameworkOrderField) UnmarshalText(text []byte) error {
|
||||
*p = FrameworkOrderField(text)
|
||||
return nil
|
||||
}
|
||||
@@ -39,8 +39,13 @@ type (
|
||||
Organizations []*Organization
|
||||
)
|
||||
|
||||
func (o Organization) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(o.ID, o.CreatedAt)
|
||||
func (o Organization) CursorKey(orderBy OrganizationOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case OrganizationOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(o.ID, o.CreatedAt)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (o *Organization) LoadByID(
|
||||
|
||||
40
pkg/coredata/organization_order_field.go
Normal file
40
pkg/coredata/organization_order_field.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
type (
|
||||
OrganizationOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
OrganizationOrderFieldCreatedAt OrganizationOrderField = "CREATED_AT"
|
||||
)
|
||||
|
||||
func (p OrganizationOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p OrganizationOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p OrganizationOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *OrganizationOrderField) UnmarshalText(text []byte) error {
|
||||
*p = OrganizationOrderField(text)
|
||||
return nil
|
||||
}
|
||||
@@ -50,8 +50,15 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (p People) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(p.ID, p.CreatedAt)
|
||||
func (p People) CursorKey(orderBy PeopleOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case PeopleOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(p.ID, p.CreatedAt)
|
||||
case PeopleOrderFieldFullName:
|
||||
return page.NewCursorKey(p.ID, p.FullName)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (p *People) LoadByID(
|
||||
@@ -171,8 +178,9 @@ func (p *Peoples) LoadByOrganizationID(
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor,
|
||||
cursor *page.Cursor[PeopleOrderField],
|
||||
) error {
|
||||
// Base query
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
|
||||
41
pkg/coredata/people_order_field.go
Normal file
41
pkg/coredata/people_order_field.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
type (
|
||||
PeopleOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
PeopleOrderFieldCreatedAt PeopleOrderField = "CREATED_AT"
|
||||
PeopleOrderFieldFullName PeopleOrderField = "FULL_NAME"
|
||||
)
|
||||
|
||||
func (p PeopleOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p PeopleOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p PeopleOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *PeopleOrderField) UnmarshalText(text []byte) error {
|
||||
*p = PeopleOrderField(text)
|
||||
return nil
|
||||
}
|
||||
@@ -38,8 +38,15 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (p Policy) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(p.ID, p.CreatedAt)
|
||||
func (p Policy) CursorKey(orderBy PolicyOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case PolicyOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(p.ID, p.CreatedAt)
|
||||
case PolicyOrderFieldName:
|
||||
return page.NewCursorKey(p.ID, p.Name)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (p *Policy) LoadByID(
|
||||
@@ -93,7 +100,7 @@ func (p *Policies) LoadByOrganizationID(
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor,
|
||||
cursor *page.Cursor[PolicyOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
|
||||
41
pkg/coredata/policy_order_field.go
Normal file
41
pkg/coredata/policy_order_field.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
type (
|
||||
PolicyOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
PolicyOrderFieldCreatedAt PolicyOrderField = "CREATED_AT"
|
||||
PolicyOrderFieldName PolicyOrderField = "NAME"
|
||||
)
|
||||
|
||||
func (p PolicyOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p PolicyOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p PolicyOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *PolicyOrderField) UnmarshalText(text []byte) error {
|
||||
*p = PolicyOrderField(text)
|
||||
return nil
|
||||
}
|
||||
@@ -38,8 +38,13 @@ type (
|
||||
SessionData struct{}
|
||||
)
|
||||
|
||||
func (s Session) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(s.ID, s.CreatedAt)
|
||||
func (s Session) CursorKey(orderBy SessionOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case SessionOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(s.ID, s.CreatedAt)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (s *Session) LoadByID(
|
||||
|
||||
40
pkg/coredata/session_order_field.go
Normal file
40
pkg/coredata/session_order_field.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
type (
|
||||
SessionOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
SessionOrderFieldCreatedAt SessionOrderField = "CREATED_AT"
|
||||
)
|
||||
|
||||
func (p SessionOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p SessionOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p SessionOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *SessionOrderField) UnmarshalText(text []byte) error {
|
||||
*p = SessionOrderField(text)
|
||||
return nil
|
||||
}
|
||||
@@ -53,8 +53,13 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (t Task) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(t.ID, t.CreatedAt)
|
||||
func (t Task) CursorKey(orderBy TaskOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case TaskOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(t.ID, t.CreatedAt)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (t *Task) LoadByID(
|
||||
@@ -163,7 +168,7 @@ func (t *Tasks) LoadByControlID(
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
controlID gid.GID,
|
||||
cursor *page.Cursor,
|
||||
cursor *page.Cursor[TaskOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
|
||||
40
pkg/coredata/task_order_field.go
Normal file
40
pkg/coredata/task_order_field.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
type (
|
||||
TaskOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
TaskOrderFieldCreatedAt TaskOrderField = "CREATED_AT"
|
||||
)
|
||||
|
||||
func (p TaskOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p TaskOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p TaskOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *TaskOrderField) UnmarshalText(text []byte) error {
|
||||
*p = TaskOrderField(text)
|
||||
return nil
|
||||
}
|
||||
@@ -59,15 +59,20 @@ func (e ErrUserAlreadyExists) Error() string {
|
||||
return e.message
|
||||
}
|
||||
|
||||
func (u User) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
return page.NewCursorKey(u.ID, u.CreatedAt)
|
||||
func (u User) CursorKey(orderBy UserOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case UserOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(u.ID, u.CreatedAt)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (u *Users) LoadByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor,
|
||||
cursor *page.Cursor[UserOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
|
||||
40
pkg/coredata/user_order_field.go
Normal file
40
pkg/coredata/user_order_field.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
type (
|
||||
UserOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
UserOrderFieldCreatedAt UserOrderField = "CREATED_AT"
|
||||
)
|
||||
|
||||
func (p UserOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p UserOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p UserOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *UserOrderField) UnmarshalText(text []byte) error {
|
||||
*p = UserOrderField(text)
|
||||
return nil
|
||||
}
|
||||
@@ -63,17 +63,15 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (v Vendor) CursorKey(orderBy page.OrderField) page.CursorKey {
|
||||
func (v Vendor) CursorKey(orderBy VendorOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case page.OrderFieldCreatedAt:
|
||||
case VendorOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(v.ID, v.CreatedAt)
|
||||
case page.OrderFieldUpdatedAt:
|
||||
return page.NewCursorKey(v.ID, v.UpdatedAt)
|
||||
case page.OrderFieldName:
|
||||
case VendorOrderFieldName:
|
||||
return page.NewCursorKey(v.ID, v.Name)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unknown order by: %s", orderBy))
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (v *Vendor) LoadByID(
|
||||
@@ -213,7 +211,7 @@ func (v *Vendors) LoadByOrganizationID(
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor,
|
||||
cursor *page.Cursor[VendorOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
|
||||
41
pkg/coredata/vendor_order_field.go
Normal file
41
pkg/coredata/vendor_order_field.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
type (
|
||||
VendorOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
VendorOrderFieldCreatedAt VendorOrderField = "CREATED_AT"
|
||||
VendorOrderFieldName VendorOrderField = "NAME"
|
||||
)
|
||||
|
||||
func (p VendorOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p VendorOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p VendorOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *VendorOrderField) UnmarshalText(text []byte) error {
|
||||
*p = VendorOrderField(text)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user