-
Notifications
You must be signed in to change notification settings - Fork 14
/
validate.go
40 lines (32 loc) · 965 Bytes
/
validate.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
package crud
import (
"errors"
"fmt"
"github.com/coretrix/hitrix/pkg/dto/list"
"github.com/coretrix/hitrix/service/component/crud"
)
func ValidateListRequest(request list.RequestDTOList, pageSizeMin, pageSizeMax int) (*crud.ListRequest, error) {
if request.Page == nil {
return nil, errors.New("page is empty")
}
if request.PageSize == nil {
return nil, errors.New("page size is empty")
}
if *request.Page < 1 {
return nil, errors.New("page must be greater than or equal to 1")
}
if *request.PageSize < pageSizeMin {
return nil, fmt.Errorf("page size must be greater than or equal to %v", pageSizeMin)
}
if *request.PageSize > pageSizeMax {
return nil, fmt.Errorf("page size must be greater than or equal to %v", pageSizeMax)
}
return &crud.ListRequest{
Page: request.Page,
PageSize: request.PageSize,
Filter: request.Filter,
Search: request.Search,
SearchOR: request.SearchOR,
Sort: request.Sort,
}, nil
}