-
Notifications
You must be signed in to change notification settings - Fork 44
/
property_schema.go
82 lines (68 loc) · 1.96 KB
/
property_schema.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package fs
import (
"context"
"errors"
"github.com/reearth/reearth/server/internal/usecase/repo"
"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearth/server/pkg/property"
"github.com/reearth/reearthx/rerror"
"github.com/spf13/afero"
)
type propertySchema struct {
fs afero.Fs
f repo.SceneFilter
}
func NewPropertySchema(fs afero.Fs) repo.PropertySchema {
return &propertySchema{
fs: fs,
}
}
func (r *propertySchema) Filtered(f repo.SceneFilter) repo.PropertySchema {
return &propertySchema{
fs: r.fs,
f: r.f.Merge(f),
}
}
func (r *propertySchema) FindByID(ctx context.Context, i id.PropertySchemaID) (*property.Schema, error) {
m, err := readPluginManifest(ctx, r.fs, i.Plugin())
if err != nil {
return nil, err
}
if m.Schema != nil && m.Schema.ID() == i {
return m.Schema, nil
}
for _, ps := range m.ExtensionSchema {
if ps == nil {
continue
}
if ps.ID().Equal(i) {
if s := ps.Scene(); s == nil || r.f.CanRead(*s) {
return ps, nil
}
}
}
return nil, rerror.ErrNotFound
}
func (r *propertySchema) FindByIDs(ctx context.Context, ids []id.PropertySchemaID) (property.SchemaList, error) {
results := make(property.SchemaList, 0, len(ids))
for _, id := range ids {
res, err := r.FindByID(ctx, id)
if err != nil {
return nil, err
}
results = append(results, res)
}
return results, nil
}
func (r *propertySchema) Save(ctx context.Context, p *property.Schema) error {
return rerror.ErrInternalByWithContext(ctx, errors.New("read only"))
}
func (r *propertySchema) SaveAll(ctx context.Context, p property.SchemaList) error {
return rerror.ErrInternalByWithContext(ctx, errors.New("read only"))
}
func (r *propertySchema) Remove(ctx context.Context, pid id.PropertySchemaID) error {
return rerror.ErrInternalByWithContext(ctx, errors.New("read only"))
}
func (r *propertySchema) RemoveAll(ctx context.Context, pid []id.PropertySchemaID) error {
return rerror.ErrInternalByWithContext(ctx, errors.New("read only"))
}