task_nature_controller.go
3.7 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
99
100
101
102
103
package controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/taskNature/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/taskNature/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/taskNature/service"
)
type TaskNatureController struct {
beego.Controller
}
func (controller *TaskNatureController) CreateTaskNature() {
taskNatureService := service.NewTaskNatureService(nil)
createTaskNatureCommand := &command.CreateTaskNatureCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createTaskNatureCommand)
data, err := taskNatureService.CreateTaskNature(createTaskNatureCommand)
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 *TaskNatureController) UpdateTaskNature() {
taskNatureService := service.NewTaskNatureService(nil)
updateTaskNatureCommand := &command.UpdateTaskNatureCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateTaskNatureCommand)
taskNatureId, _ := controller.GetInt(":taskNatureId")
updateTaskNatureCommand.TaskNatureId = taskNatureId
data, err := taskNatureService.UpdateTaskNature(updateTaskNatureCommand)
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 *TaskNatureController) GetTaskNature() {
taskNatureService := service.NewTaskNatureService(nil)
getTaskNatureQuery := &query.GetTaskNatureQuery{}
taskNatureId, _ := controller.GetInt(":taskNatureId")
getTaskNatureQuery.TaskNatureId = taskNatureId
data, err := taskNatureService.GetTaskNature(getTaskNatureQuery)
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 *TaskNatureController) RemoveTaskNature() {
taskNatureService := service.NewTaskNatureService(nil)
removeTaskNatureCommand := &command.RemoveTaskNatureCommand{}
taskNatureId, _ := controller.GetInt(":taskNatureId")
removeTaskNatureCommand.TaskNatureId = taskNatureId
data, err := taskNatureService.RemoveTaskNature(removeTaskNatureCommand)
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 *TaskNatureController) ListTaskNature() {
taskNatureService := service.NewTaskNatureService(nil)
listTaskNatureQuery := &query.ListTaskNatureQuery{}
companyId, _ := controller.GetInt64("companyId")
listTaskNatureQuery.CompanyId = companyId
taskNatureName := controller.GetString("taskNatureName")
listTaskNatureQuery.TaskNatureName = taskNatureName
taskNatureNameMatch := controller.GetString("taskNatureNameMatch")
listTaskNatureQuery.TaskNatureNameMatch = taskNatureNameMatch
offset, _ := controller.GetInt("offset")
listTaskNatureQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listTaskNatureQuery.Limit = limit
data, err := taskNatureService.ListTaskNature(listTaskNatureQuery)
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()
}