2020-06-02 15:45:21 +00:00
|
|
|
package resolvers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-05 17:32:45 +00:00
|
|
|
"github.com/Kichiyaki/goutil/safeptr"
|
|
|
|
"github.com/tribalwarshelp/shared/tw/twmodel"
|
2020-06-19 17:50:23 +00:00
|
|
|
|
2020-06-18 14:44:02 +00:00
|
|
|
"github.com/tribalwarshelp/api/middleware"
|
2020-11-21 09:50:52 +00:00
|
|
|
"github.com/tribalwarshelp/api/server"
|
2020-06-18 14:44:02 +00:00
|
|
|
|
2020-06-02 15:45:21 +00:00
|
|
|
"github.com/tribalwarshelp/api/graphql/generated"
|
|
|
|
)
|
|
|
|
|
2021-05-05 17:32:45 +00:00
|
|
|
func (r *serverResolver) Version(ctx context.Context, obj *twmodel.Server) (*twmodel.Version, error) {
|
2021-05-10 21:15:55 +00:00
|
|
|
loaders := middleware.DataLoaderFromContext(ctx)
|
2020-06-18 14:44:02 +00:00
|
|
|
if loaders != nil {
|
2020-12-25 11:42:46 +00:00
|
|
|
lv, _ := loaders.VersionByCode.Load(obj.VersionCode.String())
|
2020-06-18 14:44:02 +00:00
|
|
|
return lv, nil
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2020-11-21 09:50:52 +00:00
|
|
|
func (r *queryResolver) Servers(ctx context.Context,
|
2021-05-05 17:32:45 +00:00
|
|
|
f *twmodel.ServerFilter,
|
2020-11-21 11:01:16 +00:00
|
|
|
limit *int,
|
2020-11-21 09:50:52 +00:00
|
|
|
offset *int,
|
|
|
|
sort []string) (*generated.ServerList, error) {
|
2020-06-02 15:45:21 +00:00
|
|
|
var err error
|
2020-06-28 11:55:37 +00:00
|
|
|
list := &generated.ServerList{}
|
2020-11-21 09:50:52 +00:00
|
|
|
list.Items, list.Total, err = r.ServerUcase.Fetch(ctx, server.FetchConfig{
|
|
|
|
Filter: f,
|
|
|
|
Sort: sort,
|
2021-05-05 17:32:45 +00:00
|
|
|
Limit: safeptr.SafeIntPointer(limit, 0),
|
|
|
|
Offset: safeptr.SafeIntPointer(offset, 0),
|
2020-12-25 11:13:12 +00:00
|
|
|
Count: shouldCount(ctx),
|
2021-03-21 12:03:39 +00:00
|
|
|
Select: shouldSelectItems(ctx),
|
2020-11-21 09:50:52 +00:00
|
|
|
})
|
2020-06-02 15:45:21 +00:00
|
|
|
return list, err
|
|
|
|
}
|
|
|
|
|
2021-05-05 17:32:45 +00:00
|
|
|
func (r *queryResolver) Server(ctx context.Context, key string) (*twmodel.Server, error) {
|
2020-06-02 15:45:21 +00:00
|
|
|
return r.ServerUcase.GetByKey(ctx, key)
|
|
|
|
}
|