+ contact requests
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/fx_ingestor Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
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
ci/woodpecker/push/bump_version Pipeline failed
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/fx_ingestor Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
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
ci/woodpecker/push/bump_version Pipeline failed
This commit is contained in:
@@ -44,3 +44,38 @@ func NewDemoRequestEnvelope(sender string, request *model.DemoRequest) messaging
|
||||
request: request,
|
||||
}
|
||||
}
|
||||
|
||||
type ContactRequestNotification struct {
|
||||
messaging.Envelope
|
||||
request *model.ContactRequest
|
||||
}
|
||||
|
||||
func (crn *ContactRequestNotification) Serialize() ([]byte, error) {
|
||||
if crn.request == nil {
|
||||
return nil, merrors.InvalidArgument("contact request payload is empty", "request")
|
||||
}
|
||||
msg := gmessaging.ContactRequestEvent{
|
||||
Name: crn.request.Name,
|
||||
Email: crn.request.Email,
|
||||
Phone: crn.request.Phone,
|
||||
Company: crn.request.Company,
|
||||
Topic: crn.request.Topic,
|
||||
Message: crn.request.Message,
|
||||
}
|
||||
data, err := proto.Marshal(&msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return crn.Envelope.Wrap(data)
|
||||
}
|
||||
|
||||
func NewContactRequestEvent() model.NotificationEvent {
|
||||
return model.NewNotification(mservice.Site, nm.NACreated)
|
||||
}
|
||||
|
||||
func NewContactRequestEnvelope(sender string, request *model.ContactRequest) messaging.Envelope {
|
||||
return &ContactRequestNotification{
|
||||
Envelope: messaging.CreateEnvelope(sender, NewContactRequestEvent()),
|
||||
request: request,
|
||||
}
|
||||
}
|
||||
|
||||
11
api/pkg/messaging/notifications/site/contact_request.go
Normal file
11
api/pkg/messaging/notifications/site/contact_request.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
messaging "github.com/tech/sendico/pkg/messaging/envelope"
|
||||
internalsite "github.com/tech/sendico/pkg/messaging/internal/notifications/site"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
)
|
||||
|
||||
func ContactRequest(sender string, request *model.ContactRequest) messaging.Envelope {
|
||||
return internalsite.NewContactRequestEnvelope(sender, request)
|
||||
}
|
||||
@@ -7,3 +7,4 @@ import (
|
||||
)
|
||||
|
||||
type DemoRequestHandler = func(context.Context, *model.DemoRequest) error
|
||||
type ContactRequestHandler = func(context.Context, *model.ContactRequest) error
|
||||
|
||||
@@ -48,3 +48,38 @@ func NewDemoRequestProcessor(logger mlogger.Logger, handler handler.DemoRequestH
|
||||
event: internalsite.NewDemoRequestEvent(),
|
||||
}
|
||||
}
|
||||
|
||||
type ContactRequestProcessor struct {
|
||||
logger mlogger.Logger
|
||||
handler handler.ContactRequestHandler
|
||||
event model.NotificationEvent
|
||||
}
|
||||
|
||||
func (crp *ContactRequestProcessor) Process(ctx context.Context, envelope me.Envelope) error {
|
||||
var msg gmessaging.ContactRequestEvent
|
||||
if err := proto.Unmarshal(envelope.GetData(), &msg); err != nil {
|
||||
crp.logger.Warn("Failed to decode contact request envelope", zap.Error(err), zap.String("topic", crp.event.ToString()))
|
||||
return err
|
||||
}
|
||||
request := &model.ContactRequest{
|
||||
Name: msg.GetName(),
|
||||
Email: msg.GetEmail(),
|
||||
Phone: msg.GetPhone(),
|
||||
Company: msg.GetCompany(),
|
||||
Topic: msg.GetTopic(),
|
||||
Message: msg.GetMessage(),
|
||||
}
|
||||
return crp.handler(ctx, request)
|
||||
}
|
||||
|
||||
func (crp *ContactRequestProcessor) GetSubject() model.NotificationEvent {
|
||||
return crp.event
|
||||
}
|
||||
|
||||
func NewContactRequestProcessor(logger mlogger.Logger, handler handler.ContactRequestHandler) np.EnvelopeProcessor {
|
||||
return &ContactRequestProcessor{
|
||||
logger: logger.Named("contact_request_processor"),
|
||||
handler: handler,
|
||||
event: internalsite.NewContactRequestEvent(),
|
||||
}
|
||||
}
|
||||
|
||||
41
api/pkg/model/contactrequest.go
Normal file
41
api/pkg/model/contactrequest.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
)
|
||||
|
||||
// ContactRequest represents a contact form submission from the marketing site.
|
||||
type ContactRequest struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Phone string `json:"phone"`
|
||||
Company string `json:"company"`
|
||||
Topic string `json:"topic"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// Normalize trims whitespace from all string fields.
|
||||
func (cr *ContactRequest) Normalize() {
|
||||
if cr == nil {
|
||||
return
|
||||
}
|
||||
cr.Name = strings.TrimSpace(cr.Name)
|
||||
cr.Email = strings.TrimSpace(cr.Email)
|
||||
cr.Phone = strings.TrimSpace(cr.Phone)
|
||||
cr.Company = strings.TrimSpace(cr.Company)
|
||||
cr.Topic = strings.TrimSpace(cr.Topic)
|
||||
cr.Message = strings.TrimSpace(cr.Message)
|
||||
}
|
||||
|
||||
// Validate ensures required contact request fields are present.
|
||||
func (cr *ContactRequest) Validate() error {
|
||||
if cr == nil {
|
||||
return merrors.InvalidArgument("request payload is empty", "request")
|
||||
}
|
||||
if (cr.Email == "") || (cr.Phone == "") {
|
||||
return merrors.InvalidArgument("email or phone must not be empty", "request.email", "request.phone")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
31
api/pkg/model/contactrequest_test.go
Normal file
31
api/pkg/model/contactrequest_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package model
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestContactRequestNormalizeAndValidate(t *testing.T) {
|
||||
req := &ContactRequest{
|
||||
Name: " Alice ",
|
||||
Email: " alice@example.com ",
|
||||
Phone: " +1 234 ",
|
||||
Company: " Sendico ",
|
||||
Topic: " General question ",
|
||||
Message: " Hello team ",
|
||||
}
|
||||
|
||||
req.Normalize()
|
||||
if err := req.Validate(); err != nil {
|
||||
t.Fatalf("expected request to be valid, got error: %v", err)
|
||||
}
|
||||
|
||||
if req.Name != "Alice" || req.Email != "alice@example.com" || req.Phone != "+1 234" || req.Company != "Sendico" || req.Topic != "General question" || req.Message != "Hello team" {
|
||||
t.Fatalf("normalize failed: %+v", req)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContactRequestValidateMissing(t *testing.T) {
|
||||
req := &ContactRequest{}
|
||||
req.Normalize()
|
||||
if err := req.Validate(); err == nil {
|
||||
t.Fatalf("expected validation error for empty request")
|
||||
}
|
||||
}
|
||||
@@ -34,20 +34,8 @@ func (dr *DemoRequest) Validate() error {
|
||||
if dr == nil {
|
||||
return merrors.InvalidArgument("request payload is empty", "request")
|
||||
}
|
||||
if dr.Name == "" {
|
||||
return merrors.InvalidArgument("name must not be empty", "request.name")
|
||||
}
|
||||
if dr.OrganizationName == "" {
|
||||
return merrors.InvalidArgument("organization name must not be empty", "request.organizationName")
|
||||
}
|
||||
if dr.Phone == "" {
|
||||
return merrors.InvalidArgument("phone must not be empty", "request.phone")
|
||||
}
|
||||
if dr.WorkEmail == "" {
|
||||
return merrors.InvalidArgument("work email must not be empty", "request.workEmail")
|
||||
}
|
||||
if dr.PayoutVolume == "" {
|
||||
return merrors.InvalidArgument("payout volume must not be empty", "request.payoutVolume")
|
||||
if (dr.WorkEmail == "") || (dr.Phone == "") {
|
||||
return merrors.InvalidArgument("work email or phone must not be empty", "request.workEmail", "request.phone")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user