Skip to content

Commit

Permalink
fix: 🐛some bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdihadeli committed Jul 22, 2024
1 parent 270702f commit 14fc2ea
Show file tree
Hide file tree
Showing 25 changed files with 81 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"resmon.show.cpufreq": false,
"omnisharp.projectLoadTimeout": 60,
"workbench.colorTheme": "Visual Studio Light",
"workbench.iconTheme": "vscode-icons",
"workbench.iconTheme": "material-icon-theme",
"editor.minimap.enabled": false,
"editor.fontFamily": "'MesloLGM Nerd Font', 'Droid Sans Mono', 'monospace', 'Droid Sans Fallback', 'Consolas'",
"editor.fontSize": 14,
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"resmon.show.cpufreq": false,
"omnisharp.projectLoadTimeout": 60,
"workbench.colorTheme": "Visual Studio Light",
"workbench.iconTheme": "vscode-icons",
"workbench.iconTheme": "material-icon-theme",
"editor.minimap.enabled": false,
"editor.fontFamily": "'MesloLGM Nerd Font', 'Droid Sans Mono', 'monospace', 'Droid Sans Fallback', 'Consolas'",
"editor.fontSize": 14,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package grpcError
package interceptors

import (
"context"

"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/grpc/grpcerrors"

"emperror.dev/errors"
grpcerrors "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/grpc/grpcErrors"
"google.golang.org/grpc"
)

Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/grpc/config"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/grpc/handlers/otel"
grpcError "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/grpc/interceptors/grpcerror"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/grpc/interceptors"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/logger"

