rename the models package -> model, return normal types instead of interfaces (repositories)

pull/31/head
Dawid Wysokiński 2 years ago
parent 241538a83f
commit b4b3379765

@ -3,7 +3,7 @@ package cron
import (
"github.com/tribalwarshelp/shared/tw/twmodel"
"github.com/tribalwarshelp/dcbot/tw/twutil"
"github.com/tribalwarshelp/dcbot/util/twutil"
)
type ennoblements []*twmodel.Ennoblement

@ -12,13 +12,13 @@ import (
"github.com/pkg/errors"
"github.com/tribalwarshelp/dcbot/message"
"github.com/tribalwarshelp/dcbot/tw/twutil"
"github.com/tribalwarshelp/dcbot/util/twutil"
"github.com/tribalwarshelp/golang-sdk/sdk"
"github.com/tribalwarshelp/dcbot/discord"
"github.com/tribalwarshelp/dcbot/group"
"github.com/tribalwarshelp/dcbot/models"
"github.com/tribalwarshelp/dcbot/model"
"github.com/tribalwarshelp/dcbot/observation"
"github.com/tribalwarshelp/dcbot/server"
)
@ -259,7 +259,7 @@ func (h *handler) checkBotServers() {
}
if len(idsToDelete) > 0 {
deleted, err := h.serverRepo.Delete(context.Background(), &models.ServerFilter{
deleted, err := h.serverRepo.Delete(context.Background(), &model.ServerFilter{
ID: idsToDelete,
})
if err != nil {
@ -300,7 +300,7 @@ func (h *handler) deleteClosedTWServers() {
}
if len(keys) > 0 {
deleted, err := h.observationRepo.Delete(context.Background(), &models.ObservationFilter{
deleted, err := h.observationRepo.Delete(context.Background(), &model.ObservationFilter{
Server: keys,
})
if err != nil {

@ -5,7 +5,7 @@ import (
"github.com/tribalwarshelp/shared/tw/twmodel"
"time"
"github.com/tribalwarshelp/dcbot/tw/twutil"
"github.com/tribalwarshelp/dcbot/util/twutil"
)
func isBarbarian(p *twmodel.Player) bool {

@ -7,7 +7,7 @@ import (
"github.com/tribalwarshelp/dcbot/discord"
"github.com/tribalwarshelp/dcbot/message"
"github.com/tribalwarshelp/dcbot/tw/twutil"
"github.com/tribalwarshelp/dcbot/util/twutil"
)
type messageType string

@ -3,7 +3,8 @@ package discord
import (
"github.com/bwmarrin/discordgo"
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/tribalwarshelp/dcbot/models"
"github.com/tribalwarshelp/dcbot/model"
)
type Command string
@ -17,7 +18,7 @@ func (cmd Command) WithPrefix(prefix string) Command {
}
type commandCtx struct {
server *models.Server
server *model.Server
localizer *i18n.Localizer
}

@ -11,7 +11,7 @@ import (
"github.com/tribalwarshelp/golang-sdk/sdk"
"github.com/tribalwarshelp/dcbot/message"
"github.com/tribalwarshelp/dcbot/tw/twutil"
"github.com/tribalwarshelp/dcbot/util/twutil"
)
const (

@ -12,7 +12,7 @@ import (
"github.com/tribalwarshelp/golang-sdk/sdk"
"github.com/tribalwarshelp/dcbot/group"
"github.com/tribalwarshelp/dcbot/models"
"github.com/tribalwarshelp/dcbot/model"
"github.com/tribalwarshelp/dcbot/observation"
"github.com/tribalwarshelp/dcbot/server"
@ -233,7 +233,7 @@ func (s *Session) handleNewMessage(_ *discordgo.Session, m *discordgo.MessageCre
parts := strings.Split(m.Content, " ")
args := parts[1:]
svr := &models.Server{
svr := &model.Server{
ID: m.GuildID,
Lang: message.GetDefaultLanguage().String(),
}

@ -14,8 +14,8 @@ import (
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/tribalwarshelp/dcbot/message"
"github.com/tribalwarshelp/dcbot/models"
"github.com/tribalwarshelp/dcbot/tw/twutil"
"github.com/tribalwarshelp/dcbot/model"
"github.com/tribalwarshelp/dcbot/util/twutil"
)
const (
@ -55,7 +55,7 @@ func (s *Session) handleAddGroupCommand(ctx *commandCtx, m *discordgo.MessageCre
return
}
group := &models.Group{
group := &model.Group{
ServerID: m.GuildID,
ShowEnnobledBarbarians: true,
}
@ -115,7 +115,7 @@ func (s *Session) handleDeleteGroupCommand(ctx *commandCtx, m *discordgo.Message
return
}
go s.cfg.GroupRepository.Delete(context.Background(), &models.GroupFilter{
go s.cfg.GroupRepository.Delete(context.Background(), &model.GroupFilter{
ID: []int{groupID},
ServerID: []string{m.GuildID},
})
@ -132,9 +132,9 @@ func (s *Session) handleDeleteGroupCommand(ctx *commandCtx, m *discordgo.Message
}
func (s *Session) handleGroupsCommand(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
groups, _, err := s.cfg.GroupRepository.Fetch(context.Background(), &models.GroupFilter{
groups, _, err := s.cfg.GroupRepository.Fetch(context.Background(), &model.GroupFilter{
ServerID: []string{m.GuildID},
DefaultFilter: models.DefaultFilter{
DefaultFilter: model.DefaultFilter{
Order: []string{"id ASC"},
},
})
@ -204,7 +204,7 @@ func (s *Session) handleConqueredVillagesCommand(ctx *commandCtx, m *discordgo.M
return
}
groups, _, err := s.cfg.GroupRepository.Fetch(context.Background(), &models.GroupFilter{
groups, _, err := s.cfg.GroupRepository.Fetch(context.Background(), &model.GroupFilter{
ID: []int{groupID},
ServerID: []string{m.GuildID},
})
@ -264,7 +264,7 @@ func (s *Session) handleDisableConqueredVillagesCommand(ctx *commandCtx, m *disc
return
}
groups, _, err := s.cfg.GroupRepository.Fetch(context.Background(), &models.GroupFilter{
groups, _, err := s.cfg.GroupRepository.Fetch(context.Background(), &model.GroupFilter{
ID: []int{groupID},
ServerID: []string{m.GuildID},
})
@ -326,7 +326,7 @@ func (s *Session) handleLostVillagesCommand(ctx *commandCtx, m *discordgo.Messag
return
}
groups, _, err := s.cfg.GroupRepository.Fetch(context.Background(), &models.GroupFilter{
groups, _, err := s.cfg.GroupRepository.Fetch(context.Background(), &model.GroupFilter{
ID: []int{groupID},
ServerID: []string{m.GuildID},
})
@ -387,7 +387,7 @@ func (s *Session) handleDisableLostVillagesCommand(ctx *commandCtx, m *discordgo
return
}
groups, _, err := s.cfg.GroupRepository.Fetch(context.Background(), &models.GroupFilter{
groups, _, err := s.cfg.GroupRepository.Fetch(context.Background(), &model.GroupFilter{
ID: []int{groupID},
ServerID: []string{m.GuildID},
})
@ -541,7 +541,7 @@ func (s *Session) handleObserveCommand(ctx *commandCtx, m *discordgo.MessageCrea
return
}
go s.cfg.ObservationRepository.Store(context.Background(), &models.Observation{
go s.cfg.ObservationRepository.Store(context.Background(), &model.Observation{
Server: server.Key,
TribeID: tribe.ID,
GroupID: groupID,
@ -613,7 +613,7 @@ func (s *Session) handleDeleteObservationCommand(ctx *commandCtx, m *discordgo.M
return
}
go s.cfg.ObservationRepository.Delete(context.Background(), &models.ObservationFilter{
go s.cfg.ObservationRepository.Delete(context.Background(), &model.ObservationFilter{
GroupID: []int{groupID},
ID: []int{observationID},
})
@ -668,9 +668,9 @@ func (s *Session) handleObservationsCommand(ctx *commandCtx, m *discordgo.Messag
}))
return
}
observations, _, err := s.cfg.ObservationRepository.Fetch(context.Background(), &models.ObservationFilter{
observations, _, err := s.cfg.ObservationRepository.Fetch(context.Background(), &model.ObservationFilter{
GroupID: []int{groupID},
DefaultFilter: models.DefaultFilter{
DefaultFilter: model.DefaultFilter{
Order: []string{"id ASC"},
},
})

@ -17,6 +17,5 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/tribalwarshelp/golang-sdk v0.0.0-20210717112029-bb518cbee33d
github.com/tribalwarshelp/shared v0.0.0-20210717094429-6efa1a4f614c
go.opentelemetry.io/otel v0.20.0 // indirect
golang.org/x/text v0.3.6
)

@ -7,7 +7,6 @@ github.com/Kichiyaki/appmode v0.0.0-20210502105643-0a26207c548d/go.mod h1:41p1KT
github.com/Kichiyaki/go-pg-logrus-query-logger/v10 v10.0.0-20210428180109-fb97298564d9 h1:S/08K0AD4bXYeSPJKei8ZbumDy1JNARZsgYbNZgr9Tk=
github.com/Kichiyaki/go-pg-logrus-query-logger/v10 v10.0.0-20210428180109-fb97298564d9/go.mod h1:ADHVWnGlWcRn1aGthuh7I1Lrn6zzsjkVJju151dXyDw=
github.com/Kichiyaki/go-php-serialize v0.0.0-20200601110855-47b6982acf83/go.mod h1:+iGkf5HfOVeRVd9K7qQDucIl+/Kt3MyenMa90b/O/c4=
github.com/Kichiyaki/gopgutil/v10 v10.0.0-20210505093434-655fa2df248f/go.mod h1:MSAEhr8oeK+Rhjhqyl31/8/AI88thYky80OyD8mheDA=
github.com/Kichiyaki/gopgutil/v10 v10.0.0-20210521204542-cc672e361b3d h1:7ZJVfFgAR0zNf5fNc6M9v2PZbXvTgGgDjQo4/+NIezQ=
github.com/Kichiyaki/gopgutil/v10 v10.0.0-20210521204542-cc672e361b3d/go.mod h1:MSAEhr8oeK+Rhjhqyl31/8/AI88thYky80OyD8mheDA=
github.com/Kichiyaki/goutil v0.0.0-20210502095630-318d17091eab/go.mod h1:+HhI932Xb0xrCodNcCv5GPiCjLYhDxWhCtlEqMIJhB4=
@ -29,10 +28,7 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-pg/pg/v10 v10.9.1 h1:kU4t84zWGGaU0Qsu49FbNtToUVrlSTkNOngW8aQmwvk=
github.com/go-pg/pg/v10 v10.9.1/go.mod h1:rgmTPgHgl5EN2CNKKoMwC7QT62t8BqsdpEkUQuiZMQs=
github.com/go-pg/pg/v10 v10.10.1 h1:82lLX4KGs2wOFOvVVIICoU0Si1fLu6Aitniu73HaDuM=
github.com/go-pg/pg/v10 v10.10.1/go.mod h1:EmoJGYErc+stNN/1Jf+o4csXuprjxcRztBnn6cHe38E=
github.com/go-pg/pg/v10 v10.10.2 h1:8G2DdKrB3/0nRIlpur0HySEWBJnHYUByiC0ko4XzE8w=
github.com/go-pg/pg/v10 v10.10.2/go.mod h1:EmoJGYErc+stNN/1Jf+o4csXuprjxcRztBnn6cHe38E=
github.com/go-pg/zerochecker v0.2.0 h1:pp7f72c3DobMWOb2ErtZsnrPaSvHd2W4o9//8HtF4mU=
@ -54,7 +50,6 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
@ -100,27 +95,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo=
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=
github.com/tribalwarshelp/golang-sdk v0.0.0-20210505172651-7dc458534a8c h1:Ip4C8G6zjdHnsHeyuajb5BZeRrls/Ym14Vww8e9jGLM=
github.com/tribalwarshelp/golang-sdk v0.0.0-20210505172651-7dc458534a8c/go.mod h1:0VNYCWHFE5Szvd/b5RpnhtHdvYwR/6XfB/iFjgPTAtY=
github.com/tribalwarshelp/golang-sdk v0.0.0-20210705044231-26168540b50a h1:LAru/bPO0v+vzhYhzQoDoEsQ4nNW2IQzX1xs8MnTZjY=
github.com/tribalwarshelp/golang-sdk v0.0.0-20210705044231-26168540b50a/go.mod h1:SWLnHJnMhZcr1hpIyiwN7A5u6yaJqQ64Dv0I49f4OLc=
github.com/tribalwarshelp/golang-sdk v0.0.0-20210712101301-0e40924ae102 h1:a5Zb0i8m/5KDqm67vt4Z65V7ypgXK145vU5AauvfoA0=
github.com/tribalwarshelp/golang-sdk v0.0.0-20210712101301-0e40924ae102/go.mod h1:TuTVOLripDuR/YUXRkzC0QnbAtrabSlNF3c1Vl7S9wA=
github.com/tribalwarshelp/golang-sdk v0.0.0-20210717082347-98161a4b2533 h1:84UBdpylmqqlGDwOmRUbZAXX/CnJCCKWnnbTHZNyZ7A=
github.com/tribalwarshelp/golang-sdk v0.0.0-20210717082347-98161a4b2533/go.mod h1:2uacP5AiUf1HWK/gwun5Y8VHLybIMaocsSrnluDBNFo=
github.com/tribalwarshelp/golang-sdk v0.0.0-20210717112029-bb518cbee33d h1:Xh5rVjUP55jOZZM3PaI2AvMpCoiRadwIe5gfDBpDC+0=
github.com/tribalwarshelp/golang-sdk v0.0.0-20210717112029-bb518cbee33d/go.mod h1:COakTplg+GL/4mIPyry00PcZqOcCNCDXkhM36Dci+kA=
github.com/tribalwarshelp/shared v0.0.0-20210505172413-bf85190fd66d/go.mod h1:GBnSKQrxL8Nmi3MViIzZVbyP9+ugd28gWArsSvw1iVU=
github.com/tribalwarshelp/shared v0.0.0-20210521205055-fcef062f6b8a h1:nKEymuRmwv5qGS2uyURYwN6JKqdqEFsb6Q9Fbn4iQbY=
github.com/tribalwarshelp/shared v0.0.0-20210521205055-fcef062f6b8a/go.mod h1://pyC+3J9nFBdpvNpVf1w7+LNNOw+L/kqxHlFK+kuLk=
github.com/tribalwarshelp/shared v0.0.0-20210606172508-1eaae48e4c3e h1:qez3K2fVLaocxHBgDHP6z/ZiTlzVm1DF0Y81jY5bnHo=
github.com/tribalwarshelp/shared v0.0.0-20210606172508-1eaae48e4c3e/go.mod h1://pyC+3J9nFBdpvNpVf1w7+LNNOw+L/kqxHlFK+kuLk=
github.com/tribalwarshelp/shared v0.0.0-20210704200704-f3e5bd092975 h1:H0Dm+nHpbiNz3wmpYV1UcF//6KXN8bRO260QG5zdEX0=
github.com/tribalwarshelp/shared v0.0.0-20210704200704-f3e5bd092975/go.mod h1:R7761+5rdyaMUM2dPMgBma05Z8XDgA3bCl/Grydb09g=
github.com/tribalwarshelp/shared v0.0.0-20210712092456-dcd6203b1fd9 h1:rpuecZUAul4lCdcWjYx05ZNDff6RBbwJatxOcYpFjRY=
github.com/tribalwarshelp/shared v0.0.0-20210712092456-dcd6203b1fd9/go.mod h1:M+33qeTM/oxG7IyxKbIZqs0wqpB5nEHPfgdo29kqHMI=
github.com/tribalwarshelp/shared v0.0.0-20210717070514-5030d62000d4 h1:lnbuxPwiWsCTLeFCvuxDRNlqYvD1O/ssYE52HInqdAY=
github.com/tribalwarshelp/shared v0.0.0-20210717070514-5030d62000d4/go.mod h1:6xooIU27fjagr/KVBPayktW4gn9ylTdBPGgxlQ6+x9s=
github.com/tribalwarshelp/shared v0.0.0-20210717094429-6efa1a4f614c h1:dgWoORgR3COUbO0Dhho+fB1axhsKGXadaxeCiw9APFA=
github.com/tribalwarshelp/shared v0.0.0-20210717094429-6efa1a4f614c/go.mod h1:6xooIU27fjagr/KVBPayktW4gn9ylTdBPGgxlQ6+x9s=
github.com/vmihailenco/bufpool v0.1.11 h1:gOq2WmBrq0i2yW5QJ16ykccQ4wH9UyEsgLm6czKAd94=
@ -133,17 +109,9 @@ github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgq
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg=
go.opentelemetry.io/otel v0.20.0 h1:eaP0Fqu7SXHwvjiqDq83zImeehOHX8doTvU9AwXON8g=
go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo=
go.opentelemetry.io/otel/metric v0.19.0/go.mod h1:8f9fglJPRnXuskQmKpnad31lcLJ2VmNNqIsx/uIwBSc=
go.opentelemetry.io/otel/metric v0.20.0 h1:4kzhXFP+btKm4jwxpjIqjs41A7MakRFUS86bqLHTIw8=
go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU=
go.opentelemetry.io/otel/oteltest v0.19.0/go.mod h1:tI4yxwh8U21v7JD6R3BcA/2+RBoTKFexE/PJ/nSO7IA=
go.opentelemetry.io/otel/oteltest v0.20.0 h1:HiITxCawalo5vQzdHfKeZurV8x7ljcqAgiWzF6Vaeaw=
go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw=
go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bjBWZQA5DXz/qg=
go.opentelemetry.io/otel/trace v0.20.0 h1:1DL6EXUdcg95gukhuRRvLDO/4X5THh/5dIV52lqtnbw=
go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw=
golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@ -185,14 +153,11 @@ golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 h1:iGu644GcxtEcrInvDsQRCwJjtCIOlT2V7IRt6ah2Whw=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
@ -235,8 +200,8 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200603094226-e3079894b1e8 h1:jL/vaozO53FMfZLySWM+4nulF3gQEC6q5jH90LPomDo=
gopkg.in/yaml.v3 v3.0.0-20200603094226-e3079894b1e8/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

@ -3,14 +3,14 @@ package group
import (
"context"
"github.com/tribalwarshelp/dcbot/models"
"github.com/tribalwarshelp/dcbot/model"
)
type Repository interface {
Store(ctx context.Context, group *models.Group) error
StoreMany(ctx context.Context, groups []*models.Group) error
Update(ctx context.Context, group *models.Group) error
Delete(ctx context.Context, filter *models.GroupFilter) ([]*models.Group, error)
GetByID(ctx context.Context, id int) (*models.Group, error)
Fetch(ctx context.Context, filter *models.GroupFilter) ([]*models.Group, int, error)
Store(ctx context.Context, group *model.Group) error
StoreMany(ctx context.Context, groups []*model.Group) error
Update(ctx context.Context, group *model.Group) error
Delete(ctx context.Context, filter *model.GroupFilter) ([]*model.Group, error)
GetByID(ctx context.Context, id int) (*model.Group, error)
Fetch(ctx context.Context, filter *model.GroupFilter) ([]*model.Group, int, error)
}

@ -4,42 +4,44 @@ import (
"context"
"github.com/tribalwarshelp/dcbot/group"
"github.com/tribalwarshelp/dcbot/models"
"github.com/tribalwarshelp/dcbot/model"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"github.com/pkg/errors"
)
type pgRepo struct {
type PGRepository struct {
*pg.DB
}
func NewPgRepo(db *pg.DB) (group.Repository, error) {
if err := db.Model((*models.Group)(nil)).CreateTable(&orm.CreateTableOptions{
var _ group.Repository = &PGRepository{}
func NewPgRepo(db *pg.DB) (*PGRepository, error) {
if err := db.Model((*model.Group)(nil)).CreateTable(&orm.CreateTableOptions{
IfNotExists: true,
FKConstraints: true,
}); err != nil {
return nil, errors.Wrap(err, "couldn't create the 'groups' table")
}
return &pgRepo{db}, nil
return &PGRepository{db}, nil
}
func (repo *pgRepo) Store(ctx context.Context, group *models.Group) error {
func (repo *PGRepository) Store(ctx context.Context, group *model.Group) error {
if _, err := repo.Model(group).Returning("*").Context(ctx).Insert(); err != nil {
return err
}
return nil
}
func (repo *pgRepo) StoreMany(ctx context.Context, groups []*models.Group) error {
func (repo *PGRepository) StoreMany(ctx context.Context, groups []*model.Group) error {
if _, err := repo.Model(&groups).Returning("*").Context(ctx).Insert(); err != nil {
return err
}
return nil
}
func (repo *pgRepo) Update(ctx context.Context, group *models.Group) error {
func (repo *PGRepository) Update(ctx context.Context, group *model.Group) error {
if _, err := repo.
Model(group).
WherePK().
@ -51,8 +53,8 @@ func (repo *pgRepo) Update(ctx context.Context, group *models.Group) error {
return nil
}
func (repo *pgRepo) GetByID(ctx context.Context, id int) (*models.Group, error) {
g := &models.Group{
func (repo *PGRepository) GetByID(ctx context.Context, id int) (*model.Group, error) {
g := &model.Group{
ID: id,
}
if err := repo.
@ -67,9 +69,9 @@ func (repo *pgRepo) GetByID(ctx context.Context, id int) (*models.Group, error)
return g, nil
}
func (repo *pgRepo) Fetch(ctx context.Context, f *models.GroupFilter) ([]*models.Group, int, error) {
func (repo *PGRepository) Fetch(ctx context.Context, f *model.GroupFilter) ([]*model.Group, int, error) {
var err error
var data []*models.Group
var data []*model.Group
query := repo.Model(&data).Relation("Server").Relation("Observations").Context(ctx)
if f != nil {
@ -87,8 +89,8 @@ func (repo *pgRepo) Fetch(ctx context.Context, f *models.GroupFilter) ([]*models
return data, total, nil
}
func (repo *pgRepo) Delete(ctx context.Context, f *models.GroupFilter) ([]*models.Group, error) {
var data []*models.Group
func (repo *PGRepository) Delete(ctx context.Context, f *model.GroupFilter) ([]*model.Group, error) {
var data []*model.Group
query := repo.Model(&data).Context(ctx)
if f != nil {

@ -71,7 +71,7 @@ func main() {
})
}
serverRepo, err := serverepository.NewPgRepo(db)
serverRepo, err := serverepository.NewPgRepository(db)
if err != nil {
logrus.Fatal(err)
}
@ -79,7 +79,7 @@ func main() {
if err != nil {
logrus.Fatal(err)
}
observationRepo, err := observationrepository.NewPgRepo(db)
observationRepo, err := observationrepository.NewPgRepository(db)
if err != nil {
logrus.Fatal(err)
}

@ -1,4 +1,4 @@
package models
package model
import "github.com/go-pg/pg/v10/orm"

@ -1,4 +1,4 @@
package models
package model
import (
"github.com/Kichiyaki/gopgutil/v10"

@ -1,4 +1,4 @@
package models
package model
import (
"github.com/Kichiyaki/gopgutil/v10"

@ -1,4 +1,4 @@
package models
package model
import (
"github.com/Kichiyaki/gopgutil/v10"

@ -3,14 +3,14 @@ package observation
import (
"context"
"github.com/tribalwarshelp/dcbot/models"
"github.com/tribalwarshelp/dcbot/model"
)
type Repository interface {
Store(ctx context.Context, observation *models.Observation) error
StoreMany(ctx context.Context, observations []*models.Observation) error
Update(ctx context.Context, observation *models.Observation) error
Delete(ctx context.Context, filter *models.ObservationFilter) ([]*models.Observation, error)
Fetch(ctx context.Context, filter *models.ObservationFilter) ([]*models.Observation, int, error)
Store(ctx context.Context, observation *model.Observation) error
StoreMany(ctx context.Context, observations []*model.Observation) error
Update(ctx context.Context, observation *model.Observation) error
Delete(ctx context.Context, filter *model.ObservationFilter) ([]*model.Observation, error)
Fetch(ctx context.Context, filter *model.ObservationFilter) ([]*model.Observation, int, error)
FetchServers(ctx context.Context) ([]string, error)
}

@ -3,7 +3,7 @@ package repository
import (
"context"
"github.com/tribalwarshelp/dcbot/models"
"github.com/tribalwarshelp/dcbot/model"
"github.com/tribalwarshelp/dcbot/observation"
"github.com/go-pg/pg/v10"
@ -11,35 +11,37 @@ import (
"github.com/pkg/errors"
)
type pgRepo struct {
type PGRepository struct {
*pg.DB
}
func NewPgRepo(db *pg.DB) (observation.Repository, error) {
if err := db.Model((*models.Observation)(nil)).CreateTable(&orm.CreateTableOptions{
var _ observation.Repository = &PGRepository{}
func NewPgRepository(db *pg.DB) (*PGRepository, error) {
if err := db.Model((*model.Observation)(nil)).CreateTable(&orm.CreateTableOptions{
IfNotExists: true,
FKConstraints: true,
}); err != nil {
return nil, errors.Wrap(err, "couldn't create the 'observations' table")
}
return &pgRepo{db}, nil
return &PGRepository{db}, nil
}
func (repo *pgRepo) Store(ctx context.Context, observation *models.Observation) error {
func (repo *PGRepository) Store(ctx context.Context, observation *model.Observation) error {
if _, err := repo.Model(observation).Returning("*").Context(ctx).Insert(); err != nil {
return err
}
return nil
}
func (repo *pgRepo) StoreMany(ctx context.Context, observations []*models.Observation) error {
func (repo *PGRepository) StoreMany(ctx context.Context, observations []*model.Observation) error {
if _, err := repo.Model(&observations).Returning("*").Context(ctx).Insert(); err != nil {
return err
}
return nil
}
func (repo *pgRepo) Update(ctx context.Context, observation *models.Observation) error {
func (repo *PGRepository) Update(ctx context.Context, observation *model.Observation) error {
if _, err := repo.
Model(observation).
WherePK().
@ -51,9 +53,9 @@ func (repo *pgRepo) Update(ctx context.Context, observation *models.Observation)
return nil
}
func (repo *pgRepo) Fetch(ctx context.Context, f *models.ObservationFilter) ([]*models.Observation, int, error) {
func (repo *PGRepository) Fetch(ctx context.Context, f *model.ObservationFilter) ([]*model.Observation, int, error) {
var err error
var data []*models.Observation
var data []*model.Observation
query := repo.Model(&data).Context(ctx)
if f != nil {
@ -71,10 +73,10 @@ func (repo *pgRepo) Fetch(ctx context.Context, f *models.ObservationFilter) ([]*
return data, total, nil
}
func (repo *pgRepo) FetchServers(ctx context.Context) ([]string, error) {
func (repo *PGRepository) FetchServers(ctx context.Context) ([]string, error) {
var res []string
err := repo.
Model(&models.Observation{}).
Model(&model.Observation{}).
Column("server").
Context(ctx).
Group("server").
@ -83,8 +85,8 @@ func (repo *pgRepo) FetchServers(ctx context.Context) ([]string, error) {
return res, err
}
func (repo *pgRepo) Delete(ctx context.Context, f *models.ObservationFilter) ([]*models.Observation, error) {
var data []*models.Observation
func (repo *PGRepository) Delete(ctx context.Context, f *model.ObservationFilter) ([]*model.Observation, error) {
var data []*model.Observation
query := repo.Model(&data).Context(ctx)
if f != nil {

@ -3,12 +3,12 @@ package server
import (
"context"
"github.com/tribalwarshelp/dcbot/models"
"github.com/tribalwarshelp/dcbot/model"
)
type Repository interface {
Store(ctx context.Context, server *models.Server) error
Update(ctx context.Context, server *models.Server) error
Delete(ctx context.Context, filter *models.ServerFilter) ([]*models.Server, error)
Fetch(ctx context.Context, filter *models.ServerFilter) ([]*models.Server, int, error)
Store(ctx context.Context, server *model.Server) error
Update(ctx context.Context, server *model.Server) error
Delete(ctx context.Context, filter *model.ServerFilter) ([]*model.Server, error)
Fetch(ctx context.Context, filter *model.ServerFilter) ([]*model.Server, int, error)
}

@ -3,7 +3,7 @@ package repository
import (
"context"
"github.com/tribalwarshelp/dcbot/models"
"github.com/tribalwarshelp/dcbot/model"
"github.com/tribalwarshelp/dcbot/server"
"github.com/go-pg/pg/v10"
@ -11,20 +11,22 @@ import (
"github.com/pkg/errors"
)
type pgRepo struct {
type PGRepository struct {
*pg.DB
}
func NewPgRepo(db *pg.DB) (server.Repository, error) {
if err := db.Model((*models.Server)(nil)).CreateTable(&orm.CreateTableOptions{
var _ server.Repository = &PGRepository{}
func NewPgRepository(db *pg.DB) (*PGRepository, error) {
if err := db.Model((*model.Server)(nil)).CreateTable(&orm.CreateTableOptions{
IfNotExists: true,
}); err != nil {
return nil, errors.Wrap(err, "couldn't create the 'servers' table")
}
return &pgRepo{db}, nil
return &PGRepository{db}, nil
}
func (repo *pgRepo) Store(ctx context.Context, server *models.Server) error {
func (repo *PGRepository) Store(ctx context.Context, server *model.Server) error {
if _, err := repo.
Model(server).
Where("id = ?id").
@ -37,7 +39,7 @@ func (repo *pgRepo) Store(ctx context.Context, server *models.Server) error {
return nil
}
func (repo *pgRepo) Update(ctx context.Context, server *models.Server) error {
func (repo *PGRepository) Update(ctx context.Context, server *model.Server) error {
if _, err := repo.
Model(server).
WherePK().
@ -49,9 +51,9 @@ func (repo *pgRepo) Update(ctx context.Context, server *models.Server) error {
return nil
}
func (repo *pgRepo) Fetch(ctx context.Context, f *models.ServerFilter) ([]*models.Server, int, error) {
func (repo *PGRepository) Fetch(ctx context.Context, f *model.ServerFilter) ([]*model.Server, int, error) {
var err error
var data []*models.Server
var data []*model.Server
query := repo.Model(&data).Context(ctx).Relation("Groups")
if f != nil {
@ -69,8 +71,8 @@ func (repo *pgRepo) Fetch(ctx context.Context, f *models.ServerFilter) ([]*model
return data, total, nil
}
func (repo *pgRepo) Delete(ctx context.Context, f *models.ServerFilter) ([]*models.Server, error) {
var data []*models.Server
func (repo *PGRepository) Delete(ctx context.Context, f *model.ServerFilter) ([]*model.Server, error) {
var data []*model.Server
query := repo.Model(&data).Context(ctx)
if f != nil {