This repository has been archived on 2022-10-02. You can view files and clone it, but cannot push or open issues or pull requests.
dcbot-old/model/group.go

39 lines
1.5 KiB
Go
Raw Normal View History

package model
2020-06-26 18:30:25 +00:00
2020-10-17 10:43:27 +00:00
import (
"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"`
ShowEnnobledBarbarians bool `pg:",use_zero"`
ShowInternals bool `pg:",use_zero"`
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
}
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
}
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) {
return f.ApplyWithAlias(q, "group")
2020-06-26 18:30:25 +00:00
}