2021-07-17 15:22:36 +00:00
|
|
|
package model
|
2020-05-30 08:35:45 +00:00
|
|
|
|
2020-10-17 10:43:27 +00:00
|
|
|
import (
|
2021-05-06 12:55:51 +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-05-30 08:35:45 +00:00
|
|
|
type Server struct {
|
2020-06-26 07:47:33 +00:00
|
|
|
tableName struct{} `pg:",alias:server"`
|
|
|
|
|
2020-10-17 10:43:27 +00:00
|
|
|
ID string `pg:",pk" json:"id" gqlgen:"id"`
|
|
|
|
Lang string `pg:",use_zero"`
|
|
|
|
CoordsTranslation string `pg:",use_zero"`
|
|
|
|
Groups []*Group `pg:"rel:has-many"`
|
2020-05-30 08:35:45 +00:00
|
|
|
}
|
2020-08-09 15:20:23 +00:00
|
|
|
|
2020-05-30 08:35:45 +00:00
|
|
|
type ServerFilter struct {
|
2020-10-17 10:43:27 +00:00
|
|
|
ID []string
|
|
|
|
DefaultFilter
|
|
|
|
}
|
|
|
|
|
2021-05-06 13:28:17 +00:00
|
|
|
func (f *ServerFilter) ApplyWithAlias(q *orm.Query, alias string) (*orm.Query, error) {
|
2021-05-06 12:55:51 +00:00
|
|
|
if len(f.ID) > 0 {
|
|
|
|
q = q.Where(gopgutil.BuildConditionArray("?"), gopgutil.AddAliasToColumnName("id", alias), pg.Array(f.ID))
|
2020-10-17 10:43:27 +00:00
|
|
|
}
|
2021-05-06 12:55:51 +00:00
|
|
|
return f.DefaultFilter.Apply(q)
|
2020-10-17 10:43:27 +00:00
|
|
|
}
|
2020-07-19 14:21:32 +00:00
|
|
|
|
2020-10-17 10:43:27 +00:00
|
|
|
func (f *ServerFilter) Apply(q *orm.Query) (*orm.Query, error) {
|
2021-05-06 13:28:17 +00:00
|
|
|
return f.ApplyWithAlias(q, "server")
|
2020-05-30 08:35:45 +00:00
|
|
|
}
|