client_version_controller.go
3.5 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"github.com/tiptok/godevp/pkg/application/clientVersion/command"
"github.com/tiptok/godevp/pkg/application/clientVersion/query"
"github.com/tiptok/godevp/pkg/application/clientVersion/service"
)
type ClientVersionController struct {
beego.Controller
}
func (controller *ClientVersionController) CreateClientVersion() {
clientVersionService := service.NewClientVersionService(nil)
createClientVersionCommand := &command.CreateClientVersionCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createClientVersionCommand)
data, err := clientVersionService.CreateClientVersion(createClientVersionCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ClientVersionController) UpdateClientVersion() {
clientVersionService := service.NewClientVersionService(nil)
updateClientVersionCommand := &command.UpdateClientVersionCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateClientVersionCommand)
id, _ := controller.GetInt64(":id")
updateClientVersionCommand.Id = id
data, err := clientVersionService.UpdateClientVersion(updateClientVersionCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ClientVersionController) GetClientVersion() {
clientVersionService := service.NewClientVersionService(nil)
getClientVersionQuery := &query.GetClientVersionQuery{}
id, _ := controller.GetInt64(":id")
getClientVersionQuery.Id = id
data, err := clientVersionService.GetClientVersion(getClientVersionQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ClientVersionController) RemoveClientVersion() {
clientVersionService := service.NewClientVersionService(nil)
removeClientVersionCommand := &command.RemoveClientVersionCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), removeClientVersionCommand)
id, _ := controller.GetInt64(":id")
removeClientVersionCommand.Id = id
data, err := clientVersionService.RemoveClientVersion(removeClientVersionCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ClientVersionController) ListClientVersion() {
clientVersionService := service.NewClientVersionService(nil)
listClientVersionQuery := &query.ListClientVersionQuery{}
offset, _ := controller.GetInt("offset")
listClientVersionQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listClientVersionQuery.Limit = limit
data, err := clientVersionService.ListClientVersion(listClientVersionQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}