feat(api): add GET /api/items/by-uuid/{uuid} endpoint
Closes #43 Adds a new read-only endpoint to resolve a Silo item UUID to its full ItemResponse. Used by silo-mod to resolve FreeCAD document SiloUUID properties to part numbers during BOM sync. - Reuses existing ItemRepository.GetByID() (items.id is the stable UUID) - Returns 404 for archived items - Registered in viewer-accessible route group (no editor role required)
This commit is contained in:
@@ -465,6 +465,26 @@ func (s *Server) HandleCreateItem(w http.ResponseWriter, r *http.Request) {
|
||||
s.broker.Publish("item.created", mustMarshal(resp))
|
||||
}
|
||||
|
||||
// HandleGetItemByUUID retrieves an item by its stable UUID (the items.id column).
|
||||
// Used by silo-mod to resolve FreeCAD document SiloUUID properties to part numbers.
|
||||
func (s *Server) HandleGetItemByUUID(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
uuid := chi.URLParam(r, "uuid")
|
||||
|
||||
item, err := s.items.GetByID(ctx, uuid)
|
||||
if err != nil {
|
||||
s.logger.Error().Err(err).Msg("failed to get item by UUID")
|
||||
writeError(w, http.StatusInternalServerError, "internal_error", "Failed to get item")
|
||||
return
|
||||
}
|
||||
if item == nil || item.ArchivedAt != nil {
|
||||
writeError(w, http.StatusNotFound, "not_found", "Item not found")
|
||||
return
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusOK, itemToResponse(item))
|
||||
}
|
||||
|
||||
// HandleGetItem retrieves an item by part number.
|
||||
// Supports query param: ?include=properties to include current revision properties.
|
||||
func (s *Server) HandleGetItem(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -119,6 +119,7 @@ func NewRouter(server *Server, logger zerolog.Logger) http.Handler {
|
||||
r.Route("/items", func(r chi.Router) {
|
||||
r.Get("/", server.HandleListItems)
|
||||
r.Get("/search", server.HandleFuzzySearch)
|
||||
r.Get("/by-uuid/{uuid}", server.HandleGetItemByUUID)
|
||||
r.Get("/export.csv", server.HandleExportCSV)
|
||||
r.Get("/template.csv", server.HandleCSVTemplate)
|
||||
r.Get("/export.ods", server.HandleExportODS)
|
||||
|
||||
Reference in New Issue
Block a user