dictionary_controller.go
2.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
package controllers
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/dictionary/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/dictionary/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/dictionary/service"
)
type DictionaryController struct {
baseController
}
func (controller *DictionaryController) returnPageListData(count int64, data interface{}, err error, pageNumber int) {
dataMap := map[string]interface{}{
"grid": map[string]interface{}{
"total": count,
"pageNumber": pageNumber,
"list": data,
},
}
controller.Response(dataMap, err)
}
func (controller *DictionaryController) CreateDictionary() {
dictionaryService := service.NewDictionaryService(nil)
createDictionaryCommand := &command.CreateDictionaryCommand{}
_ = controller.Unmarshal(createDictionaryCommand)
data, err := dictionaryService.CreateDictionary(createDictionaryCommand)
controller.Response(data, err)
}
func (controller *DictionaryController) UpdateDictionary() {
dictionaryService := service.NewDictionaryService(nil)
updateDictionaryCommand := &command.UpdateDictionaryCommand{}
_ = controller.Unmarshal(updateDictionaryCommand)
dictionaryId, _ := controller.GetInt64(":dictionaryId")
updateDictionaryCommand.DictionaryId = dictionaryId
data, err := dictionaryService.UpdateDictionary(updateDictionaryCommand)
controller.Response(data, err)
}
func (controller *DictionaryController) GetDictionary() {
dictionaryService := service.NewDictionaryService(nil)
getDictionaryQuery := &query.GetDictionaryQuery{}
dictionaryId, _ := controller.GetInt64(":dictionaryId")
getDictionaryQuery.DictionaryId = dictionaryId
data, err := dictionaryService.GetDictionary(getDictionaryQuery)
controller.Response(data, err)
}
func (controller *DictionaryController) ListDictionary() {
dictionaryService := service.NewDictionaryService(nil)
listDictionaryQuery := &query.ListDictionaryQuery{}
_ = controller.Unmarshal(listDictionaryQuery)
count, listData, err := dictionaryService.ListDictionary(listDictionaryQuery)
controller.returnPageListData(count, listData, err, listDictionaryQuery.Pageindex)
}
func (controller *DictionaryController) GetDictionaryByCode() {
dictionaryService := service.NewDictionaryService(nil)
getDictionaryQuery := &query.GetDictionaryByCodeQuery{}
_ = controller.Unmarshal(getDictionaryQuery)
data, err := dictionaryService.GetDictionaryByCode(getDictionaryQuery)
controller.Response(data, err)
}