-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCatalogCategoryAncCategsIndexTmp.go
75 lines (66 loc) · 2.53 KB
/
CatalogCategoryAncCategsIndexTmp.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"
)
// CatalogCategoryAncCategsIndexTmp :
type CatalogCategoryAncCategsIndexTmp struct {
CategoryId uint16 `gorm:"column:category_id" form:"category_id" json:"category_id"`
Path string `gorm:"column:path" form:"path" json:"path"`
}
// TableName :
func (*CatalogCategoryAncCategsIndexTmp) TableName() string {
return "catalog_category_anc_categs_index_tmp"
}
// handler create
func initRoutersCatalogCategoryAncCategsIndexTmp(r *gin.Engine, catalogcategoryanccategsindextmp string) {
route := r.Group("catalogcategoryanccategsindextmp")
route.GET("/", getCatalogCategoryAncCategsIndexTmps)
route.GET("/:id", getCatalogCategoryAncCategsIndexTmp)
route.POST("/", createCatalogCategoryAncCategsIndexTmp)
route.PUT("/:id", updateCatalogCategoryAncCategsIndexTmp)
route.DELETE("/:id", deleteCatalogCategoryAncCategsIndexTmp)
}
func getCatalogCategoryAncCategsIndexTmps(c *gin.Context) {
var catalogCategoryAncCategsIndexTmps []CatalogCategoryAncCategsIndexTmp
if err := g.Find(&catalogCategoryAncCategsIndexTmps).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.JSON(200, catalogCategoryAncCategsIndexTmps)
}
}
func getCatalogCategoryAncCategsIndexTmp(c *gin.Context) {
id := c.Params.ByName("id")
var catalogCategoryAncCategsIndexTmp CatalogCategoryAncCategsIndexTmp
if err := g.Where("id = ?", id).First(&catalogCategoryAncCategsIndexTmp).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.JSON(200, catalogCategoryAncCategsIndexTmp)
}
}
func createCatalogCategoryAncCategsIndexTmp(c *gin.Context) {
var catalogCategoryAncCategsIndexTmp CatalogCategoryAncCategsIndexTmp
c.BindJSON(&catalogCategoryAncCategsIndexTmp)
g.Create(&catalogCategoryAncCategsIndexTmp)
c.JSON(200, catalogCategoryAncCategsIndexTmp)
}
func updateCatalogCategoryAncCategsIndexTmp(c *gin.Context) {
var catalogCategoryAncCategsIndexTmp CatalogCategoryAncCategsIndexTmp
id := c.Params.ByName("id")
if err := g.Where("id = ?", id).First(&catalogCategoryAncCategsIndexTmp).Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
}
c.BindJSON(&catalogCategoryAncCategsIndexTmp)
g.Save(&catalogCategoryAncCategsIndexTmp)
c.JSON(200, catalogCategoryAncCategsIndexTmp)
}
func deleteCatalogCategoryAncCategsIndexTmp(c *gin.Context) {
id := c.Params.ByName("id")
var catalogCategoryAncCategsIndexTmp CatalogCategoryAncCategsIndexTmp
d := g.Where("id = ?", id).Delete(&catalogCategoryAncCategsIndexTmp)
fmt.Println(d)
c.JSON(200, gin.H{"id #" + id: "deleted"})
}