Skip to content

Commit

Permalink
fixes issue with not having all system transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzelei committed Nov 21, 2024
1 parent 8f6aa01 commit 718ad80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -690,27 +690,17 @@ func (s *Service) GetSystemTransformers(
ctx context.Context,
req *connect.Request[mgmtv1alpha1.GetSystemTransformersRequest],
) (*connect.Response[mgmtv1alpha1.GetSystemTransformersResponse], error) {
if s.cfg.IsNeosyncCloud {
return connect.NewResponse(&mgmtv1alpha1.GetSystemTransformersResponse{
Transformers: allSystemTransformers,
}), nil
} else {
return connect.NewResponse(&mgmtv1alpha1.GetSystemTransformersResponse{
Transformers: baseSystemTransformers,
}), nil
}
systemTransformers := s.getSystemTransformers()
return connect.NewResponse(&mgmtv1alpha1.GetSystemTransformersResponse{
Transformers: systemTransformers,
}), nil
}

func (s *Service) GetSystemTransformerBySource(
ctx context.Context,
req *connect.Request[mgmtv1alpha1.GetSystemTransformerBySourceRequest],
) (*connect.Response[mgmtv1alpha1.GetSystemTransformerBySourceResponse], error) {
var transformerMap map[mgmtv1alpha1.TransformerSource]*mgmtv1alpha1.SystemTransformer
if s.cfg.IsNeosyncCloud {
transformerMap = allSystemTransformersSourceMap
} else {
transformerMap = baseSystemTransformerSourceMap
}
transformerMap := s.getSystemTransformerSourceMap()

transformer, ok := transformerMap[req.Msg.GetSource()]
if !ok {
Expand All @@ -720,3 +710,17 @@ func (s *Service) GetSystemTransformerBySource(
Transformer: transformer,
}), nil
}

func (s *Service) getSystemTransformerSourceMap() map[mgmtv1alpha1.TransformerSource]*mgmtv1alpha1.SystemTransformer {
if s.cfg.IsNeosyncCloud {
return allSystemTransformersSourceMap
}
return baseSystemTransformerSourceMap
}

func (s *Service) getSystemTransformers() []*mgmtv1alpha1.SystemTransformer {
if s.cfg.IsNeosyncCloud {
return allSystemTransformers
}
return baseSystemTransformers
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *Service) GetUserDefinedTransformers(
dtoTransformers := []*mgmtv1alpha1.UserDefinedTransformer{}
for idx := range transformers {
transformer := transformers[idx]
dto, err := dtomaps.ToUserDefinedTransformerDto(&transformer, baseSystemTransformerSourceMap)
dto, err := dtomaps.ToUserDefinedTransformerDto(&transformer, s.getSystemTransformerSourceMap())
if err != nil {
return nil, fmt.Errorf("failed to map user defined transformer %s with source %d: %w", neosyncdb.UUIDString(transformer.ID), transformer.Source, err)
}
Expand Down Expand Up @@ -66,7 +66,7 @@ func (s *Service) GetUserDefinedTransformerById(
return nil, err
}

dto, err := dtomaps.ToUserDefinedTransformerDto(&transformer, baseSystemTransformerSourceMap)
dto, err := dtomaps.ToUserDefinedTransformerDto(&transformer, s.getSystemTransformerSourceMap())
if err != nil {
return nil, fmt.Errorf("failed to map user defined transformer %s with source %d: %w", neosyncdb.UUIDString(transformer.ID), transformer.Source, err)
}
Expand Down Expand Up @@ -107,7 +107,7 @@ func (s *Service) CreateUserDefinedTransformer(ctx context.Context, req *connect
return nil, err
}

dto, err := dtomaps.ToUserDefinedTransformerDto(&ct, baseSystemTransformerSourceMap)
dto, err := dtomaps.ToUserDefinedTransformerDto(&ct, s.getSystemTransformerSourceMap())
if err != nil {
return nil, fmt.Errorf("failed to map user defined transformer %s with source %d: %w", neosyncdb.UUIDString(ct.ID), ct.Source, err)
}
Expand Down Expand Up @@ -188,9 +188,9 @@ func (s *Service) UpdateUserDefinedTransformer(ctx context.Context, req *connect
return nil, err
}

dto, err := dtomaps.ToUserDefinedTransformerDto(&updatedTransformer, baseSystemTransformerSourceMap)
dto, err := dtomaps.ToUserDefinedTransformerDto(&updatedTransformer, s.getSystemTransformerSourceMap())
if err != nil {
return nil, fmt.Errorf("failed to map user defined transformer %s with source %d", neosyncdb.UUIDString(updatedTransformer.ID), updatedTransformer.Source)
return nil, fmt.Errorf("failed to map user defined transformer %s with source %d: %w", neosyncdb.UUIDString(updatedTransformer.ID), updatedTransformer.Source, err)
}

return connect.NewResponse(&mgmtv1alpha1.UpdateUserDefinedTransformerResponse{
Expand Down

0 comments on commit 718ad80

Please sign in to comment.