fix bug of test data with update handler
This commit is contained in:
parent
59574b4b90
commit
0520e9cece
|
|
@ -24,13 +24,33 @@ func UpdateTopologicIntoDB(ctx context.Context, tx *gorm.DB, pageID int64, chang
|
|||
case constant.UUIDFromChangeType:
|
||||
result = tx.WithContext(cancelCtx).Model(&orm.Topologic{}).Where("page_id = ? and uuid_from = ? and uuid_to = ?", pageID, changeInfo.OldUUIDFrom, changeInfo.OldUUIDTo).Updates(orm.Topologic{UUIDFrom: changeInfo.NewUUIDFrom})
|
||||
case constant.UUIDToChangeType:
|
||||
var delTopologic orm.Topologic
|
||||
result = tx.WithContext(cancelCtx).Model(&orm.Topologic{}).Where("page_id = ? and uuid_to = ?", pageID, changeInfo.NewUUIDTo).Find(&delTopologic)
|
||||
|
||||
if result.Error != nil {
|
||||
return fmt.Errorf("find topologic link by new_uuid_to failed:%w", result.Error)
|
||||
}
|
||||
|
||||
if result.RowsAffected == 1 {
|
||||
// delete old topologic link
|
||||
result = tx.WithContext(cancelCtx).Where("id = ?", delTopologic.ID).Delete(&delTopologic)
|
||||
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check delete topologic where conditions", constant.ErrDeleteRowZero)
|
||||
}
|
||||
return fmt.Errorf("del old topologic link by new_uuid_to failed:%w", err)
|
||||
}
|
||||
}
|
||||
|
||||
result = tx.WithContext(cancelCtx).Model(&orm.Topologic{}).Where("page_id = ? and uuid_from = ? and uuid_to = ?", pageID, changeInfo.OldUUIDFrom, changeInfo.OldUUIDTo).Updates(&orm.Topologic{UUIDTo: changeInfo.NewUUIDTo})
|
||||
case constant.UUIDAddChangeType:
|
||||
topologic := orm.Topologic{
|
||||
PageID: pageID,
|
||||
Flag: changeInfo.Flag,
|
||||
UUIDFrom: changeInfo.NewUUIDFrom,
|
||||
UUIDTo: changeInfo.OldUUIDFrom,
|
||||
UUIDTo: changeInfo.NewUUIDTo,
|
||||
Comment: changeInfo.Comment,
|
||||
}
|
||||
result = tx.WithContext(cancelCtx).Create(&topologic)
|
||||
|
|
|
|||
|
|
@ -105,12 +105,14 @@ func (g *Graph) DelEdge(from, to uuid.UUID) error {
|
|||
fromKeys = []uuid.UUID{from}
|
||||
}
|
||||
|
||||
// Process the situation where the to node is taken as the parent node while deleting edges
|
||||
childvertex := g.VerticeLinks[toKey]
|
||||
err := g.DelNode(toKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("delete edge failed: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("fromKeys:", fromKeys)
|
||||
for _, fromUUID := range fromKeys {
|
||||
fromKey := fromUUID.String()
|
||||
var delIndex int
|
||||
|
|
@ -119,10 +121,15 @@ func (g *Graph) DelEdge(from, to uuid.UUID) error {
|
|||
delIndex = index
|
||||
}
|
||||
}
|
||||
|
||||
vertex := g.VerticeLinks[fromKey]
|
||||
copy(vertex[delIndex:], vertex[delIndex+1:])
|
||||
vertex = vertex[:len(vertex)-1]
|
||||
g.VerticeLinks[fromKey] = vertex
|
||||
if len(vertex) == 1 {
|
||||
g.DelNode(fromKey)
|
||||
} else {
|
||||
copy(vertex[delIndex:], vertex[delIndex+1:])
|
||||
vertex = vertex[:len(vertex)-1]
|
||||
g.VerticeLinks[fromKey] = vertex
|
||||
}
|
||||
}
|
||||
|
||||
fromKey := from.String()
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
"topologics":[
|
||||
{
|
||||
"change_type":1,
|
||||
"old_uuid_from":"70c190f2-8a75-42a9-b166-ec5f87e0aa6b",
|
||||
"old_uuid_from":"e32bc0be-67f4-4d79-a5da-eaa40a5bd77d",
|
||||
"old_uuid_to":"70c200f2-8a75-42a9-c166-bf5f87e0aa6b",
|
||||
"new_uuid_from":"e32bc0be-67f4-4d79-a5da-eaa40a5bd77d",
|
||||
"new_uuid_from":"70c190f2-8a75-42a9-b166-ec5f87e0aa6b",
|
||||
"new_uuid_to":"70c200f2-8a75-42a9-c166-bf5f87e0aa6b"
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ func CircuitDiagramCreateHandler(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// commit transsction
|
||||
// commit transaction
|
||||
tx.Commit()
|
||||
resp := network.SuccessResponse{
|
||||
SuccessResponseHeader: network.SuccessResponseHeader{Status: http.StatusOK},
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ func CircuitDiagramDeleteHandler(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// commit transsction
|
||||
// commit transaction
|
||||
tx.Commit()
|
||||
resp := network.SuccessResponse{
|
||||
SuccessResponseHeader: network.SuccessResponseHeader{Status: http.StatusOK},
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ func CircuitDiagramUpdateHandler(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// commit transsction
|
||||
// commit transaction
|
||||
tx.Commit()
|
||||
|
||||
resp := network.SuccessResponse{
|
||||
|
|
|
|||
Loading…
Reference in New Issue