Add Surat Keluar

This commit is contained in:
Aditya Siregar
2025-09-20 16:31:22 +07:00
parent 0399c87736
commit e4946d6e05
13 changed files with 1151 additions and 13 deletions
+20
View File
@@ -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