From de8dad8fa86d4d91e859ee0b8350ddd4ba88c3fe Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sun, 10 Mar 2024 15:40:25 +0100 Subject: [PATCH] validate missing communication method --- internal/server/handle_public.go | 9 +++++-- internal/view/index.templ | 22 ++++++++++++++-- internal/view/index_templ.go | 43 ++++++++++++++++++++++++++++++-- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/internal/server/handle_public.go b/internal/server/handle_public.go index 8f0df5d..743d94f 100644 --- a/internal/server/handle_public.go +++ b/internal/server/handle_public.go @@ -34,8 +34,13 @@ func handleRequestBooking() echo.HandlerFunc { if to.Sub(from) < time.Duration(0) { errs = append(errs, errors.New("invalid_time_range")) } - // a communication mean - // + + phoneNumber := c.FormValue("phone") + email := c.FormValue("email") + if phoneNumber == "" && email == "" { + errs = append(errs, errors.New("missing_communication_method")) + } + return renderTempl(c, http.StatusOK, view.RequestBookingForm(errs)) } } diff --git a/internal/view/index.templ b/internal/view/index.templ index e8e5338..344cb18 100644 --- a/internal/view/index.templ +++ b/internal/view/index.templ @@ -24,6 +24,15 @@ func invalidTimeRange(errs []error) bool { return false } +func missingCommunicationMethod(errs []error) bool { + for _, e := range errs { + if e.Error() == "missing_communication_method" { + return true + } + } + return false +} + templ RequestBookingForm(errors []error) {
@@ -56,11 +65,20 @@ templ RequestBookingForm(errors []error) {
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }