mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-06-01 21:50:05 +08:00
feat: automatic file organization based on rules, close #28
This commit is contained in:
@@ -41,3 +41,7 @@ func GetDirsByUserIDAndStorageName(userID uint, storageName string) ([]Dir, erro
|
||||
func DeleteDirForUser(userID uint, storageName, path string) error {
|
||||
return db.Unscoped().Where("user_id = ? AND storage_name = ? AND path = ?", userID, storageName, path).Delete(&Dir{}).Error
|
||||
}
|
||||
|
||||
func DeleteDirByID(id uint) error {
|
||||
return db.Unscoped().Delete(&Dir{}, id).Error
|
||||
}
|
||||
22
dao/rule.go
Normal file
22
dao/rule.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package dao
|
||||
|
||||
func CreateRule(rule *Rule) error {
|
||||
return db.Create(rule).Error
|
||||
}
|
||||
|
||||
func DeleteRule(ruleID uint) error {
|
||||
return db.Unscoped().Delete(&Rule{}, ruleID).Error
|
||||
}
|
||||
|
||||
func UpdateUserApplyRule(chatID int64, applyRule bool) error {
|
||||
return db.Model(&User{}).Where("chat_id = ?", chatID).Update("apply_rule", applyRule).Error
|
||||
}
|
||||
|
||||
func GetRulesByUserChatID(chatID int64) ([]Rule, error) {
|
||||
var rules []Rule
|
||||
err := db.Where("user_id = (SELECT id FROM users WHERE chat_id = ?)", chatID).Find(&rules).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rules, nil
|
||||
}
|
||||
Reference in New Issue
Block a user