From 6a0c8dff8ede89e48f67c272a400badd94aec109 Mon Sep 17 00:00:00 2001 From: rajdeep11 Date: Fri, 31 Jan 2025 14:42:43 +0530 Subject: [PATCH] changes to fix update model Issue-Id: AIMLFW-174 Change-Id: I263294f683a9edc3b7296c6c35085a3cf2b5c8e9 Signed-off-by: rajdeep11 --- apis/mmes_apis.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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 -- 2.16.6