mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-04 12:36:37 +08:00
complete multi-root library path support
This commit is contained in:
@@ -31,9 +31,16 @@ func (r *LibraryRepository) CreateWithRoots(ctx context.Context, l *model.Librar
|
||||
if roots[i].SortOrder == 0 {
|
||||
roots[i].SortOrder = i
|
||||
}
|
||||
enabled := roots[i].Enabled
|
||||
if err := tx.Create(&roots[i]).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if !enabled {
|
||||
if err := tx.Model(&model.LibraryRoot{}).Where("id = ?", roots[i].ID).Update("enabled", false).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
roots[i].Enabled = false
|
||||
}
|
||||
}
|
||||
l.Roots = roots
|
||||
return nil
|
||||
@@ -113,7 +120,19 @@ func (r *LibraryRepository) CreateRoot(ctx context.Context, root *model.LibraryR
|
||||
if !r.hasLibraryRootsTable() {
|
||||
return nil
|
||||
}
|
||||
return r.db.WithContext(ctx).Create(root).Error
|
||||
enabled := root.Enabled
|
||||
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Create(root).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if !enabled {
|
||||
if err := tx.Model(&model.LibraryRoot{}).Where("id = ?", root.ID).Update("enabled", false).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
root.Enabled = false
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (r *LibraryRepository) UpdateRoot(ctx context.Context, root *model.LibraryRoot, updates map[string]any) error {
|
||||
|
||||
Reference in New Issue
Block a user