mirror of
https://github.com/KevinMidboe/planetposen-mail.git
synced 2025-10-28 17:20:32 +00:00
Non-empty validation of required post body fields
This commit is contained in:
@@ -22,7 +22,6 @@ func SendOrderConfirmation(s *sendgrid.Client) http.HandlerFunc {
|
||||
|
||||
err = s.SendOrderConfirmation(ctx, *mailData)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
handleError(w, err, "error from sendgrid ", http.StatusInternalServerError, true)
|
||||
return
|
||||
}
|
||||
@@ -51,5 +50,17 @@ func getOrderConfirmationPayload(r *http.Request) (*mail.OrderConfirmationData,
|
||||
return nil, fmt.Errorf("decode: %w", err)
|
||||
}
|
||||
|
||||
if payload.Email == "" {
|
||||
return nil, fmt.Errorf("missing required email field")
|
||||
}
|
||||
|
||||
if payload.OrderId == "" {
|
||||
return nil, fmt.Errorf("missing required orderid field")
|
||||
}
|
||||
|
||||
if len(payload.Products) == 0 {
|
||||
return nil, fmt.Errorf("missing required products array")
|
||||
}
|
||||
|
||||
return &payload, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user