-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCatalogCategoryProductIndexEnblTmp.go
75 lines (66 loc) · 2.62 KB
/
CatalogCategoryProductIndexEnblTmp.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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
// CatalogCategoryProductIndexEnblTmp :
type CatalogCategoryProductIndexEnblTmp struct {
ProductId uint16 `gorm:"column:product_id" form:"product_id" json:"product_id"`
Visibility uint16 `gorm:"column:visibility" form:"visibility" json:"visibility"`
}
// TableName :
func (*CatalogCategoryProductIndexEnblTmp) TableName() string {
return "catalog_category_product_index_enbl_tmp"
}
// handler create
func initRoutersCatalogCategoryProductIndexEnblTmp(r *gin.Engine, catalogcategoryproductindexenbltmp string) {
route := r.Group("catalogcategoryproductindexenbltmp")
route.GET("/", getCatalogCategoryProductIndexEnblTmps)
route.GET("/:id", getCatalogCategoryProductIndexEnblTmp)
route.POST("/", createCatalogCategoryProductIndexEnblTmp)
route.PUT("/:id", updateCatalogCategoryProductIndexEnblTmp)
route.DELETE("/:id", deleteCatalogCategoryProductIndexEnblTmp)
}
func getCatalogCategoryProductIndexEnblTmps(c *gin.Context) {
var catalogCategoryProductIndexEnblTmps []CatalogCategoryProductIndexEnblTmp
if err := g.Find(&catalogCategoryProductIndexEnblTmps).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.JSON(200, catalogCategoryProductIndexEnblTmps)
}
}
func getCatalogCategoryProductIndexEnblTmp(c *gin.Context) {
id := c.Params.ByName("id")
var catalogCategoryProductIndexEnblTmp CatalogCategoryProductIndexEnblTmp
if err := g.Where("id = ?", id).First(&catalogCategoryProductIndexEnblTmp).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.JSON(200, catalogCategoryProductIndexEnblTmp)
}
}
func createCatalogCategoryProductIndexEnblTmp(c *gin.Context) {
var catalogCategoryProductIndexEnblTmp CatalogCategoryProductIndexEnblTmp
c.BindJSON(&catalogCategoryProductIndexEnblTmp)
g.Create(&catalogCategoryProductIndexEnblTmp)
c.JSON(200, catalogCategoryProductIndexEnblTmp)
}
func updateCatalogCategoryProductIndexEnblTmp(c *gin.Context) {
var catalogCategoryProductIndexEnblTmp CatalogCategoryProductIndexEnblTmp
id := c.Params.ByName("id")
if err := g.Where("id = ?", id).First(&catalogCategoryProductIndexEnblTmp).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
}
c.BindJSON(&catalogCategoryProductIndexEnblTmp)
g.Save(&catalogCategoryProductIndexEnblTmp)
c.JSON(200, catalogCategoryProductIndexEnblTmp)
}
func deleteCatalogCategoryProductIndexEnblTmp(c *gin.Context) {
id := c.Params.ByName("id")
var catalogCategoryProductIndexEnblTmp CatalogCategoryProductIndexEnblTmp
d := g.Where("id = ?", id).Delete(&catalogCategoryProductIndexEnblTmp)
fmt.Println(d)
c.JSON(200, gin.H{"id #" + id: "deleted"})
}