add paper weight
This commit is contained in:
@@ -136,6 +136,7 @@ func (rc *configController) PaperHandler(ctx *gin.Context) {
|
|||||||
paper.Name = newPaper.Name
|
paper.Name = newPaper.Name
|
||||||
paper.Brand = newPaper.Brand
|
paper.Brand = newPaper.Brand
|
||||||
paper.Size = newPaper.Size
|
paper.Size = newPaper.Size
|
||||||
|
paper.Weight = newPaper.Weight
|
||||||
paper.Price = newPaper.Price
|
paper.Price = newPaper.Price
|
||||||
paper, err = repositories.Papers.Update(paper)
|
paper, err = repositories.Papers.Update(paper)
|
||||||
|
|
||||||
|
|||||||
@@ -34,40 +34,49 @@ func ParseSize(s string) (c PaperSize, err error) {
|
|||||||
|
|
||||||
type Paper struct {
|
type Paper struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Name string `json:"name" binding:"required" gorm:"not null"`
|
Name string `json:"name" binding:"required" gorm:"not null"`
|
||||||
Brand string `json:"brand" binding:"required"`
|
Brand string `json:"brand" binding:"required"`
|
||||||
Size PaperSize `json:"size" binding:"required"`
|
Size PaperSize `json:"size" binding:"required"`
|
||||||
Price float64 `json:"price" binding:"required"`
|
Weight int `json:"weight" binding:"required"`
|
||||||
|
Price float64 `json:"price" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPaper(ctx *gin.Context) (Paper, error) {
|
func NewPaper(ctx *gin.Context) (Paper, error) {
|
||||||
name := ctx.PostForm("name")
|
name := ctx.PostForm("name")
|
||||||
brand := ctx.PostForm("brand")
|
brand := ctx.PostForm("brand")
|
||||||
sizeTmp := ctx.PostForm("size")
|
sizeTmp := ctx.PostForm("size")
|
||||||
|
weightTmp := ctx.PostForm("weight")
|
||||||
priceTmp := ctx.PostForm("price")
|
priceTmp := ctx.PostForm("price")
|
||||||
|
|
||||||
price, err := strconv.ParseFloat(priceTmp, 64)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return Paper{}, fmt.Errorf("Couldnt parse Price")
|
|
||||||
}
|
|
||||||
|
|
||||||
size, err := ParseSize(sizeTmp)
|
size, err := ParseSize(sizeTmp)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Paper{}, fmt.Errorf("Couldnt parse Size")
|
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 == "" {
|
if name == "" || brand == "" {
|
||||||
return Paper{}, fmt.Errorf("Name or brand empty")
|
return Paper{}, fmt.Errorf("Name or brand empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the price string to float64
|
// Convert the price string to float64
|
||||||
tag := Paper{
|
tag := Paper{
|
||||||
Name: name,
|
Name: name,
|
||||||
Brand: brand,
|
Brand: brand,
|
||||||
Size: size,
|
Size: size,
|
||||||
Price: price,
|
Weight: weight,
|
||||||
|
Price: price,
|
||||||
}
|
}
|
||||||
|
|
||||||
return tag, nil
|
return tag, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user