Last active
May 19, 2018 14:25
-
-
Save vporoshok/74e315f0476c2ff95fedd264792d5502 to your computer and use it in GitHub Desktop.
Action example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package action | |
import ( | |
"context" | |
"github.com/vporoshok/bfapp/internal/model" | |
) | |
// TxManager implement transaction decorator | |
type TxConnection interface { | |
WithTx(context.Context, func(context.Context) error) error | |
} | |
// UserRepository provide methods to CRUD users in db | |
type UserRepository interface { | |
Save(context.Context, *model.User) error | |
GetByID(context.Context, int) (*model.User, error) | |
} | |
// GroupRepository provides methods to CRUD groups in db | |
type GroupRepository interface { | |
Save(context.Context, *model.Group) error | |
GetByID(context.Context, int) (*model.Group, error) | |
} | |
// EventBus provide methods to event mediator bus | |
type EventBus interface { | |
Send(context.Context, *model.Event) error | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package action | |
import ( | |
"context" | |
"github.com/vporoshok/bfapp/internal/model" | |
) | |
// CreateUser with group and event notification | |
type CreateUser interface { | |
Do(ctx context.Context, email, password string) (*model.User, error) | |
} | |
type createUser struct { | |
txConnection CreateUserTxConnection | |
userRepository CreateUserUserRepository | |
groupRepository CreateUserGroupRepository | |
eventBus CreateUserEventBus | |
} | |
// NewCreateUser is a constructor | |
func NewCreateUser(txConnection TxConnection, userRepository UserRepository, groupRepository GroupRepository, eventBus EventBus) CreateUser { | |
return &createUser{ | |
txConnection, | |
userRepository, | |
groupRepository, | |
eventBus, | |
} | |
} | |
func (cu *createUser) Do(ctx context.Context, email string, password string) (*model.User, error) { | |
// Тут собственно вся логика создания | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment