Skip to content

Commit

Permalink
better request.Context
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcGrol committed Feb 23, 2018
1 parent 4efdf76 commit 6867a2b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion generator/event/wrappers_test.tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Test{{.Name}}Wrapper(t *testing.T) {
{{end -}}
{{end -}}
}
wrapped, err := event.Wrap(request.NewBuilder().SessionUID("test_session").Build())
wrapped, err := event.Wrap(request.New(request.SessionUID("test_session")))
assert.NoError(t, err)
assert.True(t, Is{{.Name}}(wrapped))
assert.Equal(t, {{GetAggregateName . }}AggregateName, wrapped.AggregateName)
Expand Down
11 changes: 5 additions & 6 deletions generator/eventService/handlers.tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,19 @@ func (es *{{$eventServiceName}}) httpHandleEventAsync() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
c := ctx.New.CreateContext(r)
rcb := request.NewMinimalContextBuilder(c,r)
rc := request.NewMinimalContext(c,r)
// read and parse request body
var envlp envelope.Envelope
err := json.NewDecoder(r.Body).Decode(&envlp)
if err != nil {
errorh.HandleHttpError(c, rcb.Build(), errorh.NewInvalidInputErrorf(1, "Error parsing request body: %s", err), w, r)
errorh.HandleHttpError(c, rc, errorh.NewInvalidInputErrorf(1, "Error parsing request body: %s", err), w, r)
return
}
rc := rcb.RequestUID( envlp.UUID ).
SessionUID( envlp.SessionUID ).
RequestUID(envlp.UUID). // pas a stable identifyer that make write of resulting events idempotent
Build()
rc.Set(request.RequestUID( envlp.UUID ),
request.SessionUID( envlp.SessionUID ),
request.RequestUID(envlp.UUID)) // pas a stable identifyer that make write of resulting events idempotent
err = es.handleEventAsync(c, rc, envlp.AggregateName, envlp)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions generator/rest/httpHandlers.tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ func {{$oper.Name}}( service *{{$service.Name}} ) http.HandlerFunc {
preLogicHook( nil, w, r )
{{end -}}
rc := {{ $extractRequestContextMethod }}Builder(c, r).
Transactional({{ IsRestOperationTransactional $service .}}).
Build()
rc := {{ $extractRequestContextMethod }}(c, r)
{{if (not $noValidation) and (HasRequestContext $oper) -}}
err = validateRequestContext(c, rc, {{GetRestOperationRolesString $oper}})
Expand Down Expand Up @@ -159,8 +157,9 @@ func {{$oper.Name}}( service *{{$service.Name}} ) http.HandlerFunc {
}
{{end}}
// call business logic: transactional: {{ IsRestOperationTransactional $service .}}
{{range GetOutputArgsDeclaration . -}}
// call business logic
rc.Set(request.Transactional({{ IsRestOperationTransactional $service .}}))
{{range GetOutputArgsDeclaration . -}}
{{.}}
{{end -}}
{{if IsRestOperationTransactional $service . -}}
Expand Down

0 comments on commit 6867a2b

Please sign in to comment.