From: rajdeep11 Date: Fri, 31 Jan 2025 09:12:43 +0000 (+0530) Subject: changes to fix update model X-Git-Tag: 4.0.0~9 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=6a0c8dff8ede89e48f67c272a400badd94aec109;p=aiml-fw%2Fawmf%2Fmodelmgmtservice.git changes to fix update model Issue-Id: AIMLFW-174 Change-Id: I263294f683a9edc3b7296c6c35085a3cf2b5c8e9 Signed-off-by: rajdeep11 --- diff --git a/apis/mmes_apis.go b/apis/mmes_apis.go index d599dcf..183d5ad 100644 --- a/apis/mmes_apis.go +++ b/apis/mmes_apis.go @@ -305,14 +305,28 @@ func (m *MmeApiHandler) UpdateModel(c *gin.Context) { }) return } + existingModelInfo, err := m.iDB.GetModelInfoById(id) - if id != modelInfo.Id { - c.JSON(http.StatusBadRequest, gin.H{ - "error": "ID in path and body does not match", + if err != nil || existingModelInfo.Id == ""{ + statusCode := http.StatusNotFound + logging.ERROR("Error occurred, send status code: ", statusCode) + c.JSON(statusCode, gin.H{ + "code": statusCode, + "message": fmt.Sprintf("model not found with id: %s", id), + }) + return + } + if existingModelInfo.ModelId.ModelName != modelInfo.ModelId.ModelName || existingModelInfo.ModelId.ModelVersion != modelInfo.ModelId.ModelVersion{ + statusCode := http.StatusBadRequest + logging.ERROR("Error occurred, send status code: ", statusCode) + c.JSON(statusCode, gin.H{ + "code": statusCode, + "message": fmt.Sprintf("model with id: %s have different modelname and modelversion than provided", id), }) return } + modelInfo.Id = id if err := m.iDB.Update(modelInfo); err != nil { logging.ERROR("error in update db", "Error:", err) return