🔥 Removed memory client repository
All checks were successful
/ docker (push) Successful in 1m43s

This commit is contained in:
Maxim Lebedev 2024-05-15 16:59:57 +05:00
parent c35fe67be9
commit 1c88d31dc2
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
5 changed files with 6 additions and 61 deletions

View File

@ -8,8 +8,7 @@ import (
type (
Repository interface {
Create(ctx context.Context, client domain.Client) error
Get(ctx context.Context, cid domain.ClientID) (*domain.Client, error)
Fetch(ctx context.Context, cid domain.ClientID) (*domain.Client, error)
}
dummyClientRepository struct{}
@ -32,11 +31,7 @@ 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) {
func (dummyClientRepository) Fetch(_ context.Context, _ domain.ClientID) (*domain.Client, error) {
return nil, nil
}
@ -49,10 +44,6 @@ func NewStubClientRepository(client *domain.Client, err error) Repository {
}
}
func (repo *stubClientRepository) Create(_ context.Context, _ domain.Client) error {
return repo.error
}
func (repo *stubClientRepository) Get(_ context.Context, _ domain.ClientID) (*domain.Client, error) {
func (repo *stubClientRepository) Fetch(_ context.Context, _ domain.ClientID) (*domain.Client, error) {
return repo.client, repo.error
}

View File

@ -55,12 +55,7 @@ func NewHTTPClientRepository(c *http.Client) client.Repository {
}
}
// WARN(toby3d): not implemented.
func (httpClientRepository) Create(_ context.Context, _ domain.Client) error {
return nil
}
func (repo httpClientRepository) Get(ctx context.Context, cid domain.ClientID) (*domain.Client, error) {
func (repo *httpClientRepository) Fetch(ctx context.Context, cid domain.ClientID) (*domain.Client, error) {
out := &domain.Client{
ID: cid,
RedirectURI: make([]*url.URL, 0),

View File

@ -44,7 +44,7 @@ func TestGet(t *testing.T) {
client.ID = *domain.TestClientID(t, srv.URL+"/")
clients := repository.NewHTTPClientRepository(srv.Client())
result, err := clients.Get(context.Background(), client.ID)
result, err := clients.Fetch(context.Background(), client.ID)
if err != nil {
t.Fatal(err)
}

View File

@ -1,41 +0,0 @@
package memory
import (
"context"
"sync"
"source.toby3d.me/toby3d/auth/internal/client"
"source.toby3d.me/toby3d/auth/internal/domain"
)
type memoryClientRepository struct {
mutex *sync.RWMutex
clients map[string]domain.Client
}
func NewMemoryClientRepository() client.Repository {
return &memoryClientRepository{
mutex: new(sync.RWMutex),
clients: make(map[string]domain.Client),
}
}
func (repo memoryClientRepository) Create(ctx context.Context, client domain.Client) error {
repo.mutex.RLock()
defer repo.mutex.RUnlock()
repo.clients[client.ID.String()] = client
return nil
}
func (repo memoryClientRepository) Get(ctx context.Context, cid domain.ClientID) (*domain.Client, error) {
repo.mutex.RLock()
defer repo.mutex.RUnlock()
if c, ok := repo.clients[cid.String()]; ok {
return &c, nil
}
return nil, client.ErrNotExist
}

View File

@ -19,7 +19,7 @@ func NewClientUseCase(repo client.Repository) client.UseCase {
}
func (useCase *clientUseCase) Discovery(ctx context.Context, id domain.ClientID) (*domain.Client, error) {
c, err := useCase.repo.Get(ctx, id)
c, err := useCase.repo.Fetch(ctx, id)
if err != nil {
return nil, fmt.Errorf("cannot discovery client by id: %w", err)
}