move safeStrPointer and safeIntPointer from the resolvers package to the utils package
This commit is contained in:
parent
1f3450cfca
commit
8d4ce284f5
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tribalwarshelp/api/utils"
|
||||
|
||||
"github.com/tribalwarshelp/api/dailyplayerstats"
|
||||
"github.com/tribalwarshelp/api/graphql/generated"
|
||||
|
@ -28,8 +29,8 @@ func (r *queryResolver) DailyPlayerStats(ctx context.Context,
|
|||
Server: server,
|
||||
Filter: filter,
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Count: shouldCount(ctx),
|
||||
})
|
||||
return list, err
|
||||
|
|
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tribalwarshelp/api/utils"
|
||||
|
||||
"github.com/tribalwarshelp/api/dailytribestats"
|
||||
"github.com/tribalwarshelp/api/graphql/generated"
|
||||
|
@ -28,8 +29,8 @@ func (r *queryResolver) DailyTribeStats(ctx context.Context,
|
|||
Server: server,
|
||||
Filter: filter,
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Count: shouldCount(ctx),
|
||||
})
|
||||
return list, err
|
||||
|
|
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tribalwarshelp/api/utils"
|
||||
|
||||
"github.com/tribalwarshelp/api/ennoblement"
|
||||
"github.com/tribalwarshelp/api/graphql/generated"
|
||||
|
@ -59,8 +60,8 @@ func (r *queryResolver) Ennoblements(ctx context.Context, server string,
|
|||
Server: server,
|
||||
Filter: f,
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Count: shouldCount(ctx),
|
||||
})
|
||||
return list, err
|
||||
|
|
|
@ -75,17 +75,3 @@ func shouldCount(ctx context.Context) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func safeStrPointer(s *string, def string) string {
|
||||
if s == nil {
|
||||
return def
|
||||
}
|
||||
return *s
|
||||
}
|
||||
|
||||
func safeIntPointer(s *int, def int) int {
|
||||
if s == nil {
|
||||
return def
|
||||
}
|
||||
return *s
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tribalwarshelp/api/utils"
|
||||
|
||||
"github.com/tribalwarshelp/api/graphql/generated"
|
||||
"github.com/tribalwarshelp/api/middleware"
|
||||
|
@ -58,8 +59,8 @@ func (r *queryResolver) Players(ctx context.Context,
|
|||
Server: server,
|
||||
Filter: f,
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Count: shouldCount(ctx),
|
||||
})
|
||||
return list, err
|
||||
|
@ -80,11 +81,11 @@ func (r *queryResolver) SearchPlayer(ctx context.Context,
|
|||
list := &generated.FoundPlayerList{}
|
||||
list.Items, list.Total, err = r.PlayerUcase.SearchPlayer(ctx, player.SearchPlayerConfig{
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Version: version,
|
||||
Name: safeStrPointer(name, ""),
|
||||
ID: safeIntPointer(id, 0),
|
||||
Name: utils.SafeStrPointer(name, ""),
|
||||
ID: utils.SafeIntPointer(id, 0),
|
||||
Count: shouldCount(ctx),
|
||||
})
|
||||
return list, err
|
||||
|
|
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tribalwarshelp/api/utils"
|
||||
|
||||
"github.com/tribalwarshelp/api/graphql/generated"
|
||||
"github.com/tribalwarshelp/api/playerhistory"
|
||||
|
@ -36,8 +37,8 @@ func (r *Resolver) PlayerHistory(ctx context.Context,
|
|||
Server: server,
|
||||
Filter: f,
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Count: shouldCount(ctx),
|
||||
})
|
||||
return list, err
|
||||
|
|
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tribalwarshelp/api/utils"
|
||||
|
||||
"github.com/tribalwarshelp/api/middleware"
|
||||
"github.com/tribalwarshelp/api/server"
|
||||
|
@ -29,8 +30,8 @@ func (r *queryResolver) Servers(ctx context.Context,
|
|||
list.Items, list.Total, err = r.ServerUcase.Fetch(ctx, server.FetchConfig{
|
||||
Filter: f,
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Count: shouldCount(ctx),
|
||||
})
|
||||
return list, err
|
||||
|
|
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tribalwarshelp/api/utils"
|
||||
|
||||
"github.com/tribalwarshelp/api/graphql/generated"
|
||||
"github.com/tribalwarshelp/api/serverstats"
|
||||
|
@ -20,8 +21,8 @@ func (r *Resolver) ServerStats(ctx context.Context,
|
|||
Server: server,
|
||||
Filter: f,
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Count: shouldCount(ctx),
|
||||
})
|
||||
return list, err
|
||||
|
|
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tribalwarshelp/api/utils"
|
||||
|
||||
"github.com/tribalwarshelp/api/graphql/generated"
|
||||
"github.com/tribalwarshelp/api/tribe"
|
||||
|
@ -20,8 +21,8 @@ func (r *queryResolver) Tribes(ctx context.Context,
|
|||
Server: server,
|
||||
Filter: f,
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Count: shouldCount(ctx),
|
||||
})
|
||||
return list, err
|
||||
|
@ -41,8 +42,8 @@ func (r *queryResolver) SearchTribe(ctx context.Context,
|
|||
list := &generated.FoundTribeList{}
|
||||
list.Items, list.Total, err = r.TribeUcase.SearchTribe(ctx, tribe.SearchTribeConfig{
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Version: version,
|
||||
Query: query,
|
||||
Count: shouldCount(ctx),
|
||||
|
|
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tribalwarshelp/api/utils"
|
||||
|
||||
"github.com/tribalwarshelp/api/graphql/generated"
|
||||
"github.com/tribalwarshelp/api/tribechange"
|
||||
|
@ -43,8 +44,8 @@ func (r *Resolver) TribeChanges(ctx context.Context,
|
|||
list.Items, list.Total, err = r.TribeChangeUcase.Fetch(ctx, tribechange.FetchConfig{
|
||||
Filter: f,
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Count: shouldCount(ctx),
|
||||
Server: server,
|
||||
})
|
||||
|
|
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tribalwarshelp/api/utils"
|
||||
|
||||
"github.com/tribalwarshelp/api/graphql/generated"
|
||||
"github.com/tribalwarshelp/api/tribehistory"
|
||||
|
@ -27,8 +28,8 @@ func (r *Resolver) TribeHistory(ctx context.Context,
|
|||
list.Items, list.Total, err = r.TribeHistoryUcase.Fetch(ctx, tribehistory.FetchConfig{
|
||||
Filter: f,
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Count: shouldCount(ctx),
|
||||
Server: server,
|
||||
})
|
||||
|
|
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tribalwarshelp/api/utils"
|
||||
|
||||
"github.com/tribalwarshelp/api/graphql/generated"
|
||||
"github.com/tribalwarshelp/api/version"
|
||||
|
@ -18,8 +19,8 @@ func (r *queryResolver) Versions(ctx context.Context,
|
|||
list.Items, list.Total, err = r.VersionUcase.Fetch(ctx, version.FetchConfig{
|
||||
Filter: f,
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Count: shouldCount(ctx),
|
||||
})
|
||||
return list, err
|
||||
|
|
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tribalwarshelp/api/utils"
|
||||
|
||||
"github.com/tribalwarshelp/api/graphql/generated"
|
||||
"github.com/tribalwarshelp/api/village"
|
||||
|
@ -27,8 +28,8 @@ func (r *queryResolver) Villages(ctx context.Context,
|
|||
list.Items, list.Total, err = r.VillageUcase.Fetch(ctx, village.FetchConfig{
|
||||
Filter: f,
|
||||
Sort: sort,
|
||||
Limit: safeIntPointer(limit, 0),
|
||||
Offset: safeIntPointer(offset, 0),
|
||||
Limit: utils.SafeIntPointer(limit, 0),
|
||||
Offset: utils.SafeIntPointer(offset, 0),
|
||||
Count: shouldCount(ctx),
|
||||
Server: server,
|
||||
})
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package utils
|
||||
|
||||
func SafeBoolPointer(value *bool, defaultValue bool) bool {
|
||||
if value == nil {
|
||||
return defaultValue
|
||||
}
|
||||
return *value
|
||||
}
|
||||
|
||||
func SafeIntPointer(value *int, defaultValue int) int {
|
||||
if value == nil {
|
||||
return defaultValue
|
||||
}
|
||||
return *value
|
||||
}
|
||||
|
||||
func SafeStrPointer(value *string, defaultValue string) string {
|
||||
if value == nil {
|
||||
return defaultValue
|
||||
}
|
||||
return *value
|
||||
}
|
Reference in New Issue