forked from gooaclok819/sublinkX
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from JxQg/jxq_dev
新增订阅节点排序功能
- Loading branch information
Showing
9 changed files
with
280 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package models | ||
|
||
type SubscriptionNodes struct { | ||
SubscriptionID int `gorm:"primaryKey"` | ||
NodeID int `gorm:"primaryKey"` | ||
Sort int `gorm:"default:0"` | ||
} | ||
|
||
// 更新节点列表建立多对多关系并更新排序 | ||
func (sn *SubscriptionNodes) UpdateNodesWithSort(subID int, nodeSorts []SubscriptionNodes) error { | ||
for _, node := range nodeSorts { | ||
subNode := SubscriptionNodes{ | ||
SubscriptionID: subID, | ||
NodeID: node.NodeID, | ||
Sort: node.Sort, // 使用传入的排序字段 | ||
} | ||
// 使用 Save 方法进行插入或更新 | ||
if err := DB.Save(&subNode).Error; err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// 根据订阅ID删除关联的节点排序信息的方法 | ||
func (sn *SubscriptionNodes) DeleteNodesBySubscriptionID(subID int) error { | ||
return DB.Where("subscription_id = ?", subID).Delete(&SubscriptionNodes{}).Error | ||
} | ||
|
||
// 根据节点ID删除节点排序信息的方法 | ||
func (sn *SubscriptionNodes) DeleteNodeSortByNodeID(nodeID int) error { | ||
return DB.Where("node_id = ?", nodeID).Delete(&SubscriptionNodes{}).Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.