@@ -11,6 +11,8 @@ import (
1111 "strings"
1212 "time"
1313
14+ repository "github.com/kamilsk/form-api/pkg/storage/types"
15+
1416 "github.com/kamilsk/form-api/pkg/config"
1517 "github.com/kamilsk/form-api/pkg/domain"
1618 "github.com/kamilsk/form-api/pkg/errors"
@@ -87,14 +89,30 @@ func (service *Forma) HandleInput(ctx context.Context, req v1.PostRequest) (resp
8789 return
8890 }
8991
90- input , storeErr := service .storage .StoreInput (ctx , req .ID , verified )
92+ var input * repository.Input
93+ input , resp .Error = service .storage .StoreInput (ctx , req .ID , verified )
94+
95+ if resp .Error == nil && ! req .Context .Option ().NoLog && ! ignore (req .Context ) {
96+ // if option.Anonymously {}
97+ event := domain.InputEvent {
98+ SchemaID : req .ID ,
99+ InputID : input .ID ,
100+ TemplateID : req .InputData .Template (),
101+ Identifier : nil , // TODO issue#171
102+ Context : req .Context ,
103+ Code : http .StatusFound , // TODO issue#design
104+ URL : resp .URL ,
105+ }
106+ resp .Error = service .tracker .LogInput (ctx , event ) // TODO issue#109
107+ }
108+
91109 if u , err := url .Parse (resp .URL ); err == nil {
92110 type feedback struct {
93111 ID domain.ID `json:"input"`
94112 SchemaID domain.ID `json:"id"`
95113 Result string `json:"result"`
96114 }
97- if storeErr != nil {
115+ if resp . Error != nil {
98116 u .Fragment = base64 .StdEncoding .EncodeToString (func () []byte {
99117 raw , _ := json .Marshal (feedback {SchemaID : req .ID , Result : "failure" })
100118 return raw
@@ -108,20 +126,6 @@ func (service *Forma) HandleInput(ctx context.Context, req v1.PostRequest) (resp
108126 resp .URL = u .String ()
109127 }
110128
111- if storeErr == nil && ! req .Context .Option ().NoLog && ! ignore (req .Context ) {
112- // if option.Anonymously {}
113- event := domain.InputEvent {
114- SchemaID : req .ID ,
115- InputID : input .ID ,
116- TemplateID : req .InputData .Template (),
117- Identifier : nil , // TODO issue#171
118- Context : req .Context ,
119- Code : http .StatusFound , // TODO issue#design
120- URL : resp .URL ,
121- }
122- resp .Error = service .tracker .LogInput (ctx , event ) // TODO issue#109
123- }
124-
125129 return resp
126130}
127131
@@ -130,12 +134,12 @@ func enrich(base *url.URL, schema *domain.Schema) {
130134 schema .Inputs [i ].ID = schema .ID + "_" + schema .Inputs [i ].Name
131135 }
132136 // replace fallback by current API call
133- schema .Action = extend (base , "api/v1" , schema .ID )
137+ schema .Action = extend (* base , "api/v1" , schema .ID )
134138 schema .Method = http .MethodPost
135139 schema .EncodingType = "application/x-www-form-urlencoded"
136140}
137141
138- func extend (base * url.URL , paths ... string ) string {
142+ func extend (base url.URL , paths ... string ) string {
139143 if len (paths ) == 0 {
140144 return base .String ()
141145 }
0 commit comments