2021-09-23 23:06:22 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-03-13 10:58:34 +00:00
|
|
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
2021-09-23 23:06:22 +00:00
|
|
|
)
|
|
|
|
|
2024-05-08 10:01:49 +00:00
|
|
|
type (
|
|
|
|
Repository interface {
|
2024-05-15 11:59:57 +00:00
|
|
|
Fetch(ctx context.Context, cid domain.ClientID) (*domain.Client, error)
|
2024-05-08 10:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dummyClientRepository struct{}
|
|
|
|
|
|
|
|
stubClientRepository struct {
|
|
|
|
client *domain.Client
|
|
|
|
error error
|
|
|
|
}
|
|
|
|
)
|
2021-12-29 20:53:31 +00:00
|
|
|
|
2022-02-01 17:27:48 +00:00
|
|
|
var ErrNotExist error = domain.NewError(
|
|
|
|
domain.ErrorCodeInvalidClient,
|
|
|
|
"client with the specified ID does not exist",
|
|
|
|
"",
|
|
|
|
)
|
2024-05-08 10:01:49 +00:00
|
|
|
|
|
|
|
// NewDummyClientRepository creates a new dummy [Repository] implementation what
|
|
|
|
// do nothing.
|
|
|
|
func NewDummyClientRepository() Repository {
|
|
|
|
return dummyClientRepository{}
|
|
|
|
}
|
|
|
|
|
2024-05-15 11:59:57 +00:00
|
|
|
func (dummyClientRepository) Fetch(_ context.Context, _ domain.ClientID) (*domain.Client, error) {
|
2024-05-08 10:01:49 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-15 11:59:57 +00:00
|
|
|
func (repo *stubClientRepository) Fetch(_ context.Context, _ domain.ClientID) (*domain.Client, error) {
|
2024-05-08 10:01:49 +00:00
|
|
|
return repo.client, repo.error
|
|
|
|
}
|