Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Error on filter query #99

Open
usamasaif opened this issue Jul 3, 2024 · 1 comment
Open

Getting Error on filter query #99

usamasaif opened this issue Jul 3, 2024 · 1 comment

Comments

@usamasaif
Copy link

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"
}

Copy link

github-actions bot commented Jul 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant