write comment of http handler
This commit is contained in:
parent
9385ba695c
commit
2b4ad06b71
|
|
@ -1,3 +1,4 @@
|
|||
// Package handler provides HTTP handlers for various endpoints.
|
||||
package handler
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// Package handler provides HTTP handlers for various endpoints.
|
||||
package handler
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// Package handler provides HTTP handlers for various endpoints.
|
||||
package handler
|
||||
|
||||
import (
|
||||
|
|
@ -17,6 +18,7 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
"github.com/gofrs/uuid"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
// CircuitDiagramDeleteHandler define circuit diagram delete process API
|
||||
|
|
@ -142,8 +144,29 @@ func CircuitDiagramDeleteHandler(c *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
component := &orm.Component{GlobalUUID: globalUUID}
|
||||
result := tx.WithContext(cancelCtx).Delete(component)
|
||||
var component orm.Component
|
||||
result := tx.WithContext(cancelCtx).Clauses(clause.Locking{Strength: "UPDATE"}).Where("uuid = ?", globalUUID).Find(&component)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
tx.Rollback()
|
||||
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check uuid conditions", constant.ErrDeleteRowZero)
|
||||
}
|
||||
|
||||
logger.Error("query component info into postgresDB failed", zap.String("component_global_uuid", componentInfo.UUID), zap.Error(err))
|
||||
header := network.FailResponseHeader{Status: http.StatusBadRequest, ErrMsg: err.Error()}
|
||||
resp := network.FailureResponse{
|
||||
FailResponseHeader: header,
|
||||
PayLoad: map[string]interface{}{
|
||||
"uuid": componentInfo.UUID,
|
||||
},
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
|
||||
result = tx.WithContext(cancelCtx).Delete(component)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
tx.Rollback()
|
||||
|
||||
|
|
@ -164,7 +187,6 @@ func CircuitDiagramDeleteHandler(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
// TODO 增加 for update 操作后再删除
|
||||
modelStruct := model.SelectModelByType(component.ComponentType)
|
||||
modelStruct.SetComponentID(component.ID)
|
||||
result = tx.WithContext(cancelCtx).Delete(modelStruct)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// Package handler provides HTTP handlers for various endpoints.
|
||||
package handler
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// Package handler provides HTTP handlers for various endpoints.
|
||||
package handler
|
||||
|
||||
import (
|
||||
|
|
|
|||
Loading…
Reference in New Issue