Add create framework sdk call

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-02-05 09:02:51 -08:00
parent 89fce182d2
commit beab525b89
2 changed files with 99 additions and 1 deletions

View File

@@ -30,7 +30,7 @@ import (
type (
Framework struct {
ID gid.GID
OrganizationID string
OrganizationID gid.GID
Name string
Description string
ContentRef string
@@ -149,3 +149,34 @@ LIMIT 1;
return nil
}
func (f Framework) Insert(
ctx context.Context,
conn pg.Conn,
) error {
q := `
INSERT INTO
frameworks
VALUES (
@frameworkd_id,
@organization_id,
@name,
@description,
@content_ref,
@created_at,
@updated_at
)
`
args := pgx.NamedArgs{
"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,
}
_, err := conn.Exec(ctx, q, args)
return err
}

View File

@@ -0,0 +1,67 @@
// 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 probo
import (
"context"
"fmt"
"time"
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/probo/coredata"
"go.gearno.de/kit/pg"
)
type (
CreateFrameworkRequest struct {
Name string
Description string
ContentRef string
}
)
func (s Service) CreateFramework(
ctx context.Context,
req CreateFrameworkRequest,
) (*coredata.Framework, error) {
now := time.Now()
frameworkID, err := gid.NewGID(coredata.FrameworkEntityType)
if err != nil {
return nil, fmt.Errorf("cannot create global id: %w", err)
}
framework := &coredata.Framework{
ID: frameworkID,
OrganizationID: gid.Nil,
Name: req.Name,
Description: req.Description,
ContentRef: req.ContentRef,
CreatedAt: now,
UpdatedAt: now,
}
err = s.pg.WithConn(
ctx,
func(conn pg.Conn) error {
return nil
},
)
if err != nil {
return nil, err
}
return framework, nil
}