API: Add POST /api/items/{partNumber}/bom/merge endpoint #45
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add a server-side BOM merge endpoint that accepts an assembly-derived BOM from silo-mod and intelligently merges it with the existing server BOM. The merge is synchronous — the server computes the diff, applies safe changes, and returns the full diff in the response.
Endpoint
Requires: Editor role + RequireWritable (blocked in read-only mode)
Request Body
Each entry represents a direct child from the assembly. All entries are treated as
source = "assembly".Response Body
Merge Rules
The merge only considers entries where
source = 'assembly'on the server side. Manual entries are untouched.source = 'assembly'warningsarray asunreferencedCritical rule
Assembly-sourced entries that disappear from the assembly are never auto-deleted. They appear as "unreferenced" warnings. The user must explicitly remove them via the web UI or API. This protects against:
Implementation
Database layer (
internal/db/relationships.go)New method:
This filters
GetBOMby thesourcecolumn. Needed so the merge can compare only assembly-sourced entries.Handler (
internal/api/bom_handlers.go)New handler
HandleMergeBOM:{partNumber}to parent item IDchild_part_numbervalues must exist)GetBOMBySource(ctx, parentID, "assembly")local[child_pn] = qtyvsremote[child_pn] = qtysource = 'assembly')bom.mergedevent (see #45)Route (
internal/api/routes.go)Register in the editor-gated BOM group:
Dependencies
Error Cases
404— parent part number not found400— invalid request body or unknown child part numbers409— cycle detected (adding a child would create circular BOM)503— server in read-only mode