auth/internal/profile/repository.go

46 lines
937 B
Go
Raw Permalink Normal View History

package profile
import (
"context"
"source.toby3d.me/toby3d/auth/internal/domain"
)
type (
Repository interface {
Fetch(ctx context.Context, me domain.Me) (*domain.Profile, error)
}
dummyProfileRepository struct{}
stubProfileRepository struct {
profile *domain.Profile
error error
}
)
var ErrNotExist error = domain.NewError(
domain.ErrorCodeServerError,
"no profile data for the provided Me",
"https://indieweb.org/h-card",
)
func NewDummyProfileRepository() Repository {
return dummyProfileRepository{}
}
func (dummyProfileRepository) Fetch(_ context.Context, _ domain.Me) (*domain.Profile, error) {
return nil, nil
}
func NewStubProfileRepository(profile *domain.Profile, err error) Repository {
return &stubProfileRepository{
profile: profile,
error: err,
}
}
func (repo *stubProfileRepository) Fetch(_ context.Context, _ domain.Me) (*domain.Profile, error) {
return repo.profile, repo.error
}