Skip to content

Commit b9f9014

Browse files
author
Keerthan Mala
committed
change the latest versions endpoint to suppport existing beta clients
1 parent 6c17c7d commit b9f9014

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pkg/handlers/get_latest_versions.go

+24
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,27 @@ func GetLatestVersions(params operations.GetComponentsByLatestReleaseParams, db
6262
ret := operations.GetComponentsByLatestReleaseOKBodyBody{Data: componentVersions}
6363
return operations.NewGetComponentsByLatestReleaseOK().WithPayload(ret)
6464
}
65+
66+
// GetLatestVersionsForV2 is the handler for the POST /v2/versions/latest endpoint
67+
func GetLatestVersionsForV2(params operations.GetComponentsByLatestReleaseForV2Params, db *gorm.DB) middleware.Responder {
68+
reqStruct := params.Body
69+
componentAndTrainSlice := make([]data.ComponentAndTrain, len(reqStruct.Data))
70+
for i, d := range reqStruct.Data {
71+
//this is just to make the existing workflow manager clients out in the beta world to work.
72+
if d.Version.Train == "" {
73+
d.Version.Train = "beta"
74+
}
75+
componentAndTrainSlice[i] = data.ComponentAndTrain{
76+
ComponentName: d.Component.Name,
77+
Train: d.Version.Train,
78+
}
79+
}
80+
81+
componentVersions, err := data.GetLatestVersions(db, componentAndTrainSlice)
82+
if err != nil {
83+
log.Printf("data.GetLatestVersions error (%s)", err)
84+
return operations.NewGetComponentsByLatestReleaseForV2Default(http.StatusInternalServerError).WithPayload(&models.Error{Code: http.StatusInternalServerError, Message: "database error"})
85+
}
86+
ret := operations.GetComponentsByLatestReleaseForV2OKBodyBody{Data: componentVersions}
87+
return operations.NewGetComponentsByLatestReleaseForV2OK().WithPayload(ret)
88+
}

pkg/swagger/restapi/configure_workflow_manager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func configureAPI(api *operations.WorkflowManagerAPI) http.Handler {
8080
return handlers.GetLatestVersions(params, rdsDB)
8181
})
8282
api.GetComponentsByLatestReleaseForV2Handler = operations.GetComponentsByLatestReleaseForV2HandlerFunc(func(params operations.GetComponentsByLatestReleaseForV2Params) middleware.Responder {
83-
return handlers.GetLatestVersions(operations.GetComponentsByLatestReleaseParams{Body: operations.GetComponentsByLatestReleaseBody{Data: params.Body.Data}}, rdsDB)
83+
return handlers.GetLatestVersionsForV2(params, rdsDB)
8484
})
8585
api.PublishComponentReleaseHandler = operations.PublishComponentReleaseHandlerFunc(func(params operations.PublishComponentReleaseParams) middleware.Responder {
8686
return handlers.PublishVersion(params, rdsDB)

0 commit comments

Comments
 (0)