-
Notifications
You must be signed in to change notification settings - Fork 13
/
list.go
108 lines (94 loc) · 2.75 KB
/
list.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package translation
import (
"context"
"github.com/latolukasz/beeorm"
listDto "github.com/coretrix/hitrix/pkg/dto/list"
"github.com/coretrix/hitrix/pkg/dto/translation"
"github.com/coretrix/hitrix/pkg/entity"
crudView "github.com/coretrix/hitrix/pkg/view/crud"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/crud"
)
const (
pageSizeMin = 10
pageSizeMax = 100
)
func columns() []*crud.Column {
return []*crud.Column{
{
Key: "ID",
FilterType: crud.InputTypeNumber,
Label: "ID",
Searchable: false,
Sortable: false,
Visible: true,
DataStringKeyStringValue: nil,
},
{
Key: "Status",
FilterType: crud.SelectTypeStringString,
Label: "Status",
Searchable: true,
Sortable: false,
Visible: true,
DataStringKeyStringValue: []*crud.StringKeyStringValue{
{Key: entity.TranslationStatusNew.String(), Label: entity.TranslationStatusNew.String()},
{Key: entity.TranslationStatusTranslated.String(), Label: entity.TranslationStatusTranslated.String()},
},
},
{
Key: "Lang",
FilterType: crud.InputTypeString,
Label: "Lang",
Searchable: true,
Sortable: false,
Visible: true,
},
{
Key: "Key",
FilterType: crud.InputTypeString,
Label: "Key",
Searchable: true,
Sortable: false,
Visible: true,
},
{
Key: "Text",
Label: "Text",
Searchable: false,
Sortable: false,
Visible: true,
},
}
}
func List(ctx context.Context, userListRequest listDto.RequestDTOList) (*translation.ResponseDTOList, error) {
request, err := crudView.ValidateListRequest(userListRequest, pageSizeMin, pageSizeMax)
if err != nil {
return nil, err
}
cols := columns()
crudService := service.DI().Crud()
searchParams := crudService.ExtractListParams(cols, request)
query := crudService.GenerateListMysqlQuery(searchParams)
if len(searchParams.Sort) == 0 {
query.Append("ORDER BY ID DESC")
}
ormService := service.DI().OrmEngineForContext(ctx)
var translationTextEntities []*entity.TranslationTextEntity
total := ormService.SearchWithCount(query, beeorm.NewPager(searchParams.Page, searchParams.PageSize), &translationTextEntities)
rows := make([]*translation.ListRow, len(translationTextEntities))
for i, translationTextEntity := range translationTextEntities {
rows[i] = &translation.ListRow{
ID: translationTextEntity.ID,
Status: translationTextEntity.Status,
Lang: translationTextEntity.Lang,
Key: translationTextEntity.Key,
Text: translationTextEntity.Text,
}
}
return &translation.ResponseDTOList{
Rows: rows,
Total: int(total),
Columns: cols,
}, nil
}