changes to fix update model 09/14109/1
authorrajdeep11 <rajdeep.sin@samsung.com>
Fri, 31 Jan 2025 09:12:43 +0000 (14:42 +0530)
committersubhash kumar singh <subh.singh@samsung.com>
Wed, 5 Feb 2025 14:56:06 +0000 (14:56 +0000)
Issue-Id: AIMLFW-174

Change-Id: I263294f683a9edc3b7296c6c35085a3cf2b5c8e9
Signed-off-by: rajdeep11 <rajdeep.sin@samsung.com>
apis/mmes_apis.go

index d599dcf..183d5ad 100644 (file)
@@ -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