-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCatalogProductSuperAttributePricing.go
79 lines (70 loc) · 3.14 KB
/
CatalogProductSuperAttributePricing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
// CatalogProductSuperAttributePricing :
type CatalogProductSuperAttributePricing struct {
ValueId uint16 `gorm:"column:value_id;primary_key" form:"value_id;primary_key" json:"value_id;primary_key"`
ProductSuperAttributeId uint16 `gorm:"column:product_super_attribute_id" form:"product_super_attribute_id" json:"product_super_attribute_id"`
ValueIndex string `gorm:"column:value_index" form:"value_index" json:"value_index"`
IsPercent uint16 `gorm:"column:is_percent" form:"is_percent" json:"is_percent"`
PricingValue float64 `gorm:"column:pricing_value" form:"pricing_value" json:"pricing_value"`
WebsiteId uint16 `gorm:"column:website_id" form:"website_id" json:"website_id"`
}
// TableName :
func (*CatalogProductSuperAttributePricing) TableName() string {
return "catalog_product_super_attribute_pricing"
}
// handler create
func initRoutersCatalogProductSuperAttributePricing(r *gin.Engine, catalogproductsuperattributepricing string) {
route := r.Group("catalogproductsuperattributepricing")
route.GET("/", getCatalogProductSuperAttributePricings)
route.GET("/:id", getCatalogProductSuperAttributePricing)
route.POST("/", createCatalogProductSuperAttributePricing)
route.PUT("/:id", updateCatalogProductSuperAttributePricing)
route.DELETE("/:id", deleteCatalogProductSuperAttributePricing)
}
func getCatalogProductSuperAttributePricings(c *gin.Context) {
var catalogProductSuperAttributePricings []CatalogProductSuperAttributePricing
if err := g.Find(&catalogProductSuperAttributePricings).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.JSON(200, catalogProductSuperAttributePricings)
}
}
func getCatalogProductSuperAttributePricing(c *gin.Context) {
id := c.Params.ByName("id")
var catalogProductSuperAttributePricing CatalogProductSuperAttributePricing
if err := g.Where("id = ?", id).First(&catalogProductSuperAttributePricing).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.JSON(200, catalogProductSuperAttributePricing)
}
}
func createCatalogProductSuperAttributePricing(c *gin.Context) {
var catalogProductSuperAttributePricing CatalogProductSuperAttributePricing
c.BindJSON(&catalogProductSuperAttributePricing)
g.Create(&catalogProductSuperAttributePricing)
c.JSON(200, catalogProductSuperAttributePricing)
}
func updateCatalogProductSuperAttributePricing(c *gin.Context) {
var catalogProductSuperAttributePricing CatalogProductSuperAttributePricing
id := c.Params.ByName("id")
if err := g.Where("id = ?", id).First(&catalogProductSuperAttributePricing).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
}
c.BindJSON(&catalogProductSuperAttributePricing)
g.Save(&catalogProductSuperAttributePricing)
c.JSON(200, catalogProductSuperAttributePricing)
}
func deleteCatalogProductSuperAttributePricing(c *gin.Context) {
id := c.Params.ByName("id")
var catalogProductSuperAttributePricing CatalogProductSuperAttributePricing
d := g.Where("id = ?", id).Delete(&catalogProductSuperAttributePricing)
fmt.Println(d)
c.JSON(200, gin.H{"id #" + id: "deleted"})
}