-
Notifications
You must be signed in to change notification settings - Fork 2
/
convert.go
75 lines (69 loc) · 1.33 KB
/
convert.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
package gqlmodel
import (
"io"
"github.com/99designs/gqlgen/graphql"
"github.com/reearth/reearth-cms/server/pkg/file"
"github.com/reearth/reearthx/usecasex"
"github.com/samber/lo"
)
func ToPageInfo(p *usecasex.PageInfo) *PageInfo {
if p == nil {
return &PageInfo{}
}
return &PageInfo{
StartCursor: p.StartCursor,
EndCursor: p.EndCursor,
HasNextPage: p.HasNextPage,
HasPreviousPage: p.HasPreviousPage,
}
}
func (p *Pagination) Into() *usecasex.Pagination {
if p == nil {
return nil
}
if p.Offset != nil {
var limit int64 = 50
if p.First != nil {
limit = int64(*p.First)
}
if limit > 100 {
limit = 100
}
return usecasex.OffsetPagination{
Offset: int64(*p.Offset),
Limit: limit,
}.Wrap()
}
return usecasex.CursorPagination{
Before: p.Before,
After: p.After,
First: pint2pint64(p.First),
Last: pint2pint64(p.Last),
}.Wrap()
}
func (s *Sort) Into() *usecasex.Sort {
if s == nil {
return nil
}
return &usecasex.Sort{
Key: s.Key,
Reverted: *s.Reverted,
}
}
func FromFile(f *graphql.Upload) *file.File {
if f == nil {
return nil
}
return &file.File{
Content: io.NopCloser(f.File),
Name: f.Filename,
Size: f.Size,
ContentType: f.ContentType,
}
}
func pint2pint64(i *int) *int64 {
if i == nil {
return nil
}
return lo.ToPtr(int64(*i))
}