Skip to content

Commit

Permalink
refactor(domain): rename user repository
Browse files Browse the repository at this point in the history
  • Loading branch information
bastean committed Aug 10, 2024
1 parent 23807d5 commit 8781bd1
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 54 deletions.
20 changes: 10 additions & 10 deletions internal/pkg/service/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
1 change: 0 additions & 1 deletion pkg/context/shared/domain/messages/valueobjs/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type Status struct {

func NewStatus(value string) (*Status, error) {
value = strings.TrimSpace(value)

value = strings.ToLower(value)

valueObj := &Status{
Expand Down
1 change: 0 additions & 1 deletion pkg/context/shared/domain/messages/valueobjs/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type Type struct {

func NewType(value string) (*Type, error) {
value = strings.TrimSpace(value)

value = strings.ToLower(value)

valueObj := &Type{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions pkg/context/user/application/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions pkg/context/user/application/delete/command.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -44,7 +44,7 @@ func (suite *DeleteTestSuite) TestDelete() {
Password: random.Password.Value,
}

criteria := &repository.UserSearchCriteria{
criteria := &repository.SearchCriteria{
Id: random.Id,
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/context/user/application/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions pkg/context/user/application/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
6 changes: 3 additions & 3 deletions pkg/context/user/application/login/query.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -44,7 +44,7 @@ func (suite *LoginTestSuite) TestLogin() {
Password: random.Password.Value,
}

criteria := &repository.UserSearchCriteria{
criteria := &repository.SearchCriteria{
Email: random.Email,
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/context/user/application/read/query.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -38,7 +38,7 @@ func (suite *ReadTestSuite) TestRead() {
Id: random.Id.Value,
}

criteria := &repository.UserSearchCriteria{
criteria := &repository.SearchCriteria{
Id: random.Id,
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/context/user/application/read/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
6 changes: 3 additions & 3 deletions pkg/context/user/application/update/command.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -48,7 +48,7 @@ func (suite *UpdateTestSuite) TestUpdate() {

id, _ := user.NewId(command.Id)

criteria := &repository.UserSearchCriteria{
criteria := &repository.SearchCriteria{
Id: id,
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/context/user/application/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions pkg/context/user/application/verify/command.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -40,7 +40,7 @@ func (suite *VerifyTestSuite) TestVerify() {

random.Id = id

criteria := &repository.UserSearchCriteria{
criteria := &repository.SearchCriteria{
Id: id,
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/context/user/application/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

type UserTestSuite struct {
suite.Suite
sut repository.User
sut repository.Repository
hashing *cryptographic.HashingMock
}

Expand Down Expand Up @@ -44,7 +44,7 @@ func (suite *UserTestSuite) TestSave() {

suite.hashing.AssertExpectations(suite.T())

criteria := &repository.UserSearchCriteria{
criteria := &repository.SearchCriteria{
Id: expected.Id,
}

Expand Down Expand Up @@ -92,7 +92,7 @@ func (suite *UserTestSuite) TestVerify() {

suite.NoError(suite.sut.Verify(random.Id))

criteria := &repository.UserSearchCriteria{
criteria := &repository.SearchCriteria{
Id: random.Id,
}

Expand Down Expand Up @@ -120,7 +120,7 @@ func (suite *UserTestSuite) TestUpdate() {

suite.hashing.AssertExpectations(suite.T())

criteria := &repository.UserSearchCriteria{
criteria := &repository.SearchCriteria{
Id: expected.Id,
}

Expand All @@ -140,7 +140,7 @@ func (suite *UserTestSuite) TestDelete() {

suite.NoError(suite.sut.Delete(random.Id))

criteria := &repository.UserSearchCriteria{
criteria := &repository.SearchCriteria{
Id: random.Id,
}

Expand All @@ -158,7 +158,7 @@ func (suite *UserTestSuite) TestSearch() {

suite.NoError(suite.sut.Save(expected))

criteria := &repository.UserSearchCriteria{
criteria := &repository.SearchCriteria{
Id: expected.Id,
}

Expand All @@ -172,7 +172,7 @@ func (suite *UserTestSuite) TestSearch() {
func (suite *UserTestSuite) TestSearchErrDocumentNotFound() {
random := user.Random()

criteria := &repository.UserSearchCriteria{
criteria := &repository.SearchCriteria{
Id: random.Id,
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/context/user/infrastructure/persistence/user.mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 8781bd1

Please sign in to comment.