2022-01-29 19:36:05 +00:00
|
|
|
package profile
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-03-13 10:58:34 +00:00
|
|
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
2022-01-29 19:36:05 +00:00
|
|
|
)
|
|
|
|
|
2024-05-15 09:09:16 +00:00
|
|
|
type (
|
|
|
|
Repository interface {
|
|
|
|
Fetch(ctx context.Context, me domain.Me) (*domain.Profile, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
dummyProfileRepository struct{}
|
|
|
|
|
|
|
|
stubProfileRepository struct {
|
|
|
|
profile *domain.Profile
|
|
|
|
error error
|
|
|
|
}
|
|
|
|
)
|
2022-01-29 19:36:05 +00:00
|
|
|
|
2022-02-17 14:59:59 +00:00
|
|
|
var ErrNotExist error = domain.NewError(
|
|
|
|
domain.ErrorCodeServerError,
|
|
|
|
"no profile data for the provided Me",
|
|
|
|
"https://indieweb.org/h-card",
|
|
|
|
)
|
2024-05-15 09:09:16 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|