-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCatalogCompareItem.go
78 lines (69 loc) · 2.36 KB
/
CatalogCompareItem.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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
// CatalogCompareItem :
type CatalogCompareItem struct {
CatalogCompareItemId uint16 `gorm:"column:catalog_compare_item_id;primary_key" form:"catalog_compare_item_id;primary_key" json:"catalog_compare_item_id;primary_key"`
VisitorId uint16 `gorm:"column:visitor_id" form:"visitor_id" json:"visitor_id"`
CustomerId uint16 `gorm:"column:customer_id" form:"customer_id" json:"customer_id"`
ProductId uint16 `gorm:"column:product_id" form:"product_id" json:"product_id"`
StoreId uint16 `gorm:"column:store_id" form:"store_id" json:"store_id"`
}
// TableName :
func (*CatalogCompareItem) TableName() string {
return "catalog_compare_item"
}
// handler create
func initRoutersCatalogCompareItem(r *gin.Engine, catalogcompareitem string) {
route := r.Group("catalogcompareitem")
route.GET("/", getCatalogCompareItems)
route.GET("/:id", getCatalogCompareItem)
route.POST("/", createCatalogCompareItem)
route.PUT("/:id", updateCatalogCompareItem)
route.DELETE("/:id", deleteCatalogCompareItem)
}
func getCatalogCompareItems(c *gin.Context) {
var catalogCompareItems []CatalogCompareItem
if err := g.Find(&catalogCompareItems).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.JSON(200, catalogCompareItems)
}
}
func getCatalogCompareItem(c *gin.Context) {
id := c.Params.ByName("id")
var catalogCompareItem CatalogCompareItem
if err := g.Where("id = ?", id).First(&catalogCompareItem).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.JSON(200, catalogCompareItem)
}
}
func createCatalogCompareItem(c *gin.Context) {
var catalogCompareItem CatalogCompareItem
c.BindJSON(&catalogCompareItem)
g.Create(&catalogCompareItem)
c.JSON(200, catalogCompareItem)
}
func updateCatalogCompareItem(c *gin.Context) {
var catalogCompareItem CatalogCompareItem
id := c.Params.ByName("id")
if err := g.Where("id = ?", id).First(&catalogCompareItem).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
}
c.BindJSON(&catalogCompareItem)
g.Save(&catalogCompareItem)
c.JSON(200, catalogCompareItem)
}
func deleteCatalogCompareItem(c *gin.Context) {
id := c.Params.ByName("id")
var catalogCompareItem CatalogCompareItem
d := g.Where("id = ?", id).Delete(&catalogCompareItem)
fmt.Println(d)
c.JSON(200, gin.H{"id #" + id: "deleted"})
}