Added the possibilty to not only make quadratic items
This commit is contained in:
+10
-19
@@ -176,14 +176,6 @@ func listItems(s *store.ItemStore) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
type saveItemRequest struct {
|
||||
Name string `json:"name"`
|
||||
SizeMM float64 `json:"size_mm"`
|
||||
BleedMM float64 `json:"bleed_mm"`
|
||||
MarginMM float64 `json:"margin_mm"`
|
||||
PaddingMM float64 `json:"padding_mm"`
|
||||
}
|
||||
|
||||
func saveItem(s *store.ItemStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req saveItemRequest
|
||||
@@ -191,11 +183,10 @@ func saveItem(s *store.ItemStore) http.HandlerFunc {
|
||||
writeError(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
spec := model.ItemSpec{
|
||||
SizeMM: req.SizeMM,
|
||||
BleedMM: req.BleedMM,
|
||||
MarginMM: req.MarginMM,
|
||||
PaddingMM: req.PaddingMM,
|
||||
spec, err := itemSpecFromRequest(req)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
saved, err := s.Create(req.Name, spec)
|
||||
if err != nil {
|
||||
@@ -218,12 +209,12 @@ func updateItem(s *store.ItemStore) http.HandlerFunc {
|
||||
writeError(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
saved, err := s.Update(id, req.Name, model.ItemSpec{
|
||||
SizeMM: req.SizeMM,
|
||||
BleedMM: req.BleedMM,
|
||||
MarginMM: req.MarginMM,
|
||||
PaddingMM: req.PaddingMM,
|
||||
})
|
||||
spec, err := itemSpecFromRequest(req)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
saved, err := s.Update(id, req.Name, spec)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, err)
|
||||
return
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package api
|
||||
|
||||
import "printer.backend/internal/model"
|
||||
|
||||
type saveItemRequest struct {
|
||||
Name string `json:"name"`
|
||||
SizeMM float64 `json:"size_mm"`
|
||||
WidthMM float64 `json:"width_mm"`
|
||||
HeightMM float64 `json:"height_mm"`
|
||||
CornerRadiusMM float64 `json:"corner_radius_mm"`
|
||||
BleedMM float64 `json:"bleed_mm"`
|
||||
MarginMM float64 `json:"margin_mm"`
|
||||
PaddingMM float64 `json:"padding_mm"`
|
||||
}
|
||||
|
||||
func itemSpecFromRequest(req saveItemRequest) (model.ItemSpec, error) {
|
||||
spec := model.ItemSpec{
|
||||
SizeMM: req.SizeMM,
|
||||
WidthMM: req.WidthMM,
|
||||
HeightMM: req.HeightMM,
|
||||
CornerRadiusMM: req.CornerRadiusMM,
|
||||
BleedMM: req.BleedMM,
|
||||
MarginMM: req.MarginMM,
|
||||
PaddingMM: req.PaddingMM,
|
||||
}
|
||||
if err := spec.Normalize(); err != nil {
|
||||
return model.ItemSpec{}, err
|
||||
}
|
||||
return spec, nil
|
||||
}
|
||||
Reference in New Issue
Block a user