add tags
This commit is contained in:
@@ -1,42 +1,17 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"gorm.io/gorm"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ShopItem struct {
|
||||
gorm.Model
|
||||
Name string `json:"name" binding:"required" gorm:"unique;not null"`
|
||||
Abstract string `json:"Abstract" binding:"required"`
|
||||
Description string `json:"description" binding:"required"`
|
||||
Price float64 `json:"price" binding:"required"`
|
||||
IsPublic bool `json:"isPublic" gorm:"default:true"`
|
||||
Tags []Tag `gorm:"many2many:item_tags;"`
|
||||
//Images gin.multipart.FileHeader ``
|
||||
}
|
||||
|
||||
func NewShopItem(ctx *gin.Context) (ShopItem, error) {
|
||||
name := ctx.PostForm("name")
|
||||
description := ctx.PostForm("description")
|
||||
priceStr := ctx.PostForm("price")
|
||||
|
||||
// Convert the price string to float64
|
||||
price, err := strconv.ParseFloat(priceStr, 64)
|
||||
if err != nil {
|
||||
return ShopItem{}, fmt.Errorf("Could not parse price")
|
||||
}
|
||||
|
||||
shopItem := ShopItem{
|
||||
Name: name,
|
||||
Description: description,
|
||||
Price: price,
|
||||
IsPublic: true,
|
||||
}
|
||||
|
||||
if name == "" || description == "" {
|
||||
return ShopItem{}, fmt.Errorf("Name or description empty")
|
||||
}
|
||||
|
||||
return shopItem, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user