diff --git a/pkg/domain/schema.go b/pkg/domain/schema.go index 862c7f4..b522dc8 100644 --- a/pkg/domain/schema.go +++ b/pkg/domain/schema.go @@ -9,9 +9,9 @@ import ( //go:generate easyjson -all type Schema struct { ID string `json:"id,omitempty" yaml:"id,omitempty" xml:"id,attr,omitempty"` - Language string `json:"lang" yaml:"lang" xml:"lang,attr"` - Title string `json:"title" yaml:"title" xml:"title,attr"` - Action string `json:"action" yaml:"action" xml:"action,attr"` + Language string `json:"lang,omitempty" yaml:"lang,omitempty" xml:"lang,attr,omitempty"` + Title string `json:"title,omitempty" yaml:"title,omitempty" xml:"title,attr,omitempty"` + Action string `json:"action,omitempty" yaml:"action,omitempty" xml:"action,attr,omitempty"` Method string `json:"method,omitempty" yaml:"method,omitempty" xml:"method,attr,omitempty"` EncodingType string `json:"enctype,omitempty" yaml:"enctype,omitempty" xml:"enctype,attr,omitempty"` Inputs []Input `json:"input" yaml:"input" xml:"input"` diff --git a/pkg/service/service.go b/pkg/service/service.go index 5819005..b7d5636 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -57,10 +57,7 @@ func (service *Forma) HandleGetV1(ctx context.Context, req v1.GetRequest) (resp if resp.Error != nil { return } - - // add form namespace to make its elements unique enrich(service.baseURL, &resp.Schema) - return } @@ -72,7 +69,6 @@ func (service *Forma) HandleInput(ctx context.Context, req v1.PostRequest) (resp return } - // add form namespace to make its elements unique enrich(service.baseURL, &schema) resp.URL = req.InputData.Redirect(req.Context.Referer(), schema.Action) @@ -129,11 +125,8 @@ func (service *Forma) HandleInput(ctx context.Context, req v1.PostRequest) (resp return resp } +// configure form action func enrich(base *url.URL, schema *domain.Schema) { - for i := range schema.Inputs { - schema.Inputs[i].ID = schema.ID + "_" + schema.Inputs[i].Name - } - // replace fallback by current API call schema.Action = extend(*base, "api/v1", schema.ID) schema.Method = http.MethodPost schema.EncodingType = "application/x-www-form-urlencoded" diff --git a/pkg/storage/protected.go b/pkg/storage/protected.go index ff35f44..e0dc1e2 100644 --- a/pkg/storage/protected.go +++ b/pkg/storage/protected.go @@ -45,7 +45,23 @@ func (storage *Storage) ReadSchema(ctx context.Context, tokenID domain.ID, data if authErr != nil { return entity, authErr } - return storage.exec.SchemaEditor(ctx, conn).Read(token, data) + + entity, readErr := storage.exec.SchemaEditor(ctx, conn).Read(token, data) + if readErr != nil { + return entity, readErr + } + + // TODO issue#logic duplicated + { + ptr := &entity.Definition + ptr.ID = entity.ID.String() + ptr.Title = entity.Title + for i, input := range ptr.Inputs { + ptr.Inputs[i].ID = ptr.ID + "_" + input.Name + } + } + + return entity, nil } // UpdateSchema TODO issue#173 diff --git a/pkg/storage/public.go b/pkg/storage/public.go index 46cce7d..b479718 100644 --- a/pkg/storage/public.go +++ b/pkg/storage/public.go @@ -22,8 +22,16 @@ func (storage *Storage) Schema(ctx context.Context, id domain.ID) (domain.Schema if readErr != nil { return schema, readErr } - entity.Definition.ID = entity.ID.String() - entity.Definition.Title = entity.Title + + // TODO issue#logic duplicated + { + ptr := &entity.Definition + ptr.ID = entity.ID.String() + ptr.Title = entity.Title + for i, input := range ptr.Inputs { + ptr.Inputs[i].ID = ptr.ID + "_" + input.Name + } + } return entity.Definition, nil }