[WIP] update TribeFilter
This commit is contained in:
parent
689df42cd6
commit
13d33dd5b5
201
models/tribe.go
201
models/tribe.go
|
@ -1,6 +1,11 @@
|
|||
package models
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
"github.com/go-pg/pg/v10/orm"
|
||||
)
|
||||
|
||||
type Tribe struct {
|
||||
tableName struct{} `pg:"?SERVER.tribes,alias:tribe"`
|
||||
|
@ -27,13 +32,33 @@ type Tribe struct {
|
|||
OpponentsDefeated
|
||||
}
|
||||
|
||||
type TribeFilterOr struct {
|
||||
ID []int `json:"id" xml:"id" gqlgen:"id"`
|
||||
TagIEQ string `json:"tagIEQ" xml:"tagIEQ" gqlgen:"tagIEQ"`
|
||||
NameIEQ string `json:"nameIEQ" xml:"nameIEQ" gqlgen:"nameIEQ"`
|
||||
}
|
||||
|
||||
func (f *TribeFilterOr) WhereWithAlias(q *orm.Query, alias string) *orm.Query {
|
||||
q = q.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
|
||||
if !isZero(f.ID) {
|
||||
q = q.WhereOr(buildConditionArray(addAliasToColumnName("id", alias)), pg.Array(f.ID))
|
||||
}
|
||||
if !isZero(f.TagIEQ) {
|
||||
q = q.WhereOr(buildConditionIEQ(addAliasToColumnName("tag", alias)), f.TagIEQ)
|
||||
}
|
||||
if !isZero(f.NameIEQ) {
|
||||
q = q.WhereOr(buildConditionIEQ(addAliasToColumnName("name", alias)), f.NameIEQ)
|
||||
}
|
||||
return q, nil
|
||||
})
|
||||
return q
|
||||
}
|
||||
|
||||
type TribeFilter struct {
|
||||
tableName struct{} `urlstruct:"tribe"`
|
||||
|
||||
ID []int `json:"id" gqlgen:"id"`
|
||||
IdNEQ []int `json:"idNEQ" gqlgen:"idNEQ"`
|
||||
IDNEQ []int `json:"idNEQ" gqlgen:"idNEQ"`
|
||||
|
||||
Exists *bool `urlstruct:",nowhere" json:"exists" gqlgen:"exists"`
|
||||
Exists *bool `json:"exists" gqlgen:"exists"`
|
||||
|
||||
Tag []string `json:"tag" gqlgen:"tag"`
|
||||
TagNEQ []string `json:"tagNEQ" gqlgen:"tagNEQ"`
|
||||
|
@ -93,11 +118,169 @@ type TribeFilter struct {
|
|||
DeletedAtLT time.Time `json:"deletedAtLT" gqlgen:"deletedAtLT" xml:"deletedAtLT"`
|
||||
DeletedAtLTE time.Time `json:"deletedAtLTE" gqlgen:"deletedAtLTE" xml:"deletedAtLTE"`
|
||||
|
||||
Offset int `urlstruct:",nowhere" json:"offset" gqlgen:"offset"`
|
||||
Limit int `urlstruct:",nowhere" json:"limit" gqlgen:"limit"`
|
||||
Sort string `urlstruct:",nowhere" json:"sort" gqlgen:"sort"`
|
||||
|
||||
OpponentsDefeatedFilter
|
||||
Or *TribeFilterOr
|
||||
}
|
||||
|
||||
func (f *TribeFilter) WhereWithAlias(q *orm.Query, alias string) (*orm.Query, error) {
|
||||
if !isZero(f.ID) {
|
||||
q = q.Where(buildConditionArray(addAliasToColumnName("id", alias)), pg.Array(f.ID))
|
||||
}
|
||||
if !isZero(f.IDNEQ) {
|
||||
q = q.Where(buildConditionNotInArray(addAliasToColumnName("id", alias)), pg.Array(f.IDNEQ))
|
||||
}
|
||||
|
||||
if !isZero(f.Exists) {
|
||||
q = q.Where(buildConditionEquals(addAliasToColumnName("exists", alias)), f.Exists)
|
||||
}
|
||||
|
||||
if !isZero(f.Tag) {
|
||||
q = q.Where(buildConditionArray(addAliasToColumnName("tag", alias)), pg.Array(f.Tag))
|
||||
}
|
||||
if !isZero(f.TagNEQ) {
|
||||
q = q.Where(buildConditionNotInArray(addAliasToColumnName("tag", alias)), pg.Array(f.TagNEQ))
|
||||
}
|
||||
if !isZero(f.TagMATCH) {
|
||||
q = q.Where(buildConditionMatch(addAliasToColumnName("tag", alias)), f.TagMATCH)
|
||||
}
|
||||
if !isZero(f.TagIEQ) {
|
||||
q = q.Where(buildConditionIEQ(addAliasToColumnName("tag", alias)), f.TagIEQ)
|
||||
}
|
||||
|
||||
if !isZero(f.Name) {
|
||||
q = q.Where(buildConditionArray(addAliasToColumnName("name", alias)), pg.Array(f.Name))
|
||||
}
|
||||
if !isZero(f.NameNEQ) {
|
||||
q = q.Where(buildConditionNotInArray(addAliasToColumnName("name", alias)), pg.Array(f.NameNEQ))
|
||||
}
|
||||
if !isZero(f.NameMATCH) {
|
||||
q = q.Where(buildConditionMatch(addAliasToColumnName("name", alias)), f.NameMATCH)
|
||||
}
|
||||
if !isZero(f.NameIEQ) {
|
||||
q = q.Where(buildConditionIEQ(addAliasToColumnName("name", alias)), f.NameIEQ)
|
||||
}
|
||||
|
||||
if !isZero(f.TotalMembers) {
|
||||
q = q.Where(buildConditionEquals(addAliasToColumnName("total_members", alias)), f.TotalMembers)
|
||||
}
|
||||
if !isZero(f.TotalMembersGT) {
|
||||
q = q.Where(buildConditionGT(addAliasToColumnName("total_members", alias)), f.TotalMembersGT)
|
||||
}
|
||||
if !isZero(f.TotalMembersGTE) {
|
||||
q = q.Where(buildConditionGTE(addAliasToColumnName("total_members", alias)), f.TotalMembersGTE)
|
||||
}
|
||||
if !isZero(f.TotalMembersLT) {
|
||||
q = q.Where(buildConditionLT(addAliasToColumnName("total_members", alias)), f.TotalMembersLT)
|
||||
}
|
||||
if !isZero(f.TotalMembersLTE) {
|
||||
q = q.Where(buildConditionLTE(addAliasToColumnName("total_members", alias)), f.TotalMembersLTE)
|
||||
}
|
||||
|
||||
if !isZero(f.Points) {
|
||||
q = q.Where(buildConditionEquals(addAliasToColumnName("points", alias)), f.Points)
|
||||
}
|
||||
if !isZero(f.PointsGT) {
|
||||
q = q.Where(buildConditionGT(addAliasToColumnName("points", alias)), f.PointsGT)
|
||||
}
|
||||
if !isZero(f.PointsGTE) {
|
||||
q = q.Where(buildConditionGTE(addAliasToColumnName("points", alias)), f.PointsGTE)
|
||||
}
|
||||
if !isZero(f.PointsLT) {
|
||||
q = q.Where(buildConditionLT(addAliasToColumnName("points", alias)), f.PointsLT)
|
||||
}
|
||||
if !isZero(f.PointsLTE) {
|
||||
q = q.Where(buildConditionLTE(addAliasToColumnName("points", alias)), f.PointsLTE)
|
||||
}
|
||||
|
||||
if !isZero(f.AllPoints) {
|
||||
q = q.Where(buildConditionEquals(addAliasToColumnName("all_points", alias)), f.AllPoints)
|
||||
}
|
||||
if !isZero(f.AllPointsGT) {
|
||||
q = q.Where(buildConditionGT(addAliasToColumnName("all_points", alias)), f.AllPointsGT)
|
||||
}
|
||||
if !isZero(f.AllPointsGTE) {
|
||||
q = q.Where(buildConditionGTE(addAliasToColumnName("all_points", alias)), f.AllPointsGTE)
|
||||
}
|
||||
if !isZero(f.AllPointsLT) {
|
||||
q = q.Where(buildConditionLT(addAliasToColumnName("all_points", alias)), f.AllPointsLT)
|
||||
}
|
||||
if !isZero(f.AllPointsLTE) {
|
||||
q = q.Where(buildConditionLTE(addAliasToColumnName("all_points", alias)), f.AllPointsLTE)
|
||||
}
|
||||
|
||||
if !isZero(f.Rank) {
|
||||
q = q.Where(buildConditionEquals(addAliasToColumnName("rank", alias)), f.Rank)
|
||||
}
|
||||
if !isZero(f.RankGT) {
|
||||
q = q.Where(buildConditionGT(addAliasToColumnName("rank", alias)), f.RankGT)
|
||||
}
|
||||
if !isZero(f.RankGTE) {
|
||||
q = q.Where(buildConditionGTE(addAliasToColumnName("rank", alias)), f.RankGTE)
|
||||
}
|
||||
if !isZero(f.RankLT) {
|
||||
q = q.Where(buildConditionLT(addAliasToColumnName("rank", alias)), f.RankLT)
|
||||
}
|
||||
if !isZero(f.RankLTE) {
|
||||
q = q.Where(buildConditionLTE(addAliasToColumnName("rank", alias)), f.RankLTE)
|
||||
}
|
||||
|
||||
if !isZero(f.Dominance) {
|
||||
q = q.Where(buildConditionEquals(addAliasToColumnName("dominance", alias)), f.Dominance)
|
||||
}
|
||||
if !isZero(f.DominanceGT) {
|
||||
q = q.Where(buildConditionGT(addAliasToColumnName("dominance", alias)), f.DominanceGT)
|
||||
}
|
||||
if !isZero(f.DominanceGTE) {
|
||||
q = q.Where(buildConditionGTE(addAliasToColumnName("dominance", alias)), f.DominanceGTE)
|
||||
}
|
||||
if !isZero(f.DominanceLT) {
|
||||
q = q.Where(buildConditionLT(addAliasToColumnName("dominance", alias)), f.DominanceLT)
|
||||
}
|
||||
if !isZero(f.DominanceLTE) {
|
||||
q = q.Where(buildConditionLTE(addAliasToColumnName("dominance", alias)), f.DominanceLTE)
|
||||
}
|
||||
|
||||
if !isZero(f.CreatedAt) {
|
||||
q = q.Where(buildConditionEquals(addAliasToColumnName("created_at", alias)), f.CreatedAt)
|
||||
}
|
||||
if !isZero(f.CreatedAtGT) {
|
||||
q = q.Where(buildConditionGT(addAliasToColumnName("created_at", alias)), f.CreatedAtGT)
|
||||
}
|
||||
if !isZero(f.CreatedAtGTE) {
|
||||
q = q.Where(buildConditionGTE(addAliasToColumnName("created_at", alias)), f.CreatedAtGTE)
|
||||
}
|
||||
if !isZero(f.CreatedAtLT) {
|
||||
q = q.Where(buildConditionLT(addAliasToColumnName("created_at", alias)), f.CreatedAtLT)
|
||||
}
|
||||
if !isZero(f.CreatedAtLTE) {
|
||||
q = q.Where(buildConditionLTE(addAliasToColumnName("created_at", alias)), f.CreatedAtLTE)
|
||||
}
|
||||
|
||||
if !isZero(f.DeletedAt) {
|
||||
q = q.Where(buildConditionEquals(addAliasToColumnName("deleted_at", alias)), f.DeletedAt)
|
||||
}
|
||||
if !isZero(f.DeletedAtGT) {
|
||||
q = q.Where(buildConditionGT(addAliasToColumnName("deleted_at", alias)), f.DeletedAtGT)
|
||||
}
|
||||
if !isZero(f.DeletedAtGTE) {
|
||||
q = q.Where(buildConditionGTE(addAliasToColumnName("deleted_at", alias)), f.DeletedAtGTE)
|
||||
}
|
||||
if !isZero(f.DeletedAtLT) {
|
||||
q = q.Where(buildConditionLT(addAliasToColumnName("deleted_at", alias)), f.DeletedAtLT)
|
||||
}
|
||||
if !isZero(f.DeletedAtLTE) {
|
||||
q = q.Where(buildConditionLTE(addAliasToColumnName("deleted_at", alias)), f.DeletedAtLTE)
|
||||
}
|
||||
|
||||
if f.Or != nil {
|
||||
q = f.Or.WhereWithAlias(q, alias)
|
||||
}
|
||||
|
||||
return f.OpponentsDefeatedFilter.WhereWithAlias(q, alias)
|
||||
}
|
||||
|
||||
func (f *TribeFilter) Where(q *orm.Query) (*orm.Query, error) {
|
||||
return f.WhereWithAlias(q, "tribe")
|
||||
}
|
||||
|
||||
type FoundTribe struct {
|
||||
|
|
Reference in New Issue