This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
plugin.go
62 lines (53 loc) · 1.64 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package interactor
import (
"context"
"github.com/reearth/reearth-backend/internal/usecase"
"github.com/reearth/reearth-backend/internal/usecase/gateway"
"github.com/reearth/reearth-backend/internal/usecase/interfaces"
"github.com/reearth/reearth-backend/internal/usecase/repo"
"github.com/reearth/reearth-backend/pkg/id"
"github.com/reearth/reearth-backend/pkg/plugin"
)
type Plugin struct {
common
commonScene
pluginRepo repo.Plugin
propertySchemaRepo repo.PropertySchema
propertyRepo repo.Property
file gateway.File
pluginRepository gateway.PluginRepository
transaction repo.Transaction
pluginRegistry gateway.PluginRegistry
}
func NewPlugin(r *repo.Container, gr *gateway.Container) interfaces.Plugin {
return &Plugin{
commonScene: commonScene{
sceneRepo: r.Scene,
},
pluginRepo: r.Plugin,
propertySchemaRepo: r.PropertySchema,
propertyRepo: r.Property,
transaction: r.Transaction,
pluginRepository: gr.PluginRepository,
file: gr.File,
pluginRegistry: gr.PluginRegistry,
}
}
func (i *Plugin) Fetch(ctx context.Context, ids []id.PluginID, operator *usecase.Operator) ([]*plugin.Plugin, error) {
scenes, err := i.OnlyReadableScenes(ctx, operator)
if err != nil {
return nil, err
}
res, err := i.pluginRepo.FindByIDs(ctx, ids, scenes)
return res, err
}
func (i *Plugin) FetchPluginMetadata(ctx context.Context, operator *usecase.Operator) ([]*plugin.Metadata, error) {
if err := i.OnlyOperator(operator); err != nil {
return nil, err
}
res, err := i.pluginRegistry.FetchMetadata(ctx)
if err != nil {
return nil, err
}
return res, nil
}