重构 #4
| @@ -221,7 +221,7 @@ func (c *Controller) UpdateDevice(ctx *gin.Context) { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	// 3. 更新字段 | ||||
| 	// 3. 更新从数据库中查出的现有设备对象的字段 | ||||
| 	existingDevice.Name = req.Name | ||||
| 	existingDevice.Type = req.Type | ||||
| 	existingDevice.SubType = req.SubType | ||||
| @@ -229,7 +229,7 @@ func (c *Controller) UpdateDevice(ctx *gin.Context) { | ||||
| 	existingDevice.Location = req.Location | ||||
| 	existingDevice.Properties = datatypes.JSON(req.Properties) | ||||
|  | ||||
| 	// 4. 保存到数据库 | ||||
| 	// 4. 将修改后的 existingDevice 对象保存回数据库 | ||||
| 	if err := c.repo.Update(existingDevice); err != nil { | ||||
| 		c.logger.Errorf("更新设备: 数据库操作失败: %v", err) | ||||
| 		controller.SendErrorResponse(ctx, http.StatusInternalServerError, "更新设备失败") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user