mehdihadeli / go-food-delivery-microservices

🍕 A practical and imaginary food delivery microservices, built with golang, domain-driven design, cqrs, event sourcing, vertical slice architecture, event-driven architecture, and the latest technologies.
MIT License
888 stars 92 forks source link

Getting Error on filter query #99

Open usamasaif opened 4 months ago

usamasaif commented 4 months ago

func (ep *getProductsEndpoint) handler() echo.HandlerFunc { return func(c echo.Context) error { ctx := c.Request().Context() ep.CatalogsMetrics.GetProductsHttpRequests.Add(ctx, 1)

    fmt.Println("Raw query parameters:", c.QueryParams())

    listQuery, err := utils.GetListQueryFromCtx(c)
    if err != nil {
        badRequestErr := customErrors.NewBadRequestErrorWrap(
            err,
            "[getProductsEndpoint_handler.GetListQueryFromCtx] error in getting data from query string",
        )
        ep.Logger.Errorf(
            fmt.Sprintf(
                "[getProductsEndpoint_handler.GetListQueryFromCtx] err: %v",
                badRequestErr,
            ),
        )
        return err
    }

    request := &dtos.GetProductsRequestDto{ListQuery: listQuery}
    if err := c.Bind(request); err != nil {
        badRequestErr := customErrors.NewBadRequestErrorWrap(
            err,
            "[getProductsEndpoint_handler.Bind] error in the binding request",
        )
        ep.Logger.Errorf(
            fmt.Sprintf("[getProductsEndpoint_handler.Bind] err: %v", badRequestErr),
        )
        return badRequestErr
    }

    query, err := queries.NewGetProducts(request.ListQuery)
    if err != nil {
        return err
    }

    queryResult, err := mediatr.Send[*queries.GetProducts, *dtos.GetProductsResponseDto](
        ctx,
        query,
    )
    if err != nil {
        err = errors.WithMessage(
            err,
            "[getProductsEndpoint_handler.Send] error in sending GetProducts",
        )
        ep.Logger.Error(fmt.Sprintf("[getProductsEndpoint_handler.Send] err: {%v}", err))
        return err
    }

    return c.JSON(http.StatusOK, queryResult)
}

}

http://localhost:7000/api/v1/products?size=10&page=1&filters={field:price,value:100,comparison:eq} i m getting this error { "status": 400, "title": "Bad Request", "detail": "[getProductsEndpoint_handler.Bind] error in the binding request: code=400, message=unknown type, internal=unknown type", "type": "https://httpstatuses.io/400", "timestamp": "2024-07-03T18:36:30.959922+05:00", "stackTrace": "code=400, message=unknown type, internal=unknown type\n[getProductsEndpoint_handler.Bind] error in the binding request\ngithub.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/http_errors/custom_errors.NewBadRequestErrorWrap\n\t/Users/usamasaif/Desktop/go-food-delivery-microservices/internal/pkg/http/http_errors/custom_errors/bad_request_error.go:22\ngithub.com/mehdihadeli/go-ecommerce-microservices/internal/services/catalogwriteservice/internal/products/features/getting_products/v1/endpoints.(getProductsEndpoint).MapEndpoint.(getProductsEndpoint).handler.func1\n\t/Users/usamasaif/Desktop/go-food-delivery-microservices/internal/services/catalog_write_service/internal/products/features/getting_products/v1/endpoints/get_products_endpoint.go:66\ngithub.com/labstack/echo/v4.(Echo).add.func1\n\t/Users/usamasaif/Documents/go/pkg/mod/github.com/labstack/echo/v4@v4.11.1/echo.go:582\ngithub.com/labstack/echo/v4/middleware.GzipWithConfig.func1.1\n\t/Users/usamasaif/Documents/go/pkg/mod/github.com/labstack/echo/v4@v4.11.1/middleware/compress.go:140\ngithub.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/custom_echo.(echoHttpServer).SetupDefaultMiddlewares.RequestID.RequestIDWithConfig.func5.1\n\t/Users/usamasaif/Documents/go/pkg/mod/github.com/labstack/echo/v4@v4.11.1/middleware/request_id.go:70\ngithub.com/labstack/echo/v4/middleware.BodyLimitWithConfig.func1.1\n\t/Users/usamasaif/Documents/go/pkg/mod/github.com/labstack/echo/v4@v4.11.1/middleware/body_limit.go:87\ngithub.com/labstack/echo/v4/middleware.RequestLoggerConfig.ToMiddleware.func1.1\n\t/Users/usamasaif/Documents/go/pkg/mod/github.com/labstack/echo/v4@v4.11.1/middleware/request_logger.go:259\ngithub.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/custom_echo/middlewares/otel_metrics.Middleware.func1.1\n\t/Users/usamasaif/Desktop/go-food-delivery-microservices/internal/pkg/http/custom_echo/middlewares/otel_metrics/request_status_middleware.go:32\ngo.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho.Middleware.func1.1\n\t/Users/usamasaif/Documents/go/pkg/mod/go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho@v0.43.0/echo.go:92\ngithub.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/custom_echo.(echoHttpServer).SetupDefaultMiddlewares.EchoLogger.func4.1\n\t/Users/usamasaif/Desktop/go-food-delivery-microservices/internal/pkg/http/custom_echo/middlewares/log/log_middleware.go:17\ngithub.com/labstack/echo/v4.(Echo).ServeHTTP\n\t/Users/usamasaif/Documents/go/pkg/mod/github.com/labstack/echo/v4@v4.11.1/echo.go:669\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:3137\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:2039\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1695\n" }

github-actions[bot] commented 4 months ago

Welcome to go-ecommerce-microservices. Thank you for reporting your first issue. Please check out our contributor guide.