add opportunity to filter villages by XY
This commit is contained in:
parent
73390475fc
commit
b08a067537
2
go.mod
2
go.mod
|
@ -16,7 +16,7 @@ require (
|
|||
github.com/pkg/errors v0.9.1
|
||||
github.com/segmentio/encoding v0.1.14 // indirect
|
||||
github.com/tribalwarshelp/map-generator v0.0.0-20200801113621-fb8892ceb243
|
||||
github.com/tribalwarshelp/shared v0.0.0-20200728103702-87e7e5f1b8fd
|
||||
github.com/tribalwarshelp/shared v0.0.0-20200809125423-2bc2e8dfde95
|
||||
github.com/vektah/gqlparser/v2 v2.0.1
|
||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
|
||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
|
||||
|
|
3
go.sum
3
go.sum
|
@ -193,6 +193,8 @@ github.com/tribalwarshelp/shared v0.0.0-20200622084436-3a768c8bf574 h1:y2EoH6zRK
|
|||
github.com/tribalwarshelp/shared v0.0.0-20200622084436-3a768c8bf574/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
|
||||
github.com/tribalwarshelp/shared v0.0.0-20200728103702-87e7e5f1b8fd h1:AHGZw26jj2uPgFRPLRouFjJJV97Y/p9zLgSW79ZdcVk=
|
||||
github.com/tribalwarshelp/shared v0.0.0-20200728103702-87e7e5f1b8fd/go.mod h1:SSWchTkQdgeIDr0C68C7zopEIcBLCUa8Ic2CHenUaac=
|
||||
github.com/tribalwarshelp/shared v0.0.0-20200809125423-2bc2e8dfde95 h1:mO3ZR+o5UlYN8uGX4L32H5HNpB0uHpLdZ3YiDA6ciW4=
|
||||
github.com/tribalwarshelp/shared v0.0.0-20200809125423-2bc2e8dfde95/go.mod h1:SSWchTkQdgeIDr0C68C7zopEIcBLCUa8Ic2CHenUaac=
|
||||
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
||||
|
@ -298,6 +300,7 @@ golang.org/x/tools v0.0.0-20190515012406-7d7faa4812bd/go.mod h1:RgjU9mgBXZiqYHBn
|
|||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20200114235610-7ae403b6b589 h1:rjUrONFu4kLchcZTfp3/96bR8bW8dIa8uz3cR5n0cgM=
|
||||
golang.org/x/tools v0.0.0-20200114235610-7ae403b6b589/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa h1:5E4dL8+NgFOgjwbTKz+OOEGGhP+ectTmF842l6KjupQ=
|
||||
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
|
|
|
@ -4217,6 +4217,7 @@ input VillageFilter {
|
|||
yGTE: Int
|
||||
yLT: Int
|
||||
yLTE: Int
|
||||
xy: [String!]
|
||||
|
||||
bonus: Int
|
||||
bonusGT: Int
|
||||
|
@ -19819,6 +19820,12 @@ func (ec *executionContext) unmarshalInputVillageFilter(ctx context.Context, obj
|
|||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
case "xy":
|
||||
var err error
|
||||
it.XY, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
case "bonus":
|
||||
var err error
|
||||
it.Bonus, err = ec.unmarshalOInt2int(ctx, v)
|
||||
|
|
|
@ -36,6 +36,7 @@ input VillageFilter {
|
|||
yGTE: Int
|
||||
yLT: Int
|
||||
yLTE: Int
|
||||
xy: [String!]
|
||||
|
||||
bonus: Int
|
||||
bonusGT: Int
|
||||
|
|
5
main.go
5
main.go
|
@ -51,6 +51,7 @@ import (
|
|||
villageucase "github.com/tribalwarshelp/api/village/usecase"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
"github.com/go-pg/pg/v10/pgext"
|
||||
"github.com/joho/godotenv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -76,7 +77,9 @@ func main() {
|
|||
log.Fatal("Database disconnecting:", err)
|
||||
}
|
||||
}()
|
||||
// db.AddQueryHook(pgext.DebugHook{})
|
||||
if strings.ToUpper(os.Getenv("LOG_DB_QUERIES")) == "TRUE" {
|
||||
db.AddQueryHook(pgext.DebugHook{})
|
||||
}
|
||||
|
||||
redisClient := redis.NewClient(&redis.Options{
|
||||
Addr: os.Getenv("REDIS_HOST") + ":" + os.Getenv("REDIS_PORT"),
|
||||
|
|
|
@ -3,9 +3,11 @@ package repository
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tribalwarshelp/api/village"
|
||||
"github.com/tribalwarshelp/shared/models"
|
||||
|
@ -52,6 +54,31 @@ func (repo *pgRepository) Fetch(ctx context.Context, cfg village.FetchConfig) ([
|
|||
query = query.Where("y < ?", cfg.Filter.YLT)
|
||||
}
|
||||
|
||||
if len(cfg.Filter.XY) > 0 {
|
||||
query = query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
|
||||
for _, xy := range cfg.Filter.XY {
|
||||
splitted := strings.Split(xy, "|")
|
||||
if len(splitted) != 2 {
|
||||
continue
|
||||
}
|
||||
x, err := strconv.Atoi(splitted[0])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
y, err := strconv.Atoi(splitted[1])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
q = q.WhereOrGroup(func(q *orm.Query) (*orm.Query, error) {
|
||||
q = q.Where("x = ?", x)
|
||||
q = q.Where("y = ?", y)
|
||||
return q, nil
|
||||
})
|
||||
}
|
||||
return q, nil
|
||||
})
|
||||
}
|
||||
|
||||
order := []string{}
|
||||
|
||||
if cfg.Filter.Sort != "" {
|
||||
|
|
Reference in New Issue