Bootstrap coredata object

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-01-22 10:57:09 +01:00
parent 0904426891
commit b749c1277a
6 changed files with 158 additions and 2 deletions

4
go.mod
View File

@@ -4,7 +4,9 @@ go 1.23.4
require (
github.com/99designs/gqlgen v0.17.63
github.com/jackc/pgx/v5 v5.7.1
github.com/prometheus/client_golang v1.20.5
github.com/vektah/gqlparser/v2 v2.5.21
go.gearno.de/kit v0.0.0-20241119134016-ee4f36699e6b
go.opentelemetry.io/otel/trace v1.32.0
)
@@ -22,7 +24,6 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.1 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
@@ -32,7 +33,6 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sosodev/duration v1.3.1 // indirect
github.com/urfave/cli/v2 v2.27.5 // indirect
github.com/vektah/gqlparser/v2 v2.5.21 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.gearno.de/crypto/uuid v0.1.0 // indirect
go.gearno.de/x/panicf v0.1.1 // indirect

View File

@@ -0,0 +1,13 @@
package coredata
import "time"
type (
Control struct {
ID string
FrameworkID string
ContentID string
CreatedAt time.Time
UpdatedAt time.Time
}
)

View File

@@ -0,0 +1,13 @@
package coredata
import "time"
type (
Evidence struct {
ID string
TaskID string
ContentID string
CreatedAt time.Time
UpdatedAt time.Time
}
)

View File

@@ -0,0 +1,60 @@
package coredata
import (
"context"
"time"
"github.com/jackc/pgx/v5"
"go.gearno.de/kit/pg"
)
type (
Framework struct {
ID string
OrganizationID string
ContentID string
CreatedAt time.Time
UpdatedAt time.Time
}
)
func (f *Framework) scan(r pgx.Row) error {
return r.Scan(
&f.ID,
&f.OrganizationID,
&f.ContentID,
&f.CreatedAt,
&f.UpdatedAt,
)
}
func (f *Framework) LoadByID(
ctx context.Context,
conn pg.Conn,
frameworkID string,
) error {
q := `
SELECT
framework_id,
organization_id,
content_id,
created_at,
updated_at
FROM
frameworks
WHERE
framework_id = @framework_id
LIMIT 1;
`
args := pgx.NamedArgs{"framework_id": frameworkID}
r := conn.QueryRow(ctx, q, args)
f2 := Framework{}
if err := r.Scan(&f2); err != nil {
return err
}
*f = f2
return nil
}

View File

@@ -0,0 +1,58 @@
package coredata
import (
"context"
"time"
"github.com/jackc/pgx/v5"
"go.gearno.de/kit/pg"
)
type (
Organization struct {
ID string
Name string
CreatedAt time.Time
UpdatedAt time.Time
}
)
func (o *Organization) scan(r pgx.Row) error {
return r.Scan(
&o.ID,
&o.Name,
&o.CreatedAt,
&o.UpdatedAt,
)
}
func (o *Organization) LoadByID(
ctx context.Context,
conn pg.Conn,
organizationID string,
) error {
q := `
SELECT
organization_id,
name,
created_at,
updated_at
FROM
organizations
WHERE
organization_id = @organization_id
LIMIT 1;
`
args := pgx.NamedArgs{"organization_id": organizationID}
r := conn.QueryRow(ctx, q, args)
o2 := Organization{}
if err := r.Scan(&o2); err != nil {
return err
}
*o = o2
return nil
}

View File

@@ -0,0 +1,12 @@
package coredata
import "time"
type (
Task struct {
ID string
ContentID string
CreatedAt time.Time
UpdatedAt time.Time
}
)