Added Plates and Items Models and connected them with the Frontend

This commit is contained in:
2026-05-26 16:16:30 +02:00
parent 8ec5472355
commit 50e677c729
14 changed files with 951 additions and 79 deletions
+38
View File
@@ -0,0 +1,38 @@
package svgtemplate
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"
"github.com/google/uuid"
"printer.backend/internal/model"
)
// WriteMeta writes item metadata next to the SVG in OutputDir.
func WriteMeta(svgBasename string, spec model.ItemSpec, name string) (model.Item, error) {
if err := os.MkdirAll(OutputDir, 0o755); err != nil {
return model.Item{}, err
}
base := filepath.Base(filepath.Clean(svgBasename))
item := model.Item{
ID: uuid.NewString(),
Name: name,
Spec: spec,
SVGTemplate: base,
CreatedAt: time.Now().UTC(),
}
metaPath := filepath.Join(OutputDir, model.MetaFilename(base))
data, err := json.MarshalIndent(item, "", " ")
if err != nil {
return model.Item{}, err
}
if err := os.WriteFile(metaPath, data, 0o644); err != nil {
return model.Item{}, fmt.Errorf("write meta: %w", err)
}
return item, nil
}
+3 -1
View File
@@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"text/template"
"printer.backend/internal/paths"
)
const svgTemplate = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
@@ -55,7 +57,7 @@ func Write(w io.Writer, data Data) error {
}
// OutputDir is the directory where generated SVG files are written.
const OutputDir = "svg_template"
const OutputDir = paths.SVGTemplateDir
// WriteFile renders the SVG template into OutputDir.
func WriteFile(path string, data Data) error {