🧑💻 Created dummy and stub repository and use case for client
This commit is contained in:
parent
ffeaf8c679
commit
9048d0f77c
|
@ -6,13 +6,53 @@ import (
|
|||
"source.toby3d.me/toby3d/auth/internal/domain"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
Create(ctx context.Context, client domain.Client) error
|
||||
Get(ctx context.Context, cid domain.ClientID) (*domain.Client, error)
|
||||
}
|
||||
type (
|
||||
Repository interface {
|
||||
Create(ctx context.Context, client domain.Client) error
|
||||
Get(ctx context.Context, cid domain.ClientID) (*domain.Client, error)
|
||||
}
|
||||
|
||||
dummyClientRepository struct{}
|
||||
|
||||
stubClientRepository struct {
|
||||
client *domain.Client
|
||||
error error
|
||||
}
|
||||
)
|
||||
|
||||
var ErrNotExist error = domain.NewError(
|
||||
domain.ErrorCodeInvalidClient,
|
||||
"client with the specified ID does not exist",
|
||||
"",
|
||||
)
|
||||
|
||||
// NewDummyClientRepository creates a new dummy [Repository] implementation what
|
||||
// do nothing.
|
||||
func NewDummyClientRepository() Repository {
|
||||
return dummyClientRepository{}
|
||||
}
|
||||
|
||||
func (dummyClientRepository) Create(_ context.Context, _ domain.Client) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dummyClientRepository) Get(_ context.Context, _ domain.ClientID) (*domain.Client, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// NewStubClientRepository creates a new stub [Repository] implementation what
|
||||
// always return data provided here.
|
||||
func NewStubClientRepository(client *domain.Client, err error) Repository {
|
||||
return &stubClientRepository{
|
||||
client: client,
|
||||
error: err,
|
||||
}
|
||||
}
|
||||
|
||||
func (repo *stubClientRepository) Create(_ context.Context, _ domain.Client) error {
|
||||
return repo.error
|
||||
}
|
||||
|
||||
func (repo *stubClientRepository) Get(_ context.Context, _ domain.ClientID) (*domain.Client, error) {
|
||||
return repo.client, repo.error
|
||||
}
|
||||
|
|
|
@ -6,13 +6,44 @@ import (
|
|||
"source.toby3d.me/toby3d/auth/internal/domain"
|
||||
)
|
||||
|
||||
type UseCase interface {
|
||||
// Discovery returns client public information bu ClientID URL.
|
||||
Discovery(ctx context.Context, id domain.ClientID) (*domain.Client, error)
|
||||
}
|
||||
type (
|
||||
UseCase interface {
|
||||
// Discovery returns client public information bu ClientID URL.
|
||||
Discovery(ctx context.Context, id domain.ClientID) (*domain.Client, error)
|
||||
}
|
||||
|
||||
dummyClientUseCase struct{}
|
||||
|
||||
stubClientUseCase struct {
|
||||
client *domain.Client
|
||||
error error
|
||||
}
|
||||
)
|
||||
|
||||
var ErrInvalidMe error = domain.NewError(
|
||||
domain.ErrorCodeInvalidRequest,
|
||||
"cannot fetch client endpoints on provided me",
|
||||
"",
|
||||
)
|
||||
|
||||
// NewDummyClientUseCase returns dummy [UseCase] what do nothing.
|
||||
func NewDummyClientUseCase() UseCase {
|
||||
return dummyClientUseCase{}
|
||||
}
|
||||
|
||||
func (dummyClientUseCase) Discovery(_ context.Context, _ domain.ClientID) (*domain.Client, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// NewDummyClientUseCase returns stub [UseCase] what always returns data
|
||||
// provided here.
|
||||
func NewStubClientUseCase(client *domain.Client, err error) UseCase {
|
||||
return &stubClientUseCase{
|
||||
client: client,
|
||||
error: err,
|
||||
}
|
||||
}
|
||||
|
||||
func (ucase *stubClientUseCase) Discovery(_ context.Context, _ domain.ClientID) (*domain.Client, error) {
|
||||
return ucase.client, ucase.error
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue