-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCatalogProductBundleOptionValue.go
77 lines (68 loc) · 2.66 KB
/
CatalogProductBundleOptionValue.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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
// CatalogProductBundleOptionValue :
type CatalogProductBundleOptionValue struct {
ValueId uint16 `gorm:"column:value_id;primary_key" form:"value_id;primary_key" json:"value_id;primary_key"`
OptionId uint16 `gorm:"column:option_id" form:"option_id" json:"option_id"`
StoreId uint16 `gorm:"column:store_id" form:"store_id" json:"store_id"`
Title string `gorm:"column:title" form:"title" json:"title"`
}
// TableName :
func (*CatalogProductBundleOptionValue) TableName() string {
return "catalog_product_bundle_option_value"
}
// handler create
func initRoutersCatalogProductBundleOptionValue(r *gin.Engine, catalogproductbundleoptionvalue string) {
route := r.Group("catalogproductbundleoptionvalue")
route.GET("/", getCatalogProductBundleOptionValues)
route.GET("/:id", getCatalogProductBundleOptionValue)
route.POST("/", createCatalogProductBundleOptionValue)
route.PUT("/:id", updateCatalogProductBundleOptionValue)
route.DELETE("/:id", deleteCatalogProductBundleOptionValue)
}
func getCatalogProductBundleOptionValues(c *gin.Context) {
var catalogProductBundleOptionValues []CatalogProductBundleOptionValue
if err := g.Find(&catalogProductBundleOptionValues).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.JSON(200, catalogProductBundleOptionValues)
}
}
func getCatalogProductBundleOptionValue(c *gin.Context) {
id := c.Params.ByName("id")
var catalogProductBundleOptionValue CatalogProductBundleOptionValue
if err := g.Where("id = ?", id).First(&catalogProductBundleOptionValue).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.JSON(200, catalogProductBundleOptionValue)
}
}
func createCatalogProductBundleOptionValue(c *gin.Context) {
var catalogProductBundleOptionValue CatalogProductBundleOptionValue
c.BindJSON(&catalogProductBundleOptionValue)
g.Create(&catalogProductBundleOptionValue)
c.JSON(200, catalogProductBundleOptionValue)
}
func updateCatalogProductBundleOptionValue(c *gin.Context) {
var catalogProductBundleOptionValue CatalogProductBundleOptionValue
id := c.Params.ByName("id")
if err := g.Where("id = ?", id).First(&catalogProductBundleOptionValue).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
}
c.BindJSON(&catalogProductBundleOptionValue)
g.Save(&catalogProductBundleOptionValue)
c.JSON(200, catalogProductBundleOptionValue)
}
func deleteCatalogProductBundleOptionValue(c *gin.Context) {
id := c.Params.ByName("id")
var catalogProductBundleOptionValue CatalogProductBundleOptionValue
d := g.Where("id = ?", id).Delete(&catalogProductBundleOptionValue)
fmt.Println(d)
c.JSON(200, gin.H{"id #" + id: "deleted"})
}