2021-07-17 15:22:36 +00:00
|
|
|
package model
|
2020-06-26 18:30:25 +00:00
|
|
|
|
2020-10-17 10:43:27 +00:00
|
|
|
import (
|
2021-05-06 13:28:17 +00:00
|
|
|
"github.com/Kichiyaki/gopgutil/v10"
|
2020-10-17 10:43:27 +00:00
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
|
"github.com/go-pg/pg/v10/orm"
|
|
|
|
)
|
|
|
|
|
2020-06-26 18:30:25 +00:00
|
|
|
type Group struct {
|
|
|
|
ID int `pg:",pk" json:"id" gqlgen:"id"`
|
|
|
|
ConqueredVillagesChannelID string `pg:",use_zero" json:"conqueredVillagesChannelID" gqlgen:"conqueredVillagesChannelID"`
|
|
|
|
LostVillagesChannelID string `pg:",use_zero" json:"lostVillagesChannelID" gqlgen:"lostVillagesChannelID"`
|
2020-07-15 09:51:49 +00:00
|
|
|
ShowEnnobledBarbarians bool `pg:",use_zero"`
|
2020-07-27 15:54:51 +00:00
|
|
|
ShowInternals bool `pg:",use_zero"`
|
2020-07-19 14:21:32 +00:00
|
|
|
ServerID string `pg:"on_delete:CASCADE,use_zero" json:"serverID" gqlgen:"serverID"`
|
2020-10-17 10:43:27 +00:00
|
|
|
Server *Server `json:"server,omitempty" gqlgen:"server" pg:"rel:has-one"`
|
|
|
|
Observations Observations `json:"observation,omitempty" gqlgen:"observation" pg:"rel:has-many"`
|
2020-06-26 18:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type GroupFilter struct {
|
|
|
|
ID []int
|
|
|
|
ServerID []string
|
2020-10-17 10:43:27 +00:00
|
|
|
DefaultFilter
|
|
|
|
}
|
|
|
|
|
2021-05-06 13:28:17 +00:00
|
|
|
func (f *GroupFilter) ApplyWithAlias(q *orm.Query, prefix string) (*orm.Query, error) {
|
|
|
|
if len(f.ID) > 0 {
|
|
|
|
q = q.Where(gopgutil.BuildConditionArray("?"), gopgutil.AddAliasToColumnName("id", prefix), pg.Array(f.ID))
|
2020-10-17 10:43:27 +00:00
|
|
|
}
|
2021-05-06 13:28:17 +00:00
|
|
|
if len(f.ServerID) > 0 {
|
|
|
|
q = q.Where(gopgutil.BuildConditionArray("?"), gopgutil.AddAliasToColumnName("server_id", prefix), pg.Array(f.ServerID))
|
|
|
|
}
|
|
|
|
return f.DefaultFilter.Apply(q)
|
2020-10-17 10:43:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *GroupFilter) Apply(q *orm.Query) (*orm.Query, error) {
|
2021-05-06 13:28:17 +00:00
|
|
|
return f.ApplyWithAlias(q, "group")
|
2020-06-26 18:30:25 +00:00
|
|
|
}
|