/
routes_gen.go
83 lines (71 loc) · 1.94 KB
/
routes_gen.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
79
80
81
82
83
// Code generated by server_generator. DO NOT EDIT.
// generated version: unknown
package sample
import (
"net/http"
"github.com/labstack/echo/v4"
props "github.com/go-generalize/api_gen/server_generator/sample/props"
)
// Routes ...
type Routes struct {
router *echo.Group
}
// NewRoutes ...
func NewRoutes(p *props.ControllerProps, router *echo.Group) *Routes {
r := &Routes{
router: router,
}
router.POST("create_table", r.PostCreateTable(p))
router.POST("create_user", r.PostCreateUser(p))
return r
}
// PostCreateTable ...
func (r *Routes) PostCreateTable(p *props.ControllerProps) echo.HandlerFunc {
i := NewPostCreateTableController(p)
return func(c echo.Context) error {
req := new(PostCreateTableRequest)
if err := c.Bind(req); err != nil {
return c.JSON(http.StatusBadRequest, map[string]interface{}{
"code": http.StatusBadRequest,
"message": "invalid request.",
})
}
res, err := i.PostCreateTable(c, req)
if err != nil {
return err
}
if res == nil {
return nil
}
return c.JSON(http.StatusOK, res)
}
}
// PostCreateUser ...
func (r *Routes) PostCreateUser(p *props.ControllerProps) echo.HandlerFunc {
i := NewPostCreateUserController(p)
return func(c echo.Context) error {
req := new(PostCreateUserRequest)
if err := c.Bind(req); err != nil {
return c.JSON(http.StatusBadRequest, map[string]interface{}{
"code": http.StatusBadRequest,
"message": "invalid request.",
})
}
res, err := i.PostCreateUser(c, req)
if err != nil {
return err
}
if res == nil {
return nil
}
return c.JSON(http.StatusOK, res)
}
}
// IPostCreateTableController ...
type IPostCreateTableController interface {
PostCreateTable(c echo.Context, req *PostCreateTableRequest) (res *PostCreateTableResponse, err error)
}
// IPostCreateUserController ...
type IPostCreateUserController interface {
PostCreateUser(c echo.Context, req *PostCreateUserRequest) (res *PostCreateUserResponse, err error)
}