-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcategories.controller.go
More file actions
46 lines (39 loc) · 1.16 KB
/
categories.controller.go
File metadata and controls
46 lines (39 loc) · 1.16 KB
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
package main
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
/**
* @api {post} /v1/companies/:id/categories Insert New Category
* @apiName InsertNewCategory
* @apiGroup Categories
* @apiVersion 0.1.0
*
* @apiUse jwt
*
* @apiParam (Request body) {Number} [parent_id] Parent ID.
* @apiParam (Request body) {String} name Category name.
* @apiParam (Request body) {Number} order Order.
*/
func insertNewCategory(c *gin.Context) {
var category Categorise
if err := c.ShouldBindWith(&category, binding.JSON); err != nil {
c.JSON(400, gin.H{"message": err.Error()})
return
}
category.CompanyId = c.MustGet("company_id").(uint)
_, err := MySql.InsertInto("product_categories").Values(category).Exec()
if err != nil {
c.JSON(400, gin.H{"message": err.Error()})
return
}
c.JSON(201, gin.H{"message": "successful"})
return
}
type Categorise struct {
Id uint `db:"id"`
ParentId uint `db:"parent_id" json:"parent_id" binding:"lte=2147483648"`
CompanyId uint `db:"company_id"`
Name string `db:"name" json:"name" binding:"required,gte=0,lte=64"`
Order uint `db:"order" json:"order" binding:"lte=2147483648"`
}