summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-04-25 11:00:53 -0600
committermo khan <mo@mokhan.ca>2025-04-25 11:00:53 -0600
commit0053db0d265af313dd281db5cf1e73236cde30c6 (patch)
tree2ec76a6d42fc903aaa1d0e135addd95d1fd945e4 /pkg
parent33981e04bebe39c16d3bbb3af84c8772b00102fd (diff)
refactor: move domain package into app
Diffstat (limited to 'pkg')
-rw-r--r--pkg/db/in_memory_repository.go2
-rw-r--r--pkg/db/in_memory_repository_test.go2
-rw-r--r--pkg/domain/entity.go7
-rw-r--r--pkg/domain/id.go7
-rw-r--r--pkg/domain/repository.go7
-rw-r--r--pkg/domain/sparkle.go60
-rw-r--r--pkg/domain/sparkle_test.go51
-rw-r--r--pkg/domain/user.go34
-rw-r--r--pkg/domain/user_test.go24
-rw-r--r--pkg/key/init.go2
-rw-r--r--pkg/web/middleware/init.go2
-rw-r--r--pkg/web/middleware/require_user_test.go2
-rw-r--r--pkg/web/middleware/user.go2
-rw-r--r--pkg/web/middleware/user_test.go2
14 files changed, 7 insertions, 197 deletions
diff --git a/pkg/db/in_memory_repository.go b/pkg/db/in_memory_repository.go
index 3e183fd..5b84dbf 100644
--- a/pkg/db/in_memory_repository.go
+++ b/pkg/db/in_memory_repository.go
@@ -2,7 +2,7 @@ package db
import (
"github.com/xlgmokha/x/pkg/x"
- "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/domain"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
)
diff --git a/pkg/db/in_memory_repository_test.go b/pkg/db/in_memory_repository_test.go
index 382a656..bd9d12f 100644
--- a/pkg/db/in_memory_repository_test.go
+++ b/pkg/db/in_memory_repository_test.go
@@ -5,7 +5,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/domain"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain"
)
func TestInMemoryRepository(t *testing.T) {
diff --git a/pkg/domain/entity.go b/pkg/domain/entity.go
deleted file mode 100644
index fb1cab8..0000000
--- a/pkg/domain/entity.go
+++ /dev/null
@@ -1,7 +0,0 @@
-package domain
-
-type Entity interface {
- GetID() ID
- SetID(id ID) error
- Validate() error
-}
diff --git a/pkg/domain/id.go b/pkg/domain/id.go
deleted file mode 100644
index 117a9ad..0000000
--- a/pkg/domain/id.go
+++ /dev/null
@@ -1,7 +0,0 @@
-package domain
-
-type ID string
-
-func (id ID) String() string {
- return string(id)
-}
diff --git a/pkg/domain/repository.go b/pkg/domain/repository.go
deleted file mode 100644
index fb7b6da..0000000
--- a/pkg/domain/repository.go
+++ /dev/null
@@ -1,7 +0,0 @@
-package domain
-
-type Repository[T Entity] interface {
- All() []T
- Find(ID) T
- Save(T) error
-}
diff --git a/pkg/domain/sparkle.go b/pkg/domain/sparkle.go
deleted file mode 100644
index 68aed67..0000000
--- a/pkg/domain/sparkle.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package domain
-
-import (
- "errors"
- "regexp"
-
- "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
-)
-
-type Sparkle struct {
- ID ID `json:"id" jsonapi:"primary,sparkles"`
- Sparklee string `json:"sparklee" jsonapi:"attr,sparklee"`
- Author *User `json:"author" jsonapi:"attr,author"`
- Reason string `json:"reason" jsonapi:"attr,reason"`
-}
-
-var SparkleRegex = regexp.MustCompile(`\A\s*(?P<sparklee>@\w+)\s+(?P<reason>.+)\z`)
-var SparkleeIndex = SparkleRegex.SubexpIndex("sparklee")
-var ReasonIndex = SparkleRegex.SubexpIndex("reason")
-
-var ReasonIsRequired = errors.New("Reason is required")
-var SparkleIsEmpty = errors.New("Sparkle is empty")
-var SparkleIsInvalid = errors.New("Sparkle is invalid")
-var SparkleeIsRequired = errors.New("Sparklee is required")
-
-func NewSparkle(text string) (*Sparkle, error) {
- if len(text) == 0 {
- return nil, SparkleIsEmpty
- }
-
- matches := SparkleRegex.FindStringSubmatch(text)
- if len(matches) == 0 {
- return nil, SparkleIsInvalid
- }
-
- return &Sparkle{
- ID: ID(pls.GenerateULID()),
- Sparklee: matches[SparkleeIndex],
- Reason: matches[ReasonIndex],
- }, nil
-}
-
-func (s *Sparkle) GetID() ID {
- return s.ID
-}
-
-func (s *Sparkle) SetID(id ID) error {
- s.ID = id
- return nil
-}
-
-func (s *Sparkle) Validate() error {
- if s.Sparklee == "" {
- return SparkleeIsRequired
- }
- if s.Reason == "" {
- return ReasonIsRequired
- }
- return nil
-}
diff --git a/pkg/domain/sparkle_test.go b/pkg/domain/sparkle_test.go
deleted file mode 100644
index 8d81afd..0000000
--- a/pkg/domain/sparkle_test.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package domain
-
-import (
- "testing"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestSparkle(t *testing.T) {
- t.Run("NewSparkle", func(t *testing.T) {
- t.Run("with a valid body", func(t *testing.T) {
- sparkle, err := NewSparkle("@tanuki for helping me with my homework!")
-
- assert.Nil(t, err)
- if err != nil {
- assert.Equal(t, "@tanuki", sparkle.Sparklee)
- assert.Equal(t, "for helping me with my homework!", sparkle.Reason)
- }
- })
-
- t.Run("with an empty body", func(t *testing.T) {
- sparkle, err := NewSparkle("")
-
- assert.Nil(t, sparkle)
- assert.NotNil(t, err)
- if err != nil {
- assert.Equal(t, "Sparkle is empty", err.Error())
- }
- })
-
- t.Run("without a reason", func(t *testing.T) {
- sparkle, err := NewSparkle("@tanuki")
-
- assert.Nil(t, sparkle)
- assert.NotNil(t, err)
- if err != nil {
- assert.Equal(t, "Sparkle is invalid", err.Error())
- }
- })
-
- t.Run("without a username", func(t *testing.T) {
- sparkle, err := NewSparkle("for helping me with my homework")
-
- assert.Nil(t, sparkle)
- assert.NotNil(t, err)
- if err != nil {
- assert.Equal(t, "Sparkle is invalid", err.Error())
- }
- })
- })
-}
diff --git a/pkg/domain/user.go b/pkg/domain/user.go
deleted file mode 100644
index aae17f6..0000000
--- a/pkg/domain/user.go
+++ /dev/null
@@ -1,34 +0,0 @@
-package domain
-
-type User struct {
- ID ID `json:"id" jsonapi:"primary,users"`
- Username string `json:"username" jsonapi:"attr,username"`
- Email string `json:"email" jsonapi:"attr,email"`
- ProfileURL string `json:"profile" jsonapi:"attr,profile"`
- Picture string `json:"picture" jsonapi:"attr,picture"`
-}
-
-func NewUser() *User {
- return &User{}
-}
-
-func (u *User) GetID() ID {
- return u.ID
-}
-
-func (u *User) SetID(id ID) error {
- u.ID = id
- return nil
-}
-
-func (u *User) Validate() error {
- return nil
-}
-
-func (self *User) Sparkle(sparklee string, reason string) *Sparkle {
- return &Sparkle{
- Sparklee: sparklee,
- Author: self,
- Reason: reason,
- }
-}
diff --git a/pkg/domain/user_test.go b/pkg/domain/user_test.go
deleted file mode 100644
index 1576d6d..0000000
--- a/pkg/domain/user_test.go
+++ /dev/null
@@ -1,24 +0,0 @@
-package domain
-
-import (
- "testing"
-
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
-)
-
-func TestUser(t *testing.T) {
- t.Run("Sparkle", func(t *testing.T) {
- t.Run("returns a new Sparkle", func(t *testing.T) {
- tanuki := &User{Username: "tanuki"}
- user := &User{}
-
- sparkle := user.Sparkle(tanuki.Username, "for helping me with my homework")
-
- require.NotNil(t, sparkle)
- assert.Equal(t, tanuki.Username, sparkle.Sparklee)
- assert.Equal(t, "for helping me with my homework", sparkle.Reason)
- assert.Equal(t, user, sparkle.Author)
- })
- })
-}
diff --git a/pkg/key/init.go b/pkg/key/init.go
index f2d7b7f..2c67e05 100644
--- a/pkg/key/init.go
+++ b/pkg/key/init.go
@@ -2,7 +2,7 @@ package key
import (
"github.com/xlgmokha/x/pkg/context"
- "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/domain"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc"
)
diff --git a/pkg/web/middleware/init.go b/pkg/web/middleware/init.go
index ac06c32..f1a693d 100644
--- a/pkg/web/middleware/init.go
+++ b/pkg/web/middleware/init.go
@@ -2,7 +2,7 @@ package middleware
import (
"github.com/xlgmokha/x/pkg/mapper"
- "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/domain"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc"
)
diff --git a/pkg/web/middleware/require_user_test.go b/pkg/web/middleware/require_user_test.go
index ac764f6..68b9911 100644
--- a/pkg/web/middleware/require_user_test.go
+++ b/pkg/web/middleware/require_user_test.go
@@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/domain"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test"
)
diff --git a/pkg/web/middleware/user.go b/pkg/web/middleware/user.go
index 1e46187..194ded6 100644
--- a/pkg/web/middleware/user.go
+++ b/pkg/web/middleware/user.go
@@ -6,7 +6,7 @@ import (
"github.com/xlgmokha/x/pkg/log"
"github.com/xlgmokha/x/pkg/mapper"
"github.com/xlgmokha/x/pkg/x"
- "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/domain"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc"
)
diff --git a/pkg/web/middleware/user_test.go b/pkg/web/middleware/user_test.go
index c18bfdb..b09fa7b 100644
--- a/pkg/web/middleware/user_test.go
+++ b/pkg/web/middleware/user_test.go
@@ -6,8 +6,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/db"
- "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/domain"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/key"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"