2020-09-16 17:22:02 +03:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/MichaelMure/git-bug/entity"
|
|
|
|
)
|
|
|
|
|
2022-08-13 13:08:48 +03:00
|
|
|
func makeResolvers(cache *RepoCache) entity.Resolvers {
|
|
|
|
return entity.Resolvers{
|
|
|
|
&IdentityCache{}: newIdentityCacheResolver(cache),
|
|
|
|
&BugCache{}: newBugCacheResolver(cache),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ entity.Resolver = &identityCacheResolver{}
|
2020-09-16 17:22:02 +03:00
|
|
|
|
|
|
|
// identityCacheResolver is an identity Resolver that retrieve identities from
|
|
|
|
// the cache
|
|
|
|
type identityCacheResolver struct {
|
|
|
|
cache *RepoCache
|
|
|
|
}
|
|
|
|
|
|
|
|
func newIdentityCacheResolver(cache *RepoCache) *identityCacheResolver {
|
|
|
|
return &identityCacheResolver{cache: cache}
|
|
|
|
}
|
|
|
|
|
2022-08-13 13:08:48 +03:00
|
|
|
func (i *identityCacheResolver) Resolve(id entity.Id) (entity.Interface, error) {
|
2020-09-16 17:22:02 +03:00
|
|
|
return i.cache.ResolveIdentity(id)
|
|
|
|
}
|
2021-04-04 14:28:21 +03:00
|
|
|
|
2022-08-13 13:08:48 +03:00
|
|
|
var _ entity.Resolver = &bugCacheResolver{}
|
2021-04-04 14:28:21 +03:00
|
|
|
|
2022-08-13 13:08:48 +03:00
|
|
|
type bugCacheResolver struct {
|
2021-04-04 14:28:21 +03:00
|
|
|
cache *RepoCache
|
|
|
|
}
|
|
|
|
|
2022-08-13 13:08:48 +03:00
|
|
|
func newBugCacheResolver(cache *RepoCache) *bugCacheResolver {
|
|
|
|
return &bugCacheResolver{cache: cache}
|
2021-04-04 14:28:21 +03:00
|
|
|
}
|
|
|
|
|
2022-08-13 13:08:48 +03:00
|
|
|
func (b *bugCacheResolver) Resolve(id entity.Id) (entity.Interface, error) {
|
|
|
|
return b.cache.ResolveBug(id)
|
2021-04-04 14:28:21 +03:00
|
|
|
}
|