Send and receive SMS messages using your Android phone programmatically via a simple HTTP API
Fix the validator
Acho Arnoldaa65b25b9516
diff --git a/api/go.mod b/api/go.modindex 8e4634f8..dea278e0 100644--- a/api/go.mod+++ b/api/go.mod@@ -14,6 +14,7 @@ require (github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177github.com/rs/zerolog v1.26.1github.com/swaggo/swag v1.8.2+ github.com/thedevsaddam/govalidator v1.9.10go.opentelemetry.io/otel v1.7.0go.opentelemetry.io/otel/trace v1.7.0gorm.io/driver/postgres v1.3.7diff --git a/api/go.sum b/api/go.sumindex 06ba5dcc..60286b49 100644--- a/api/go.sum+++ b/api/go.sum@@ -207,6 +207,8 @@ github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2/go.mod h1:lKJPbtWzJ9Jgithub.com/swaggo/swag v1.8.1/go.mod h1:ugemnJsPZm/kRwFUnzBlbHRd0JY9zE1M4F+uy2pAaPQ=github.com/swaggo/swag v1.8.2 h1:D4aBiVS2a65zhyk3WFqOUz7Rz0sOaUcgeErcid5uGL4=github.com/swaggo/swag v1.8.2/go.mod h1:jMLeXOOmYyjk8PvHTsXBdrubsNd9gUJTTCzL5iBnseg=+github.com/thedevsaddam/govalidator v1.9.10 h1:m3dLRbSZ5Hts3VUWYe+vxLMG+FdyQuWOjzTeQRiMCvU=+github.com/thedevsaddam/govalidator v1.9.10/go.mod h1:Ilx8u7cg5g3LXbSS943cx5kczyNuUn7LH/cK5MYuE90=github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=diff --git a/api/pkg/events/message_api_sent_event.go b/api/pkg/events/message_api_sent_event.goindex 3ba2525e..7a2a16fb 100644--- a/api/pkg/events/message_api_sent_event.go+++ b/api/pkg/events/message_api_sent_event.go@@ -1,11 +1,14 @@package events+import "github.com/google/uuid"+// EventTypeMessageAPISent is emitted when a new message is sentconst EventTypeMessageAPISent = "message.api.sent"// MessageAPISent is the payload of the EventTypeMessageSent eventtype MessageAPISent struct {- From string `json:"from"`- To string `json:"to"`- Content string `json:"content"`+ ID uuid.UUID `json:"id"`+ From string `json:"from"`+ To string `json:"to"`+ Content string `json:"content"`}diff --git a/api/pkg/validators/message_handler_validator.go b/api/pkg/validators/message_handler_validator.goindex 0327e927..2c6dac1b 100644--- a/api/pkg/validators/message_handler_validator.go+++ b/api/pkg/validators/message_handler_validator.go@@ -7,6 +7,7 @@ import ("github.com/NdoleStudio/http-sms-manager/pkg/requests""github.com/NdoleStudio/http-sms-manager/pkg/telemetry"+ "github.com/thedevsaddam/govalidator")// MessageHandlerValidator validates models used in handlers.MessageHandler@@ -27,6 +28,33 @@ func NewMessageHandlerValidator(}// ValidateMessageSend validates the requests.MessageSend request-func (v MessageHandlerValidator) ValidateMessageSend(ctx context.Context, request requests.MessageSend) url.Values {- return nil+func (validator MessageHandlerValidator) ValidateMessageSend(ctx context.Context, request requests.MessageSend) url.Values {+ v := govalidator.New(govalidator.Options{+ Data: &request,+ Rules: govalidator.MapData{+ "to": []string{+ "required",+ "regex:^\\+[1-9]\\d{1,14}$",+ },+ "from": []string{+ "required",+ "regex:^\\+[1-9]\\d{1,14}$",+ },+ "content": []string{+ "required",+ "min:1",+ "max:500",+ },+ },+ Messages: map[string][]string{+ "to": {+ "regex: The 'to' field must be a valid E.164 phone number: https://en.wikipedia.org/wiki/E.164",+ },+ "from": {+ "regex: The 'from' field must be a valid E.164 phone number: https://en.wikipedia.org/wiki/E.164",+ },+ },+ })++ return v.Validate()}