"emperror.dev/errors"
Expand Down Expand Up @@ -49,12 +49,12 @@ func NewGrpcServer(
logger logger.Logger,
) GrpcServer {
unaryServerInterceptors := []googleGrpc.UnaryServerInterceptor{
grpcError.UnaryServerInterceptor(),
interceptors.UnaryServerInterceptor(),
grpcCtxTags.UnaryServerInterceptor(),
grpcRecovery.UnaryServerInterceptor(),
}
streamServerInterceptors := []googleGrpc.StreamServerInterceptor{
grpcError.StreamServerInterceptor(),
interceptors.StreamServerInterceptor(),
}

s := googleGrpc.NewServer(
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/otel/tracing/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"reflect"

"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/core/metadata"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/grpc/grpcerrors"
grpcerrors "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/grpc/grpcErrors"
customErrors "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/http/httperrors/customerrors"
problemdetails "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/http/httperrors/problemdetails"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/otel/constants/telemetrytags"
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/rabbitmq/bus/rabbitmq_bus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
defaultlogger "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/logger/defaultlogger"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/config"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/configurations"
rabbitmqconsumer "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/consumer"
consumerConfigurations "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/consumer/configurations"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/consumer/factory"
producerfactory "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/producer"
rabbitmqproducer "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/producer"
producerConfigurations "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/producer/configurations"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/types"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/test/containers/testcontainer/rabbitmq"
Expand Down Expand Up @@ -57,13 +57,13 @@ func Test_AddRabbitMQ(t *testing.T) {
conn, err := types.NewRabbitMQConnection(options)
require.NoError(t, err)

consumerFactory := factory.NewConsumerFactory(
consumerFactory := rabbitmqconsumer.NewConsumerFactory(
options,
conn,
serializer,
defaultlogger.GetLogger(),
)
producerFactory := producerfactory.NewProducerFactory(
producerFactory := rabbitmqproducer.NewProducerFactory(
options,
conn,
serializer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package factory
package consumer

import (
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/core/messaging/consumer"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/core/messaging/types"
serializer "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/core/serializer"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/logger"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/config"
rabbitmqconsumer "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/consumer"
consumerConfigurations "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/consumer/configurations"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/consumer/consumercontracts"
types2 "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/types"
Expand Down Expand Up @@ -37,7 +36,7 @@ func (c *consumerFactory) CreateConsumer(
consumerConfiguration *consumerConfigurations.RabbitMQConsumerConfiguration,
isConsumedNotifications ...func(message types.IMessage),
) (consumer.Consumer, error) {
return rabbitmqconsumer.NewRabbitMQConsumer(
return NewRabbitMQConsumer(
c.rabbitmqOptions,
c.connection,
consumerConfiguration,
Expand Down
7 changes: 3 additions & 4 deletions internal/pkg/rabbitmq/consumer/rabbitmq_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import (
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/config"
rabbitmqConfigurations "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/configurations"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/consumer/configurations"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/consumer/factory"
producerfactory "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/producer"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/producer"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/types"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/test/containers/testcontainer/rabbitmq"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/test/messaging/consumer"
Expand Down Expand Up @@ -54,13 +53,13 @@ func Test_Consumer_With_Fake_Message(t *testing.T) {
eventSerializer := json.NewDefaultMessageJsonSerializer(
json.NewDefaultJsonSerializer(),
)
consumerFactory := factory.NewConsumerFactory(
consumerFactory := NewConsumerFactory(
options,
conn,
eventSerializer,
defaultLogger2.GetLogger(),
)
producerFactory := producerfactory.NewProducerFactory(
producerFactory := producer.NewProducerFactory(
options,
conn,
eventSerializer,
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/rabbitmq/rabbitmq_fx.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/logger"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/bus"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/config"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/consumer/factory"
producer2 "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/producer"
rabbitmqconsumer "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/consumer"
rabbitmqproducer "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/producer"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/rabbitmq/types"

"go.uber.org/fx"
Expand Down Expand Up @@ -43,8 +43,8 @@ var (
fx.As(new(bus2.Bus)),
fx.As(new(bus.RabbitmqBus)),
)),
fx.Provide(factory.NewConsumerFactory),
fx.Provide(producer2.NewProducerFactory),
fx.Provide(rabbitmqconsumer.NewConsumerFactory),
fx.Provide(rabbitmqproducer.NewProducerFactory),
fx.Provide(fx.Annotate(
NewRabbitMQHealthChecker,
fx.As(new(contracts.Health)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func Test_Gorm_Container(t *testing.T) {
gorm, err := NewGnoMockGormContainer().Start(context.Background(), t)
gorm, err := NewGnoMockGormContainer().PopulateContainerOptions(context.Background(), t)
require.NoError(t, err)

assert.NotNil(t, gorm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func Test_Custom_PostgresPgx_Container(t *testing.T) {
gorm, err := NewPostgresPgxContainers(
defaultLogger.GetLogger(),
).Start(context.Background(), t)
).PopulateContainerOptions(context.Background(), t)
require.NoError(t, err)

assert.NotNil(t, gorm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package products

import (
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/core/web/route"
customEcho "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/http/customecho"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/http/customecho/contracts"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/services/catalogreadservice/internal/products/data/repositories"
getProductByIdV1 "github.com/mehdihadeli/go-food-delivery-microservices/internal/services/catalogreadservice/internal/products/features/get_product_by_id/v1/endpoints"
getProductsV1 "github.com/mehdihadeli/go-food-delivery-microservices/internal/services/catalogreadservice/internal/products/features/getting_products/v1/endpoints"
Expand All @@ -19,7 +19,7 @@ var Module = fx.Module(
fx.Provide(repositories.NewRedisProductRepository),
fx.Provide(repositories.NewMongoProductRepository),

fx.Provide(fx.Annotate(func(catalogsServer customEcho.EchoHttpServer) *echo.Group {
fx.Provide(fx.Annotate(func(catalogsServer contracts.EchoHttpServer) *echo.Group {
var g *echo.Group
catalogsServer.RouteBuilder().RegisterGroupFunc("/api/v1", func(v1 *echo.Group) {
group := v1.Group("/products")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"

"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/fxapp/contracts"
customEcho "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/http/customecho"
echocontracts "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/http/customecho/contracts"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/services/catalogreadservice/config"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/services/catalogreadservice/internal/products/configurations"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/services/catalogreadservice/internal/shared/configurations/catalogs/infrastructure"
Expand Down Expand Up @@ -46,7 +46,7 @@ func (ic *CatalogsServiceConfigurator) ConfigureCatalogs() {
func (ic *CatalogsServiceConfigurator) MapCatalogsEndpoints() {
// Shared
ic.ResolveFunc(
func(catalogsServer customEcho.EchoHttpServer, cfg *config.Config) error {
func(catalogsServer echocontracts.EchoHttpServer, cfg *config.Config) error {
catalogsServer.SetupDefaultMiddlewares()

// config catalogs root endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,70 +120,16 @@ func provideCatalogsMetrics(
return nil, err
}

createProductHttpRequests, err := meter.Float64Counter(
fmt.Sprintf("%s_create_product_http_requests_total", appOptions.ServiceName),
api.WithDescription("The total number of create product http requests"),
)
if err != nil {
return nil, err
}

updateProductHttpRequests, err := meter.Float64Counter(
fmt.Sprintf("%s_update_product_http_requests_total", appOptions.ServiceName),
api.WithDescription("The total number of update product http requests"),
)
if err != nil {
return nil, err
}

deleteProductHttpRequests, err := meter.Float64Counter(
fmt.Sprintf("%s_delete_product_http_requests_total", appOptions.ServiceName),
api.WithDescription("The total number of delete product http requests"),
)
if err != nil {
return nil, err
}

getProductByIdHttpRequests, err := meter.Float64Counter(
fmt.Sprintf("%s_get_product_by_id_http_requests_total", appOptions.ServiceName),
api.WithDescription("The total number of get product by id http requests"),
)
if err != nil {
return nil, err
}

getProductsHttpRequests, err := meter.Float64Counter(
fmt.Sprintf("%s_get_products_http_requests_total", appOptions.ServiceName),
api.WithDescription("The total number of get products http requests"),
)
if err != nil {
return nil, err
}

searchProductHttpRequests, err := meter.Float64Counter(
fmt.Sprintf("%s_search_product_http_requests_total", appOptions.ServiceName),
api.WithDescription("The total number of search product http requests"),
)
if err != nil {
return nil, err
}

return &contracts.CatalogsMetrics{
CreateProductRabbitMQMessages: createProductRabbitMQMessages,
GetProductByIdGrpcRequests: getProductByIdGrpcRequests,
CreateProductGrpcRequests: createProductGrpcRequests,
CreateProductHttpRequests: createProductHttpRequests,
DeleteProductRabbitMQMessages: deleteProductRabbitMQMessages,
DeleteProductGrpcRequests: deleteProductGrpcRequests,
DeleteProductHttpRequests: deleteProductHttpRequests,
ErrorRabbitMQMessages: errorRabbitMQMessages,
GetProductByIdHttpRequests: getProductByIdHttpRequests,
GetProductsHttpRequests: getProductsHttpRequests,
SearchProductGrpcRequests: searchProductGrpcRequests,
SearchProductHttpRequests: searchProductHttpRequests,
SuccessRabbitMQMessages: successRabbitMQMessages,
UpdateProductRabbitMQMessages: updateProductRabbitMQMessages,
UpdateProductGrpcRequests: updateProductGrpcRequests,
UpdateProductHttpRequests: updateProductHttpRequests,
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import (
metricspipelines "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/otel/metrics/mediatr/pipelines"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/otel/tracing"
tracingpipelines "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/otel/tracing/mediatr/pipelines"
postgrespipelines "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/postgresgorm/pipelines"

"github.com/mehdihadeli/go-mediatr"
"gorm.io/gorm"
)

type InfrastructureConfigurator struct {
Expand All @@ -28,7 +26,7 @@ func NewInfrastructureConfigurator(

func (ic *InfrastructureConfigurator) ConfigInfrastructures() {
ic.ResolveFunc(
func(l logger.Logger, tracer tracing.AppTracer, metrics metrics.AppMetrics, db *gorm.DB) error {
func(l logger.Logger, tracer tracing.AppTracer, metrics metrics.AppMetrics) error {
err := mediatr.RegisterRequestPipelineBehaviors(
loggingpipelines.NewMediatorLoggingPipeline(l),
tracingpipelines.NewMediatorTracingPipeline(
Expand All @@ -39,7 +37,6 @@ func (ic *InfrastructureConfigurator) ConfigInfrastructures() {
metrics,
metricspipelines.WithLogger(l),
),
postgrespipelines.NewMediatorTransactionPipeline(l, db),
)

return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *ProductGrpcServiceServer) CreateProduct(
span.SetAttributes(attribute.Object("Request", req))
s.catalogsMetrics.CreateProductGrpcRequests.Add(ctx, 1, grpcMetricsAttr)

command, err := createProductCommandV1.NewCreateProduct(
command, err := createProductCommandV1.NewCreateProductWithValidation(
req.GetName(),
req.GetDescription(),
req.GetPrice(),
Expand Down Expand Up @@ -120,7 +120,7 @@ func (s *ProductGrpcServiceServer) UpdateProduct(
return nil, badRequestErr
}

command, err := updateProductCommandV1.NewUpdateProduct(
command, err := updateProductCommandV1.NewUpdateProductWithValidation(
productUUID,
req.GetName(),
req.GetDescription(),
Expand Down Expand Up @@ -186,7 +186,7 @@ func (s *ProductGrpcServiceServer) GetProductById(
return nil, badRequestErr
}

query, err := getProductByIdQueryV1.NewGetProductById(productUUID)
query, err := getProductByIdQueryV1.NewGetProductByIdWithValidation(productUUID)
if err != nil {
validationErr := customErrors.NewValidationErrorWrap(
err,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/es/contracts/store"
contracts2 "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/fxapp/contracts"
grpcServer "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/grpc"
customEcho "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/http/customecho"
echocontracts "github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/http/customecho/contracts"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/logger"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/pkg/otel/tracing"
"github.com/mehdihadeli/go-food-delivery-microservices/internal/services/orderservice/internal/orders/configurations/mappings"
Expand Down Expand Up @@ -35,7 +35,7 @@ func NewOrdersModuleConfigurator(
func (c *OrdersModuleConfigurator) ConfigureOrdersModule() {
c.ResolveFunc(
func(logger logger.Logger,
server customEcho.EchoHttpServer,
server echocontracts.EchoHttpServer,
orderRepository repositories.OrderMongoRepository,
orderAggregateStore store.AggregateStore[*aggregate.Order],
tracer tracing.AppTracer,
Expand Down
Loading

0 comments on commit 14fc2ea

Please sign in to comment.