Add Surat Keluar
This commit is contained in:
@@ -356,6 +356,26 @@ func (r *DepartmentRepository) GetChildren(ctx context.Context, parentPath strin
|
||||
return departments, nil
|
||||
}
|
||||
|
||||
func (r *DepartmentRepository) GetAllDescendants(ctx context.Context, parentID uuid.UUID) ([]entities.Department, error) {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
|
||||
// First get the parent department to get its path
|
||||
var parent entities.Department
|
||||
if err := db.WithContext(ctx).First(&parent, "id = ?", parentID).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var departments []entities.Department
|
||||
// Get all descendants using ltree
|
||||
if err := db.WithContext(ctx).
|
||||
Where("path <@ ? AND path != ?", parent.Path, parent.Path).
|
||||
Order("path ASC").
|
||||
Find(&departments).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return departments, nil
|
||||
}
|
||||
|
||||
func (r *DepartmentRepository) UpdateChildrenPaths(ctx context.Context, oldPath, newPath string) error {
|
||||
db := DBFromContext(ctx, r.db)
|
||||
// Use raw SQL for ltree path update
|
||||
|
||||
Reference in New Issue
Block a user