From 5e8069fecb32f944914af76b63769e0ca7e7a53b Mon Sep 17 00:00:00 2001 From: Paul Yu Date: Tue, 12 Dec 2023 13:12:07 -0800 Subject: [PATCH] fix: validator bug --- src/makeline-service/main.go | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/src/makeline-service/main.go b/src/makeline-service/main.go index 418c7758..9e314dc2 100644 --- a/src/makeline-service/main.go +++ b/src/makeline-service/main.go @@ -8,11 +8,8 @@ import ( "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" - "github.com/go-playground/validator/v10" ) -var validate *validator.Validate - // Valid database API types const ( AZURE_COSMOS_DB_SQL_API = "cosmosdbsql" @@ -105,13 +102,6 @@ func getOrder(c *gin.Context) { return } - err := validate.Var(c.Param("id"), "required,numeric") - if err != nil { - log.Printf("Failed to validate order id: %s", err) - c.AbortWithStatus(http.StatusBadRequest) - return - } - id, err := strconv.Atoi(c.Param("id")) if err != nil { log.Printf("Failed to convert order id to int: %s", err) @@ -119,9 +109,9 @@ func getOrder(c *gin.Context) { return } - orderId := strconv.FormatInt(int64(id), 10) + sanitizedOrderId := strconv.FormatInt(int64(id), 10) - order, err := client.repo.GetOrder(orderId) + order, err := client.repo.GetOrder(sanitizedOrderId) if err != nil { log.Printf("Failed to get order from database: %s", err) c.AbortWithStatus(http.StatusInternalServerError) @@ -148,21 +138,7 @@ func updateOrder(c *gin.Context) { return } - err := validate.Struct(order) - validationErrors := err.(validator.ValidationErrors) - if err != nil { - log.Printf("Failed to validate order: %s", validationErrors) - c.AbortWithStatus(http.StatusBadRequest) - return - } - err = validate.Var(order.OrderID, "required,numeric") - if err != nil { - log.Printf("Failed to validate order id: %s", err) - c.AbortWithStatus(http.StatusBadRequest) - return - } - - id, err := strconv.Atoi(c.Param("id")) + id, err := strconv.Atoi(order.OrderID) if err != nil { log.Printf("Failed to convert order id to int: %s", err) c.AbortWithStatus(http.StatusBadRequest)