-
Notifications
You must be signed in to change notification settings - Fork 8
/
feedsqueryresolver.go
50 lines (45 loc) · 1.03 KB
/
feedsqueryresolver.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
package schema
import (
"context"
"github.com/firstcontributions/backend/internal/models/storiesstore"
"github.com/firstcontributions/backend/internal/storemanager"
)
type FeedsInput struct {
First *int32
Last *int32
After *string
Before *string
SortOrder *string
SortBy *string
}
func (r *Resolver) Feeds(ctx context.Context, in *FeedsInput) (*StoriesConnection, error) {
var first, last *int64
if in.First != nil {
tmp := int64(*in.First)
first = &tmp
}
if in.Last != nil {
tmp := int64(*in.Last)
last = &tmp
}
store := storemanager.FromContext(ctx)
filters := &storiesstore.StoryFilters{}
sortByStr := ""
if in.SortBy != nil {
sortByStr = *in.SortBy
}
data, hasNextPage, hasPreviousPage, cursors, err := store.StoriesStore.GetStories(
ctx,
filters,
in.After,
in.Before,
first,
last,
storiesstore.GetStorySortByFromString(sortByStr),
in.SortOrder,
)
if err != nil {
return nil, err
}
return NewStoriesConnection(filters, data, hasNextPage, hasPreviousPage, cursors), nil
}