refactor(elixir): hierarchical refactor

to extract common code patterns from
category/storage location systems
This commit is contained in:
Schuwi
2025-09-17 23:56:56 +02:00
parent 963c9a3770
commit 264adbfb98
12 changed files with 415 additions and 1173 deletions

View File

@@ -55,6 +55,15 @@ Repo.delete_all(StorageLocation)
parent_id: capacitors.id
})
# Create a DEEP category hierarchy to test fallback path (7+ levels)
{:ok, deep_cat_1} = Inventory.create_category(%{name: "Level 1", description: "Deep hierarchy test", parent_id: resistors.id})
{:ok, deep_cat_2} = Inventory.create_category(%{name: "Level 2", description: "Deep hierarchy test", parent_id: deep_cat_1.id})
{:ok, deep_cat_3} = Inventory.create_category(%{name: "Level 3", description: "Deep hierarchy test", parent_id: deep_cat_2.id})
{:ok, deep_cat_4} = Inventory.create_category(%{name: "Level 4", description: "Deep hierarchy test", parent_id: deep_cat_3.id})
{:ok, deep_cat_5} = Inventory.create_category(%{name: "Level 5", description: "Deep hierarchy test", parent_id: deep_cat_4.id})
{:ok, deep_cat_6} = Inventory.create_category(%{name: "Level 6", description: "Deep hierarchy test", parent_id: deep_cat_5.id})
{:ok, deep_cat_7} = Inventory.create_category(%{name: "Level 7", description: "Deep hierarchy test - triggers fallback", parent_id: deep_cat_6.id})
# Create storage locations
{:ok, shelf_a} = Inventory.create_storage_location(%{name: "Shelf A", description: "Main electronics shelf"})
{:ok, _shelf_b} = Inventory.create_storage_location(%{name: "Shelf B", description: "Components overflow shelf"})
@@ -104,6 +113,15 @@ Repo.delete_all(StorageLocation)
parent_id: drawer_a2.id
})
# Create a DEEP storage location hierarchy to test fallback path (7+ levels)
{:ok, deep_loc_1} = Inventory.create_storage_location(%{name: "Deep Level 1", description: "Deep hierarchy test", parent_id: box_a1_3.id})
{:ok, deep_loc_2} = Inventory.create_storage_location(%{name: "Deep Level 2", description: "Deep hierarchy test", parent_id: deep_loc_1.id})
{:ok, deep_loc_3} = Inventory.create_storage_location(%{name: "Deep Level 3", description: "Deep hierarchy test", parent_id: deep_loc_2.id})
{:ok, deep_loc_4} = Inventory.create_storage_location(%{name: "Deep Level 4", description: "Deep hierarchy test", parent_id: deep_loc_3.id})
{:ok, deep_loc_5} = Inventory.create_storage_location(%{name: "Deep Level 5", description: "Deep hierarchy test", parent_id: deep_loc_4.id})
{:ok, deep_loc_6} = Inventory.create_storage_location(%{name: "Deep Level 6", description: "Deep hierarchy test", parent_id: deep_loc_5.id})
{:ok, deep_loc_7} = Inventory.create_storage_location(%{name: "Deep Level 7", description: "Deep hierarchy test - triggers fallback", parent_id: deep_loc_6.id})
# Create sample components
sample_components = [
%{
@@ -186,6 +204,23 @@ sample_components = [
storage_location_id: box_a1_1.id,
count: 100,
category_id: resistors.id
},
# Test components for deep hierarchies to ensure fallback path is exercised
%{
name: "Deep Category Test Component",
description: "Component in 7-level deep category hierarchy",
keywords: "test deep hierarchy category fallback",
storage_location_id: box_a1_1.id,
count: 1,
category_id: deep_cat_7.id
},
%{
name: "Deep Storage Test Component",
description: "Component in 7-level deep storage location hierarchy",
keywords: "test deep hierarchy storage fallback",
storage_location_id: deep_loc_7.id,
count: 1,
category_id: resistors.id
}
]
@@ -211,10 +246,12 @@ sample_locations = [
Enum.each(sample_locations, fn location ->
if location.apriltag_id do
apriltag_url = AprilTag.get_apriltag_url(location)
IO.puts("#{location.path}: AprilTag ID #{location.apriltag_id}")
location_path = StorageLocation.full_path(location)
IO.puts("#{location_path}: AprilTag ID #{location.apriltag_id}")
IO.puts(" Download URL: #{apriltag_url}")
else
IO.puts("#{location.path}: No AprilTag assigned")
location_path = StorageLocation.full_path(location)
IO.puts("#{location_path}: No AprilTag assigned")
end
end)