diff --git a/internal/pkg/service/user/user.go b/internal/pkg/service/user/user.go index ea7d72ea..aac0c0a0 100644 --- a/internal/pkg/service/user/user.go +++ b/internal/pkg/service/user/user.go @@ -12,44 +12,44 @@ import ( "github.com/bastean/codexgo/v4/pkg/context/user/domain/repository" ) -func Start(repository repository.User, broker messages.Broker, hashing hashing.Hashing) { +func Start(repository repository.Repository, broker messages.Broker, hashing hashing.Hashing) { Create = &create.Handler{ Create: &create.Create{ - User: repository, + Repository: repository, }, Broker: broker, } Read = &read.Handler{ Read: &read.Read{ - User: repository, + Repository: repository, }, } Update = &update.Handler{ Update: &update.Update{ - User: repository, - Hashing: hashing, + Repository: repository, + Hashing: hashing, }, } Delete = &delete.Handler{ Delete: &delete.Delete{ - User: repository, - Hashing: hashing, + Repository: repository, + Hashing: hashing, }, } Verify = &verify.Handler{ Verify: &verify.Verify{ - User: repository, + Repository: repository, }, } Login = &login.Handler{ Login: &login.Login{ - User: repository, - Hashing: hashing, + Repository: repository, + Hashing: hashing, }, } } diff --git a/pkg/context/shared/domain/messages/valueobjs/status.go b/pkg/context/shared/domain/messages/valueobjs/status.go index adb44ab3..2b35daf3 100644 --- a/pkg/context/shared/domain/messages/valueobjs/status.go +++ b/pkg/context/shared/domain/messages/valueobjs/status.go @@ -18,7 +18,6 @@ type Status struct { func NewStatus(value string) (*Status, error) { value = strings.TrimSpace(value) - value = strings.ToLower(value) valueObj := &Status{ diff --git a/pkg/context/shared/domain/messages/valueobjs/type.go b/pkg/context/shared/domain/messages/valueobjs/type.go index 6a70a0fc..c14c5c6b 100644 --- a/pkg/context/shared/domain/messages/valueobjs/type.go +++ b/pkg/context/shared/domain/messages/valueobjs/type.go @@ -18,7 +18,6 @@ type Type struct { func NewType(value string) (*Type, error) { value = strings.TrimSpace(value) - value = strings.ToLower(value) valueObj := &Type{ diff --git a/pkg/context/user/application/create/command.handler_test.go b/pkg/context/user/application/create/command.handler_test.go index 3625d52b..de3030a7 100644 --- a/pkg/context/user/application/create/command.handler_test.go +++ b/pkg/context/user/application/create/command.handler_test.go @@ -26,7 +26,7 @@ func (suite *CreateTestSuite) SetupTest() { suite.repository = new(persistence.UserMock) suite.create = &create.Create{ - User: suite.repository, + Repository: suite.repository, } suite.sut = &create.Handler{ diff --git a/pkg/context/user/application/create/create.go b/pkg/context/user/application/create/create.go index dcf7752b..4483f530 100644 --- a/pkg/context/user/application/create/create.go +++ b/pkg/context/user/application/create/create.go @@ -7,11 +7,11 @@ import ( ) type Create struct { - repository.User + repository.Repository } func (create *Create) Run(user *user.User) error { - err := create.User.Save(user) + err := create.Repository.Save(user) if err != nil { return errors.BubbleUp(err, "Run") diff --git a/pkg/context/user/application/delete/command.handler_test.go b/pkg/context/user/application/delete/command.handler_test.go index 460616b6..3972aeda 100644 --- a/pkg/context/user/application/delete/command.handler_test.go +++ b/pkg/context/user/application/delete/command.handler_test.go @@ -27,8 +27,8 @@ func (suite *DeleteTestSuite) SetupTest() { suite.hashing = new(cryptographic.HashingMock) suite.delete = &delete.Delete{ - User: suite.repository, - Hashing: suite.hashing, + Repository: suite.repository, + Hashing: suite.hashing, } suite.sut = &delete.Handler{ @@ -44,7 +44,7 @@ func (suite *DeleteTestSuite) TestDelete() { Password: random.Password.Value, } - criteria := &repository.UserSearchCriteria{ + criteria := &repository.SearchCriteria{ Id: random.Id, } diff --git a/pkg/context/user/application/delete/delete.go b/pkg/context/user/application/delete/delete.go index 52874d53..470daa91 100644 --- a/pkg/context/user/application/delete/delete.go +++ b/pkg/context/user/application/delete/delete.go @@ -9,12 +9,12 @@ import ( ) type Delete struct { - repository.User + repository.Repository hashing.Hashing } func (delete *Delete) Run(id *user.Id, password *user.Password) error { - found, err := delete.User.Search(&repository.UserSearchCriteria{ + found, err := delete.Repository.Search(&repository.SearchCriteria{ Id: id, }) @@ -28,7 +28,7 @@ func (delete *Delete) Run(id *user.Id, password *user.Password) error { return errors.BubbleUp(err, "Run") } - err = delete.User.Delete(found.Id) + err = delete.Repository.Delete(found.Id) if err != nil { return errors.BubbleUp(err, "Run") diff --git a/pkg/context/user/application/login/login.go b/pkg/context/user/application/login/login.go index 4de5980e..c14b2478 100644 --- a/pkg/context/user/application/login/login.go +++ b/pkg/context/user/application/login/login.go @@ -9,12 +9,12 @@ import ( ) type Login struct { - repository.User + repository.Repository hashing.Hashing } func (login *Login) Run(email *user.Email, password *user.Password) (*user.User, error) { - found, err := login.User.Search(&repository.UserSearchCriteria{ + found, err := login.Repository.Search(&repository.SearchCriteria{ Email: email, }) diff --git a/pkg/context/user/application/login/query.handler_test.go b/pkg/context/user/application/login/query.handler_test.go index 680814c8..253c82c2 100644 --- a/pkg/context/user/application/login/query.handler_test.go +++ b/pkg/context/user/application/login/query.handler_test.go @@ -27,8 +27,8 @@ func (suite *LoginTestSuite) SetupTest() { suite.hashing = new(cryptographic.HashingMock) suite.login = &login.Login{ - User: suite.repository, - Hashing: suite.hashing, + Repository: suite.repository, + Hashing: suite.hashing, } suite.sut = &login.Handler{ @@ -44,7 +44,7 @@ func (suite *LoginTestSuite) TestLogin() { Password: random.Password.Value, } - criteria := &repository.UserSearchCriteria{ + criteria := &repository.SearchCriteria{ Email: random.Email, } diff --git a/pkg/context/user/application/read/query.handler_test.go b/pkg/context/user/application/read/query.handler_test.go index 545414f4..9fa33bef 100644 --- a/pkg/context/user/application/read/query.handler_test.go +++ b/pkg/context/user/application/read/query.handler_test.go @@ -23,7 +23,7 @@ func (suite *ReadTestSuite) SetupTest() { suite.repository = new(persistence.UserMock) suite.read = &read.Read{ - User: suite.repository, + Repository: suite.repository, } suite.sut = &read.Handler{ @@ -38,7 +38,7 @@ func (suite *ReadTestSuite) TestRead() { Id: random.Id.Value, } - criteria := &repository.UserSearchCriteria{ + criteria := &repository.SearchCriteria{ Id: random.Id, } diff --git a/pkg/context/user/application/read/read.go b/pkg/context/user/application/read/read.go index 03506052..56265418 100644 --- a/pkg/context/user/application/read/read.go +++ b/pkg/context/user/application/read/read.go @@ -7,11 +7,11 @@ import ( ) type Read struct { - repository.User + repository.Repository } func (read *Read) Run(id *user.Id) (*user.User, error) { - found, err := read.User.Search(&repository.UserSearchCriteria{ + found, err := read.Repository.Search(&repository.SearchCriteria{ Id: id, }) diff --git a/pkg/context/user/application/update/command.handler_test.go b/pkg/context/user/application/update/command.handler_test.go index e65561c7..b29498b5 100644 --- a/pkg/context/user/application/update/command.handler_test.go +++ b/pkg/context/user/application/update/command.handler_test.go @@ -27,8 +27,8 @@ func (suite *UpdateTestSuite) SetupTest() { suite.hashing = new(cryptographic.HashingMock) suite.update = &update.Update{ - User: suite.repository, - Hashing: suite.hashing, + Repository: suite.repository, + Hashing: suite.hashing, } suite.sut = &update.Handler{ @@ -48,7 +48,7 @@ func (suite *UpdateTestSuite) TestUpdate() { id, _ := user.NewId(command.Id) - criteria := &repository.UserSearchCriteria{ + criteria := &repository.SearchCriteria{ Id: id, } diff --git a/pkg/context/user/application/update/update.go b/pkg/context/user/application/update/update.go index c0cf9a22..25b5271e 100644 --- a/pkg/context/user/application/update/update.go +++ b/pkg/context/user/application/update/update.go @@ -9,12 +9,12 @@ import ( ) type Update struct { - repository.User + repository.Repository hashing.Hashing } func (update *Update) Run(account *user.User, updated *user.Password) error { - found, err := update.User.Search(&repository.UserSearchCriteria{ + found, err := update.Repository.Search(&repository.SearchCriteria{ Id: account.Id, }) @@ -34,7 +34,7 @@ func (update *Update) Run(account *user.User, updated *user.Password) error { account.Verified = found.Verified - err = update.User.Update(account) + err = update.Repository.Update(account) if err != nil { return errors.BubbleUp(err, "Run") diff --git a/pkg/context/user/application/verify/command.handler_test.go b/pkg/context/user/application/verify/command.handler_test.go index de64d22c..e037a57a 100644 --- a/pkg/context/user/application/verify/command.handler_test.go +++ b/pkg/context/user/application/verify/command.handler_test.go @@ -23,7 +23,7 @@ func (suite *VerifyTestSuite) SetupTest() { suite.repository = new(persistence.UserMock) suite.verify = &verify.Verify{ - User: suite.repository, + Repository: suite.repository, } suite.sut = &verify.Handler{ @@ -40,7 +40,7 @@ func (suite *VerifyTestSuite) TestVerify() { random.Id = id - criteria := &repository.UserSearchCriteria{ + criteria := &repository.SearchCriteria{ Id: id, } diff --git a/pkg/context/user/application/verify/verify.go b/pkg/context/user/application/verify/verify.go index 4713c234..8de47709 100644 --- a/pkg/context/user/application/verify/verify.go +++ b/pkg/context/user/application/verify/verify.go @@ -7,11 +7,11 @@ import ( ) type Verify struct { - repository.User + repository.Repository } func (verify *Verify) Run(id *user.Id) error { - found, err := verify.User.Search(&repository.UserSearchCriteria{ + found, err := verify.Repository.Search(&repository.SearchCriteria{ Id: id, }) @@ -23,7 +23,7 @@ func (verify *Verify) Run(id *user.Id) error { return nil } - err = verify.User.Verify(id) + err = verify.Repository.Verify(id) if err != nil { return errors.BubbleUp(err, "Run") diff --git a/pkg/context/user/domain/repository/user.go b/pkg/context/user/domain/repository/repository.go similarity index 68% rename from pkg/context/user/domain/repository/user.go rename to pkg/context/user/domain/repository/repository.go index 80a15a33..eabc1393 100644 --- a/pkg/context/user/domain/repository/user.go +++ b/pkg/context/user/domain/repository/repository.go @@ -4,15 +4,15 @@ import ( "github.com/bastean/codexgo/v4/pkg/context/user/domain/aggregate/user" ) -type UserSearchCriteria struct { +type SearchCriteria struct { *user.Id *user.Email } -type User interface { +type Repository interface { Save(*user.User) error Verify(*user.Id) error Update(*user.User) error Delete(*user.Id) error - Search(*UserSearchCriteria) (*user.User, error) + Search(*SearchCriteria) (*user.User, error) } diff --git a/pkg/context/user/infrastructure/persistence/collection/user.go b/pkg/context/user/infrastructure/persistence/collection/user.go index 3272ce42..f934fac5 100644 --- a/pkg/context/user/infrastructure/persistence/collection/user.go +++ b/pkg/context/user/infrastructure/persistence/collection/user.go @@ -128,7 +128,7 @@ func (mongoDB *User) Delete(id *user.Id) error { return nil } -func (mongoDB *User) Search(criteria *repository.UserSearchCriteria) (*user.User, error) { +func (mongoDB *User) Search(criteria *repository.SearchCriteria) (*user.User, error) { var filter bson.D var index string @@ -179,7 +179,7 @@ func (mongoDB *User) Search(criteria *repository.UserSearchCriteria) (*user.User return found, nil } -func OpenUser(session *mongodb.MongoDB, name string, hashing hashing.Hashing) (repository.User, error) { +func OpenUser(session *mongodb.MongoDB, name string, hashing hashing.Hashing) (repository.Repository, error) { collection := session.Database.Collection(name) _, err := collection.Indexes().CreateMany(context.Background(), []mongo.IndexModel{ diff --git a/pkg/context/user/infrastructure/persistence/collection/user_test.go b/pkg/context/user/infrastructure/persistence/collection/user_test.go index c5cf0ca0..13bccf57 100644 --- a/pkg/context/user/infrastructure/persistence/collection/user_test.go +++ b/pkg/context/user/infrastructure/persistence/collection/user_test.go @@ -16,7 +16,7 @@ import ( type UserTestSuite struct { suite.Suite - sut repository.User + sut repository.Repository hashing *cryptographic.HashingMock } @@ -44,7 +44,7 @@ func (suite *UserTestSuite) TestSave() { suite.hashing.AssertExpectations(suite.T()) - criteria := &repository.UserSearchCriteria{ + criteria := &repository.SearchCriteria{ Id: expected.Id, } @@ -92,7 +92,7 @@ func (suite *UserTestSuite) TestVerify() { suite.NoError(suite.sut.Verify(random.Id)) - criteria := &repository.UserSearchCriteria{ + criteria := &repository.SearchCriteria{ Id: random.Id, } @@ -120,7 +120,7 @@ func (suite *UserTestSuite) TestUpdate() { suite.hashing.AssertExpectations(suite.T()) - criteria := &repository.UserSearchCriteria{ + criteria := &repository.SearchCriteria{ Id: expected.Id, } @@ -140,7 +140,7 @@ func (suite *UserTestSuite) TestDelete() { suite.NoError(suite.sut.Delete(random.Id)) - criteria := &repository.UserSearchCriteria{ + criteria := &repository.SearchCriteria{ Id: random.Id, } @@ -158,7 +158,7 @@ func (suite *UserTestSuite) TestSearch() { suite.NoError(suite.sut.Save(expected)) - criteria := &repository.UserSearchCriteria{ + criteria := &repository.SearchCriteria{ Id: expected.Id, } @@ -172,7 +172,7 @@ func (suite *UserTestSuite) TestSearch() { func (suite *UserTestSuite) TestSearchErrDocumentNotFound() { random := user.Random() - criteria := &repository.UserSearchCriteria{ + criteria := &repository.SearchCriteria{ Id: random.Id, } diff --git a/pkg/context/user/infrastructure/persistence/user.mock.go b/pkg/context/user/infrastructure/persistence/user.mock.go index d45d4202..e06c1a43 100644 --- a/pkg/context/user/infrastructure/persistence/user.mock.go +++ b/pkg/context/user/infrastructure/persistence/user.mock.go @@ -30,7 +30,7 @@ func (repository *UserMock) Delete(id *user.Id) error { return nil } -func (repository *UserMock) Search(criteria *repository.UserSearchCriteria) (*user.User, error) { +func (repository *UserMock) Search(criteria *repository.SearchCriteria) (*user.User, error) { args := repository.Called(criteria) return args.Get(0).(*user.User), nil }