Skip to content
Snippets Groups Projects
Commit d017315e authored by Pavel Antonov's avatar Pavel Antonov :asterisk:
Browse files

feat: Добавлены методы Space, Environment, Collection, Organization для...

feat: Добавлены методы Space, Environment, Collection, Organization для объекта System, который используется в шаблонах

Close #PRXS-1813
parents cbbc85a3 918ee149
No related branches found
No related tags found
No related merge requests found
...@@ -5,25 +5,38 @@ import ( ...@@ -5,25 +5,38 @@ import (
"context" "context"
"text/template" "text/template"
"git.perx.ru/perxis/perxis-go/pkg/account"
"git.perx.ru/perxis/perxis-go/pkg/collections"
"git.perx.ru/perxis/perxis-go/pkg/content" "git.perx.ru/perxis/perxis-go/pkg/content"
"git.perx.ru/perxis/perxis-go/pkg/environments"
"git.perx.ru/perxis/perxis-go/pkg/organizations"
"git.perx.ru/perxis/perxis-go/pkg/spaces"
) )
type Builder struct { type Builder struct {
ctx context.Context ctx context.Context
acc *account.Account
cnt *content.Content cnt *content.Content
SpaceID string SpaceID string
EnvID string EnvID string
funcs template.FuncMap CollID string
data map[string]interface{} data map[string]interface{}
// Для кеширования запросов
space *spaces.Space
environment *environments.Environment
collection *collections.Collection
organization *organizations.Organization
} }
func NewBuilder(cnt *content.Content, space, env string) *Builder { func NewBuilder(acc *account.Account, cnt *content.Content, space, env, col string) *Builder {
return &Builder{ return &Builder{
ctx: context.Background(), ctx: context.Background(),
acc: acc,
cnt: cnt, cnt: cnt,
SpaceID: space, SpaceID: space,
EnvID: env, EnvID: env,
funcs: make(template.FuncMap), CollID: col,
} }
} }
......
This diff is collapsed.
package template package template
import (
"git.perx.ru/perxis/perxis-go/pkg/collections"
"git.perx.ru/perxis/perxis-go/pkg/environments"
"git.perx.ru/perxis/perxis-go/pkg/organizations"
"git.perx.ru/perxis/perxis-go/pkg/spaces"
)
type System struct { type System struct {
builder *Builder builder *Builder
} }
...@@ -11,3 +18,60 @@ func (s *System) SpaceID() string { ...@@ -11,3 +18,60 @@ func (s *System) SpaceID() string {
func (s *System) EnvID() string { func (s *System) EnvID() string {
return s.builder.EnvID return s.builder.EnvID
} }
func (s *System) CollectionID() string {
return s.builder.CollID
}
func (s *System) OrganizationID() (string, error) {
org, err := s.Organization()
if err != nil {
return "", err
}
return org.ID, nil
}
func (s *System) Space() (*spaces.Space, error) {
if s.builder.space != nil {
return s.builder.space, nil
}
space, err := s.builder.cnt.Spaces.Get(s.builder.ctx, s.builder.SpaceID)
s.builder.space = space
return s.builder.space, err
}
func (s *System) Environment() (*environments.Environment, error) {
if s.builder.environment != nil {
return s.builder.environment, nil
}
env, err := s.builder.cnt.Environments.Get(s.builder.ctx, s.builder.SpaceID, s.builder.EnvID)
s.builder.environment = env
return s.builder.environment, err
}
func (s *System) Collection() (*collections.Collection, error) {
if s.builder.collection != nil {
return s.builder.collection, nil
}
coll, err := s.builder.cnt.Collections.Get(s.builder.ctx, s.builder.SpaceID, s.builder.EnvID, s.builder.CollID)
s.builder.collection = coll
return s.builder.collection, err
}
func (s *System) Organization() (*organizations.Organization, error) {
if s.builder.organization != nil {
return s.builder.organization, nil
}
sp, err := s.Space()
if err != nil {
return nil, err
}
org, err := s.builder.acc.Organizations.Get(s.builder.ctx, sp.OrgID)
s.builder.organization = org
return s.builder.organization, err
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment