MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Create

Method Create

app/controlplane/pkg/data/organization.go:45–61  ·  view source on GitHub ↗
(ctx context.Context, name string)

Source from the content-addressed store, hash-verified

43}
44
45func (r *OrganizationRepo) Create(ctx context.Context, name string) (*biz.Organization, error) {
46 ctx, span := otelx.Start(ctx, organizationRepoTracer, "OrganizationRepo.Create")
47 defer span.End()
48
49 org, err := r.data.DB.Organization.Create().
50 SetName(name).
51 Save(ctx)
52 if err != nil && ent.IsConstraintError(err) {
53 return nil, biz.NewErrAlreadyExists(err)
54 } else if err != nil {
55 return nil, err
56 }
57
58 // Reloading the organization to get the proper created_at field from the DB
59 // Otherwise there is a mismatch between the created_at field in the DB (millisecods) and the one in the struct (nanoseconds)
60 return r.FindByID(ctx, org.ID)
61}
62
63func (r *OrganizationRepo) FindByID(ctx context.Context, id uuid.UUID) (*biz.Organization, error) {
64 ctx, span := otelx.Start(ctx, organizationRepoTracer, "OrganizationRepo.FindByID")

Callers

nothing calls this directly

Implementers 3

OrganizationRepoapp/controlplane/pkg/biz/mocks/Organiz
OrganizationRepo_Expecterapp/controlplane/pkg/biz/mocks/Organiz
OrganizationRepoapp/controlplane/pkg/data/organization

Calls 7

FindByIDMethod · 0.95
StartFunction · 0.92
IsConstraintErrorFunction · 0.92
NewErrAlreadyExistsFunction · 0.92
SaveMethod · 0.65
CreateMethod · 0.65
SetNameMethod · 0.45

Tested by

no test coverage detected