+ call request
Some checks failed
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/bump_version Pipeline failed
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful

This commit is contained in:
Stephan D
2025-11-19 22:19:27 +01:00
parent 56d6c8caa6
commit 36d1a94cf6
15 changed files with 209 additions and 6 deletions

View File

@@ -0,0 +1,29 @@
package siteimp
import (
"encoding/json"
"net/http"
"github.com/tech/sendico/pkg/api/http/response"
snotifications "github.com/tech/sendico/pkg/messaging/notifications/site"
"github.com/tech/sendico/pkg/model"
"go.uber.org/zap"
)
func (a *SiteAPI) callRequest(r *http.Request) http.HandlerFunc {
var request model.CallRequest
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
a.logger.Warn("Failed to decode call request payload", zap.Error(err))
return response.BadRequest(a.logger, a.Name(), "invalid_payload", "Failed to decode call request payload")
}
request.Normalize()
if err := request.Validate(); err != nil {
a.logger.Warn("Call request validation failed", zap.Error(err))
return response.BadPayload(a.logger, a.Name(), err)
}
if err := a.producer.SendMessage(snotifications.CallRequest(a.Name(), &request)); err != nil {
a.logger.Warn("Failed to enqueue call request notification", zap.Error(err))
return response.Internal(a.logger, a.Name(), err)
}
return a.acceptedQueued()
}

View File

@@ -25,5 +25,5 @@ func (a *SiteAPI) contactRequest(r *http.Request) http.HandlerFunc {
a.logger.Warn("Failed to enqueue contact request notification", zap.Error(err))
return response.Internal(a.logger, a.Name(), err)
}
return response.Accepted(a.logger, map[string]string{"status": "queued"})
return a.acceptedQueued()
}

View File

@@ -27,5 +27,5 @@ func (a *SiteAPI) demoRequest(r *http.Request) http.HandlerFunc {
return response.Internal(a.logger, a.Name(), err)
}
return response.Accepted(a.logger, map[string]string{"status": "queued"})
return a.acceptedQueued()
}

View File

@@ -0,0 +1,19 @@
package siteimp
import (
"net/http"
"github.com/tech/sendico/pkg/api/http/response"
)
type enqueueResponse struct {
Status string `json:"status"`
}
func newEnqueueResponse() enqueueResponse {
return enqueueResponse{Status: "queued"}
}
func (a *SiteAPI) acceptedQueued() http.HandlerFunc {
return response.Accepted(a.logger, newEnqueueResponse())
}

View File

@@ -31,5 +31,6 @@ func CreateAPI(a eapi.API) (*SiteAPI, error) {
a.Register().Handler(mservice.Site, "/request/demo", api.Post, p.demoRequest)
a.Register().Handler(mservice.Site, "/request/contact", api.Post, p.contactRequest)
a.Register().Handler(mservice.Site, "/request/call", api.Post, p.callRequest)
return p, nil
}