Added Editing of plates, items, configurations

This commit is contained in:
2026-05-26 17:15:36 +02:00
parent 66543b75d4
commit be58c5941d
6 changed files with 341 additions and 40 deletions
+15
View File
@@ -58,6 +58,21 @@ func (s *ConfigurationStore) Save(c model.Configuration) (model.Configuration, e
return c, nil
}
// Update replaces an existing configuration by ID (preserves created_at).
func (s *ConfigurationStore) Update(id string, c model.Configuration) (model.Configuration, error) {
path := filepath.Join(s.dir, id+".json")
existing, err := readJSON[model.Configuration](path)
if err != nil {
return model.Configuration{}, fmt.Errorf("configuration not found: %s", id)
}
c.ID = existing.ID
c.CreatedAt = existing.CreatedAt
if err := writeJSON(path, c); err != nil {
return model.Configuration{}, fmt.Errorf("write configuration: %w", err)
}
return c, nil
}
// Delete removes a configuration by ID.
func (s *ConfigurationStore) Delete(id string) error {
path := filepath.Join(s.dir, id+".json")
+24
View File
@@ -65,6 +65,30 @@ func (s *ItemStore) Create(name string, spec model.ItemSpec) (model.Item, error)
return svgtemplate.WriteMeta(basename, spec, displayName)
}
// Update regenerates the SVG and metadata for an existing item (preserves id, svg filename, created_at).
func (s *ItemStore) Update(id string, name string, spec model.ItemSpec) (model.Item, error) {
if spec.SizeMM <= 0 {
return model.Item{}, fmt.Errorf("size_mm must be positive")
}
item, err := s.Get(id)
if err != nil {
return model.Item{}, err
}
data := svgtemplate.Build(spec.SizeMM, spec.BleedMM, spec.MarginMM, spec.PaddingMM)
if err := svgtemplate.WriteFile(item.SVGTemplate, data); err != nil {
return model.Item{}, fmt.Errorf("write svg: %w", err)
}
if name != "" {
item.Name = name
}
item.Spec = spec
metaPath := filepath.Join(s.dir, model.MetaFilename(item.SVGTemplate))
if err := writeJSON(metaPath, item); err != nil {
return model.Item{}, fmt.Errorf("write meta: %w", err)
}
return item, nil
}
// Delete removes an item's SVG and metadata by ID.
func (s *ItemStore) Delete(id string) error {
item, err := s.Get(id)
+15
View File
@@ -49,6 +49,21 @@ func (s *PlateStore) Save(p model.Plate) (model.Plate, error) {
return p, nil
}
// Update replaces an existing plate by ID (preserves created_at).
func (s *PlateStore) Update(id string, p model.Plate) (model.Plate, error) {
path := filepath.Join(s.dir, id+".json")
existing, err := readJSON[model.Plate](path)
if err != nil {
return model.Plate{}, fmt.Errorf("plate not found: %s", id)
}
p.ID = existing.ID
p.CreatedAt = existing.CreatedAt
if err := writeJSON(path, p); err != nil {
return model.Plate{}, fmt.Errorf("write plate: %w", err)
}
return p, nil
}
// Delete removes a plate by ID.
func (s *PlateStore) Delete(id string) error {
path := filepath.Join(s.dir, id+".json")