Dawid Wysokiński
a8f309c299
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #114
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package bunmodel
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gitea.dwysokinski.me/twhelp/dcbot/internal/domain"
|
|
"github.com/google/uuid"
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
type Group struct {
|
|
bun.BaseModel `bun:"base_model,table:groups,alias:group"`
|
|
|
|
ID uuid.UUID `bun:"id,pk,nullzero"`
|
|
ServerID string `bun:"server_id,nullzero"`
|
|
ChannelGains string `bun:"channel_gains,nullzero"`
|
|
ChannelLosses string `bun:"channel_losses,nullzero"`
|
|
Internals bool `bun:"internals"`
|
|
Barbarians bool `bun:"barbarians"`
|
|
ServerKey string `bun:"server_key,nullzero"`
|
|
VersionCode string `bun:"version_code,nullzero"`
|
|
LanguageTag string `bun:"language_tag,nullzero"`
|
|
CreatedAt time.Time `bun:"created_at,nullzero"`
|
|
Monitors []Monitor `bun:"monitors,rel:has-many,join:id=group_id"`
|
|
}
|
|
|
|
func (g Group) ToDomain() domain.GroupWithMonitors {
|
|
monitors := make([]domain.Monitor, 0, len(g.Monitors))
|
|
for _, m := range g.Monitors {
|
|
monitors = append(monitors, m.ToDomain())
|
|
}
|
|
return domain.GroupWithMonitors{
|
|
Group: domain.Group{
|
|
ID: g.ID.String(),
|
|
ServerID: g.ServerID,
|
|
ChannelGains: g.ChannelGains,
|
|
ChannelLosses: g.ChannelLosses,
|
|
Internals: g.Internals,
|
|
Barbarians: g.Barbarians,
|
|
ServerKey: g.ServerKey,
|
|
VersionCode: g.VersionCode,
|
|
LanguageTag: g.LanguageTag,
|
|
CreatedAt: g.CreatedAt,
|
|
},
|
|
Monitors: monitors,
|
|
}
|
|
}
|