Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-01-23 10:08:04 +01:00
parent b4acae1862
commit d49e18b1be
4 changed files with 33 additions and 10 deletions

View File

@@ -134,7 +134,7 @@ LIMIT 1;
` `
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"framework_id": frameworkID} args := pgx.NamedArgs{"framework_id": frameworkID}
maps.Copy(args, scope.SQLArguments()) maps.Copy(args, scope.SQLArguments())
r := conn.QueryRow(ctx, q, args) r := conn.QueryRow(ctx, q, args)

View File

@@ -16,9 +16,9 @@ package coredata
import ( import (
"context" "context"
"time"
"maps"
"fmt" "fmt"
"maps"
"time"
"github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5"
"go.gearno.de/kit/pg" "go.gearno.de/kit/pg"

View File

@@ -19,7 +19,7 @@ import (
) )
type ( type (
Scope struct {} Scope struct{}
) )
func NewScope() *Scope { func NewScope() *Scope {

View File

@@ -24,14 +24,14 @@ import (
type ( type (
Service struct { Service struct {
pg *pg.Client pg *pg.Client
scope *coredata.Scope scope *coredata.Scope
} }
) )
func NewService(ctx context.Context, pgClient *pg.Client) *Service { func NewService(ctx context.Context, pgClient *pg.Client) *Service {
return &Service{ return &Service{
pg: pgClient, pg: pgClient,
scope: coredata.NewScope(), // must be created from auth scope: coredata.NewScope(), // must be created from auth
} }
} }
@@ -45,7 +45,12 @@ func (s *Service) GetOrganization(
err := s.pg.WithConn( err := s.pg.WithConn(
ctx, ctx,
func(conn pg.Conn) error { func(conn pg.Conn) error {
return organization.LoadByID(ctx, conn, s.scope, organizationID) return organization.LoadByID(
ctx,
conn,
s.scope,
organizationID,
)
}, },
) )
@@ -66,7 +71,13 @@ func (s *Service) ListOrganizationFrameworks(
err := s.pg.WithConn( err := s.pg.WithConn(
ctx, ctx,
func(conn pg.Conn) error { func(conn pg.Conn) error {
return frameworks.LoadByOrganizationID(ctx, conn, s.scope, organizationID, cursor) return frameworks.LoadByOrganizationID(
ctx,
conn,
s.scope,
organizationID,
cursor,
)
}, },
) )
@@ -87,7 +98,13 @@ func (s *Service) ListFrameworkControls(
err := s.pg.WithConn( err := s.pg.WithConn(
ctx, ctx,
func(conn pg.Conn) error { func(conn pg.Conn) error {
return controls.LoadByFrameworkID(ctx, conn, s.scope, frameworkID, cursor) return controls.LoadByFrameworkID(
ctx,
conn,
s.scope,
frameworkID,
cursor,
)
}, },
) )
@@ -108,7 +125,13 @@ func (s *Service) ListControlTasks(
err := s.pg.WithConn( err := s.pg.WithConn(
ctx, ctx,
func(conn pg.Conn) error { func(conn pg.Conn) error {
return tasks.LoadByControlID(ctx, conn, s.scope, controlID, cursor) return tasks.LoadByControlID(
ctx,
conn,
s.scope,
controlID,
cursor,
)
}, },
) )