Skip to content

Commit

Permalink
update existing artifact with custom helper
Browse files Browse the repository at this point in the history
Signed-off-by: Isabella do Amaral <[email protected]>
  • Loading branch information
isinyaaa committed Sep 23, 2024
1 parent e59a231 commit 1567e6d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 156 deletions.
150 changes: 0 additions & 150 deletions internal/converter/generated/openapi_reconciler.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions internal/converter/openapi_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ type OpenAPIReconciler interface {
// goverter:ignore Id CreateTimeSinceEpoch LastUpdateTimeSinceEpoch Name RegisteredModelId
UpdateExistingModelVersion(source OpenapiUpdateWrapper[openapi.ModelVersion]) (openapi.ModelVersion, error)

// Ignore all fields that can't be updated
// goverter:default InitWithExisting
// goverter:autoMap Update
UpdateExistingArtifact(source OpenapiUpdateWrapper[openapi.Artifact]) (openapi.Artifact, error)

// Ignore all fields that can't be updated
// goverter:default InitWithExisting
// goverter:autoMap Update
Expand Down
23 changes: 23 additions & 0 deletions internal/converter/openapi_reconciler_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package converter

import (
"github.com/kubeflow/model-registry/pkg/openapi"
)

func UpdateExistingArtifact(genc OpenAPIReconciler, source OpenapiUpdateWrapper[openapi.Artifact]) (openapi.Artifact, error) {
art := InitWithExisting(source)
if source.Update == nil {
return art, nil
}
ma, err := genc.UpdateExistingModelArtifact(OpenapiUpdateWrapper[openapi.ModelArtifact]{Existing: art.ModelArtifact, Update: source.Update.ModelArtifact})
if err != nil {
return art, err
}
da, err := genc.UpdateExistingDocArtifact(OpenapiUpdateWrapper[openapi.DocArtifact]{Existing: art.DocArtifact, Update: source.Update.DocArtifact})
if err != nil {
return art, err
}
art.DocArtifact = &da
art.ModelArtifact = &ma
return art, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func (s *ModelRegistryServiceAPIService) UpdateArtifact(ctx context.Context, art
if err != nil {
return ErrorResponse(api.ErrToStatus(err), err), err
}
update, err := s.reconciler.UpdateExistingArtifact(converter.NewOpenapiUpdateWrapper(existing, entity))
update, err := converter.UpdateExistingArtifact(s.reconciler, converter.NewOpenapiUpdateWrapper(existing, entity))
if err != nil {
return ErrorResponse(http.StatusBadRequest, err), err
}
Expand Down

0 comments on commit 1567e6d

Please sign in to comment.