-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCatalogProductSuperAttribute.go
77 lines (68 loc) · 2.68 KB
/
CatalogProductSuperAttribute.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"
)
// CatalogProductSuperAttribute :
type CatalogProductSuperAttribute struct {
ProductSuperAttributeId uint16 `gorm:"column:product_super_attribute_id;primary_key" form:"product_super_attribute_id;primary_key" json:"product_super_attribute_id;primary_key"`
ProductId uint16 `gorm:"column:product_id" form:"product_id" json:"product_id"`
AttributeId uint16 `gorm:"column:attribute_id" form:"attribute_id" json:"attribute_id"`
Position uint16 `gorm:"column:position" form:"position" json:"position"`
}
// TableName :
func (*CatalogProductSuperAttribute) TableName() string {
return "catalog_product_super_attribute"
}
// handler create
func initRoutersCatalogProductSuperAttribute(r *gin.Engine, catalogproductsuperattribute string) {
route := r.Group("catalogproductsuperattribute")
route.GET("/", getCatalogProductSuperAttributes)
route.GET("/:id", getCatalogProductSuperAttribute)
route.POST("/", createCatalogProductSuperAttribute)
route.PUT("/:id", updateCatalogProductSuperAttribute)
route.DELETE("/:id", deleteCatalogProductSuperAttribute)
}
func getCatalogProductSuperAttributes(c *gin.Context) {
var catalogProductSuperAttributes []CatalogProductSuperAttribute
if err := g.Find(&catalogProductSuperAttributes).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.JSON(200, catalogProductSuperAttributes)
}
}
func getCatalogProductSuperAttribute(c *gin.Context) {
id := c.Params.ByName("id")
var catalogProductSuperAttribute CatalogProductSuperAttribute
if err := g.Where("id = ?", id).First(&catalogProductSuperAttribute).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.JSON(200, catalogProductSuperAttribute)
}
}
func createCatalogProductSuperAttribute(c *gin.Context) {
var catalogProductSuperAttribute CatalogProductSuperAttribute
c.BindJSON(&catalogProductSuperAttribute)
g.Create(&catalogProductSuperAttribute)
c.JSON(200, catalogProductSuperAttribute)
}
func updateCatalogProductSuperAttribute(c *gin.Context) {
var catalogProductSuperAttribute CatalogProductSuperAttribute
id := c.Params.ByName("id")
if err := g.Where("id = ?", id).First(&catalogProductSuperAttribute).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
}
c.BindJSON(&catalogProductSuperAttribute)
g.Save(&catalogProductSuperAttribute)
c.JSON(200, catalogProductSuperAttribute)
}
func deleteCatalogProductSuperAttribute(c *gin.Context) {
id := c.Params.ByName("id")
var catalogProductSuperAttribute CatalogProductSuperAttribute
d := g.Where("id = ?", id).Delete(&catalogProductSuperAttribute)
fmt.Println(d)
c.JSON(200, gin.H{"id #" + id: "deleted"})
}