add paper weight

This commit is contained in:
2025-06-29 15:37:02 +02:00
parent f4faeb351d
commit 6330a990f5
2 changed files with 24 additions and 14 deletions

View File

@@ -136,6 +136,7 @@ func (rc *configController) PaperHandler(ctx *gin.Context) {
paper.Name = newPaper.Name
paper.Brand = newPaper.Brand
paper.Size = newPaper.Size
paper.Weight = newPaper.Weight
paper.Price = newPaper.Price
paper, err = repositories.Papers.Update(paper)

View File

@@ -37,6 +37,7 @@ type Paper struct {
Name string `json:"name" binding:"required" gorm:"not null"`
Brand string `json:"brand" binding:"required"`
Size PaperSize `json:"size" binding:"required"`
Weight int `json:"weight" binding:"required"`
Price float64 `json:"price" binding:"required"`
}
@@ -44,20 +45,27 @@ func NewPaper(ctx *gin.Context) (Paper, error) {
name := ctx.PostForm("name")
brand := ctx.PostForm("brand")
sizeTmp := ctx.PostForm("size")
weightTmp := ctx.PostForm("weight")
priceTmp := ctx.PostForm("price")
price, err := strconv.ParseFloat(priceTmp, 64)
if err != nil {
return Paper{}, fmt.Errorf("Couldnt parse Price")
}
size, err := ParseSize(sizeTmp)
if err != nil {
return Paper{}, fmt.Errorf("Couldnt parse Size")
}
weight, err := strconv.Atoi(weightTmp)
if err != nil {
return Paper{}, fmt.Errorf("Couldnt parse Weight")
}
price, err := strconv.ParseFloat(priceTmp, 64)
if err != nil {
return Paper{}, fmt.Errorf("Couldnt parse Price")
}
if name == "" || brand == "" {
return Paper{}, fmt.Errorf("Name or brand empty")
}
@@ -67,6 +75,7 @@ func NewPaper(ctx *gin.Context) (Paper, error) {
Name: name,
Brand: brand,
Size: size,
Weight: weight,
Price: price,
}