Added the possibilty to not only make quadratic items
This commit is contained in:
+14
-6
@@ -49,12 +49,16 @@ func (s *ItemStore) Get(id string) (model.Item, error) {
|
||||
|
||||
// Create generates SVG + metadata for a new item.
|
||||
func (s *ItemStore) Create(name string, spec model.ItemSpec) (model.Item, error) {
|
||||
if spec.SizeMM <= 0 {
|
||||
return model.Item{}, fmt.Errorf("size_mm must be positive")
|
||||
if err := spec.Normalize(); err != nil {
|
||||
return model.Item{}, err
|
||||
}
|
||||
|
||||
basename := svgBasename(name)
|
||||
data := svgtemplate.Build(spec.SizeMM, spec.BleedMM, spec.MarginMM, spec.PaddingMM)
|
||||
data := svgtemplate.Build(
|
||||
spec.WidthMM, spec.HeightMM,
|
||||
spec.BleedMM, spec.MarginMM, spec.PaddingMM,
|
||||
spec.CornerRadiusMM,
|
||||
)
|
||||
if err := svgtemplate.WriteFile(basename, data); err != nil {
|
||||
return model.Item{}, fmt.Errorf("write svg: %w", err)
|
||||
}
|
||||
@@ -67,14 +71,18 @@ func (s *ItemStore) Create(name string, spec model.ItemSpec) (model.Item, error)
|
||||
|
||||
// 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")
|
||||
if err := spec.Normalize(); err != nil {
|
||||
return model.Item{}, err
|
||||
}
|
||||
item, err := s.Get(id)
|
||||
if err != nil {
|
||||
return model.Item{}, err
|
||||
}
|
||||
data := svgtemplate.Build(spec.SizeMM, spec.BleedMM, spec.MarginMM, spec.PaddingMM)
|
||||
data := svgtemplate.Build(
|
||||
spec.WidthMM, spec.HeightMM,
|
||||
spec.BleedMM, spec.MarginMM, spec.PaddingMM,
|
||||
spec.CornerRadiusMM,
|
||||
)
|
||||
if err := svgtemplate.WriteFile(item.SVGTemplate, data); err != nil {
|
||||
return model.Item{}, fmt.Errorf("write svg: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user