summaryrefslogtreecommitdiff
path: root/app/domain
diff options
context:
space:
mode:
Diffstat (limited to 'app/domain')
-rw-r--r--app/domain/entity.go6
-rw-r--r--app/domain/identifiable.go12
-rw-r--r--app/domain/sparkle.go3
-rw-r--r--app/domain/sparkle_test.go15
-rw-r--r--app/domain/user.go5
5 files changed, 24 insertions, 17 deletions
diff --git a/app/domain/entity.go b/app/domain/entity.go
index b2c2166..0377c51 100644
--- a/app/domain/entity.go
+++ b/app/domain/entity.go
@@ -1,12 +1,6 @@
package domain
-import "github.com/xlgmokha/x/pkg/x"
-
type Entity interface {
Identifiable
Validate() error
}
-
-func New[T Entity](options ...x.Configure[T]) T {
- return x.New[T](x.Map[x.Configure[T], x.Option[T]](options, x.With[T])...)
-}
diff --git a/app/domain/identifiable.go b/app/domain/identifiable.go
index 190f20c..3a39cf9 100644
--- a/app/domain/identifiable.go
+++ b/app/domain/identifiable.go
@@ -3,17 +3,21 @@ package domain
import (
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
"github.com/xlgmokha/x/pkg/x"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
)
type Identifiable interface {
GetID() ID
SetID(id ID) error
- ToGID() string
ToObjectReference() *v1.ObjectReference
}
-func WithID[T Identifiable](id ID) x.Configure[T] {
- return func(item T) {
+func WithID[T Identifiable](id ID) x.Option[T] {
+ return x.With(func(item T) {
item.SetID(id)
- }
+ })
+}
+
+func WithULID[T Identifiable]() x.Option[T] {
+ return WithID[T](ID(pls.GenerateULID()))
}
diff --git a/app/domain/sparkle.go b/app/domain/sparkle.go
index c9ff02a..2ea5a53 100644
--- a/app/domain/sparkle.go
+++ b/app/domain/sparkle.go
@@ -57,8 +57,7 @@ func (s *Sparkle) ToGID() string {
func (self *Sparkle) ToObjectReference() *v1.ObjectReference {
return &v1.ObjectReference{
ObjectType: "sparkle",
- // ObjectId: self.ID.String(),
- ObjectId: "1",
+ ObjectId: self.ID.String(),
}
}
diff --git a/app/domain/sparkle_test.go b/app/domain/sparkle_test.go
index 8d81afd..c040d89 100644
--- a/app/domain/sparkle_test.go
+++ b/app/domain/sparkle_test.go
@@ -1,9 +1,12 @@
package domain
import (
+ "fmt"
"testing"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+ "github.com/xlgmokha/x/pkg/x"
)
func TestSparkle(t *testing.T) {
@@ -48,4 +51,16 @@ func TestSparkle(t *testing.T) {
}
})
})
+
+ t.Run("ToObjectReference", func(t *testing.T) {
+ t.Run("returns a valid object reference", func(t *testing.T) {
+ sparkle := x.New[*Sparkle](WithULID[*Sparkle]())
+ reference := sparkle.ToObjectReference()
+
+ require.NotNil(t, reference)
+ require.NoError(t, reference.Validate())
+ require.NoError(t, reference.ValidateAll())
+ assert.Equal(t, fmt.Sprintf("object_type:\"sparkle\" object_id:\"%s\"", sparkle.ID), reference.String())
+ })
+ })
}
diff --git a/app/domain/user.go b/app/domain/user.go
index e618b5f..c9dcfb4 100644
--- a/app/domain/user.go
+++ b/app/domain/user.go
@@ -2,7 +2,6 @@ package domain
import (
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
- "github.com/xlgmokha/x/pkg/x"
)
type User struct {
@@ -12,10 +11,6 @@ type User struct {
Picture string `json:"picture" jsonapi:"attr,picture"`
}
-func NewUser(options ...x.Configure[*User]) *User {
- return New[*User](options...)
-}
-
func (u *User) GetID() ID {
return u.ID
}