From e9546b40c8befabda26c1598c124a6ee2a8d2b8f Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 28 May 2025 14:26:19 -0600 Subject: refactor: always provide a user in the request context --- app/domain/entity.go | 6 ++++++ app/domain/user.go | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'app/domain') diff --git a/app/domain/entity.go b/app/domain/entity.go index 0377c51..b2c2166 100644 --- a/app/domain/entity.go +++ b/app/domain/entity.go @@ -1,6 +1,12 @@ 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/user.go b/app/domain/user.go index a6adfa8..52cd780 100644 --- a/app/domain/user.go +++ b/app/domain/user.go @@ -10,11 +10,7 @@ type User struct { } func NewUser(options ...x.Configure[*User]) *User { - user := &User{} - for _, option := range options { - option(user) - } - return user + return New[*User](options...) } func (u *User) GetID() ID { -- cgit v1.2.3