From e98540ad3a3922be7f2146ea192a329fa665ea1d Mon Sep 17 00:00:00 2001 From: Leigh MacDonald Date: Thu, 13 Jun 2024 03:08:30 -0600 Subject: [PATCH] Simplify naming of members and constructors --- internal/appeal/appeal_usecase.go | 50 ++++----- internal/asset/asset_usecase.go | 10 +- internal/auth/auth_usecase.go | 46 ++++---- internal/ban/ban_asn_usecase.go | 28 ++--- internal/ban/ban_net_usecase.go | 8 +- internal/ban/ban_steam_usecase.go | 15 ++- internal/blocklist/blocklist_usecase.go | 48 ++++---- internal/config/config_usecase.go | 10 +- internal/contest/contest_service.go | 52 ++++----- internal/contest/contest_usecase.go | 30 ++--- internal/demo/demo_service.go | 8 +- internal/demo/demo_usecase.go | 12 +- internal/discord/discord_service_oauth.go | 42 +++---- internal/discord/discord_usecase.go | 18 +-- internal/discord/discord_usecase_oauth.go | 26 ++--- internal/forum/forum_service.go | 108 +++++++++--------- internal/match/match_repository.go | 50 ++++----- internal/match/match_service.go | 4 +- internal/match/match_usecase.go | 72 ++++++------ internal/network/network_usecase.go | 44 ++++---- internal/person/person_usecase.go | 46 ++++---- internal/report/report_service.go | 2 +- internal/report/report_usecase.go | 52 ++++----- internal/servers/servers_usecase.go | 16 +-- internal/srcds/srcds_usecase.go | 130 +++++++++++----------- internal/state/state_usecase.go | 6 +- internal/steamgroup/steamgroup_usecase.go | 45 ++++---- internal/votes/vote_service.go | 14 +-- internal/votes/vote_usecase.go | 18 +-- internal/wiki/wiki_service.go | 10 +- internal/wiki/wiki_usecase.go | 10 +- internal/wordfilter/wordfilter_service.go | 10 +- internal/wordfilter/wordfilter_usecase.go | 24 ++-- 33 files changed, 531 insertions(+), 533 deletions(-) diff --git a/internal/appeal/appeal_usecase.go b/internal/appeal/appeal_usecase.go index b15364c2..8a1e3bcf 100644 --- a/internal/appeal/appeal_usecase.go +++ b/internal/appeal/appeal_usecase.go @@ -11,21 +11,21 @@ import ( ) type appeals struct { - appealRepository domain.AppealRepository - banUsecase domain.BanSteamUsecase - personUsecase domain.PersonUsecase - discordUsecase domain.DiscordUsecase - configUsecase domain.ConfigUsecase + repository domain.AppealRepository + bans domain.BanSteamUsecase + persons domain.PersonUsecase + discord domain.DiscordUsecase + config domain.ConfigUsecase } -func NewAppealUsecase(ar domain.AppealRepository, banUsecase domain.BanSteamUsecase, personUsecase domain.PersonUsecase, - discordUsecase domain.DiscordUsecase, configUsecase domain.ConfigUsecase, +func NewAppealUsecase(ar domain.AppealRepository, bans domain.BanSteamUsecase, persons domain.PersonUsecase, + discord domain.DiscordUsecase, config domain.ConfigUsecase, ) domain.AppealUsecase { - return &appeals{appealRepository: ar, banUsecase: banUsecase, personUsecase: personUsecase, discordUsecase: discordUsecase, configUsecase: configUsecase} + return &appeals{repository: ar, bans: bans, persons: persons, discord: discord, config: config} } func (u *appeals) GetAppealsByActivity(ctx context.Context, opts domain.AppealQueryFilter) ([]domain.AppealOverview, error) { - return u.appealRepository.GetAppealsByActivity(ctx, opts) + return u.repository.GetAppealsByActivity(ctx, opts) } func (u *appeals) EditBanMessage(ctx context.Context, curUser domain.UserProfile, reportID int64, newMsg string) (domain.BanAppealMessage, error) { @@ -34,7 +34,7 @@ func (u *appeals) EditBanMessage(ctx context.Context, curUser domain.UserProfile return domain.BanAppealMessage{}, err } - bannedPerson, errReport := u.banUsecase.GetByBanID(ctx, existing.BanID, true, true) + bannedPerson, errReport := u.bans.GetByBanID(ctx, existing.BanID, true, true) if errReport != nil { return existing, errReport } @@ -53,13 +53,13 @@ func (u *appeals) EditBanMessage(ctx context.Context, curUser domain.UserProfile existing.MessageMD = newMsg - if errSave := u.appealRepository.SaveBanMessage(ctx, &existing); errSave != nil { + if errSave := u.repository.SaveBanMessage(ctx, &existing); errSave != nil { return existing, errSave } - conf := u.configUsecase.Config() + conf := u.config.Config() - u.discordUsecase.SendPayload(domain.ChannelModAppealLog, discord.NewAppealMessage(existing.MessageMD, + u.discord.SendPayload(domain.ChannelModAppealLog, discord.NewAppealMessage(existing.MessageMD, conf.ExtURL(bannedPerson.BanSteam), curUser, conf.ExtURL(curUser))) return existing, nil @@ -74,7 +74,7 @@ func (u *appeals) CreateBanMessage(ctx context.Context, curUser domain.UserProfi return domain.BanAppealMessage{}, domain.ErrBadRequest } - bannedPerson, errReport := u.banUsecase.GetByBanID(ctx, banID, true, true) + bannedPerson, errReport := u.bans.GetByBanID(ctx, banID, true, true) if errReport != nil { return domain.BanAppealMessage{}, errReport } @@ -83,12 +83,12 @@ func (u *appeals) CreateBanMessage(ctx context.Context, curUser domain.UserProfi return domain.BanAppealMessage{}, domain.ErrPermissionDenied } - _, errTarget := u.personUsecase.GetOrCreatePersonBySteamID(ctx, bannedPerson.TargetID) + _, errTarget := u.persons.GetOrCreatePersonBySteamID(ctx, bannedPerson.TargetID) if errTarget != nil { return domain.BanAppealMessage{}, errTarget } - _, errSource := u.personUsecase.GetOrCreatePersonBySteamID(ctx, bannedPerson.SourceID) + _, errSource := u.persons.GetOrCreatePersonBySteamID(ctx, bannedPerson.SourceID) if errSource != nil { return domain.BanAppealMessage{}, errSource } @@ -98,18 +98,18 @@ func (u *appeals) CreateBanMessage(ctx context.Context, curUser domain.UserProfi msg.Personaname = curUser.Name msg.Avatarhash = curUser.Avatarhash - if errSave := u.appealRepository.SaveBanMessage(ctx, &msg); errSave != nil { + if errSave := u.repository.SaveBanMessage(ctx, &msg); errSave != nil { return domain.BanAppealMessage{}, errSave } - conf := u.configUsecase.Config() + conf := u.config.Config() - u.discordUsecase.SendPayload(domain.ChannelModAppealLog, discord.NewAppealMessage(msg.MessageMD, + u.discord.SendPayload(domain.ChannelModAppealLog, discord.NewAppealMessage(msg.MessageMD, conf.ExtURL(bannedPerson.BanSteam), curUser, conf.ExtURL(curUser))) bannedPerson.UpdatedOn = time.Now() - if errUpdate := u.banUsecase.Save(ctx, &bannedPerson.BanSteam); errUpdate != nil { + if errUpdate := u.bans.Save(ctx, &bannedPerson.BanSteam); errUpdate != nil { return domain.BanAppealMessage{}, errUpdate } @@ -117,7 +117,7 @@ func (u *appeals) CreateBanMessage(ctx context.Context, curUser domain.UserProfi } func (u *appeals) GetBanMessages(ctx context.Context, userProfile domain.UserProfile, banID int64) ([]domain.BanAppealMessage, error) { - banPerson, errGetBan := u.banUsecase.GetByBanID(ctx, banID, true, true) + banPerson, errGetBan := u.bans.GetByBanID(ctx, banID, true, true) if errGetBan != nil { return nil, errGetBan } @@ -126,11 +126,11 @@ func (u *appeals) GetBanMessages(ctx context.Context, userProfile domain.UserPro return nil, domain.ErrPermissionDenied } - return u.appealRepository.GetBanMessages(ctx, banID) + return u.repository.GetBanMessages(ctx, banID) } func (u *appeals) GetBanMessageByID(ctx context.Context, banMessageID int64) (domain.BanAppealMessage, error) { - return u.appealRepository.GetBanMessageByID(ctx, banMessageID) + return u.repository.GetBanMessageByID(ctx, banMessageID) } func (u *appeals) DropBanMessage(ctx context.Context, curUser domain.UserProfile, banMessageID int64) error { @@ -143,11 +143,11 @@ func (u *appeals) DropBanMessage(ctx context.Context, curUser domain.UserProfile return domain.ErrPermissionDenied } - if errDrop := u.appealRepository.DropBanMessage(ctx, &existing); errDrop != nil { + if errDrop := u.repository.DropBanMessage(ctx, &existing); errDrop != nil { return errDrop } - u.discordUsecase.SendPayload(domain.ChannelModAppealLog, discord.DeleteAppealMessage(&existing, curUser, u.configUsecase.ExtURL(curUser))) + u.discord.SendPayload(domain.ChannelModAppealLog, discord.DeleteAppealMessage(&existing, curUser, u.config.ExtURL(curUser))) return nil } diff --git a/internal/asset/asset_usecase.go b/internal/asset/asset_usecase.go index 4404eb47..dbfda8d1 100644 --- a/internal/asset/asset_usecase.go +++ b/internal/asset/asset_usecase.go @@ -18,11 +18,11 @@ import ( ) type assets struct { - assetRepository domain.AssetRepository + repository domain.AssetRepository } func NewAssetUsecase(assetRepository domain.AssetRepository) domain.AssetUsecase { - return &assets{assetRepository: assetRepository} + return &assets{repository: assetRepository} } func (s assets) Create(ctx context.Context, author steamid.SteamID, bucket domain.Bucket, fileName string, content io.ReadSeeker) (domain.Asset, error) { @@ -44,7 +44,7 @@ func (s assets) Create(ctx context.Context, author steamid.SteamID, bucket domai return domain.Asset{}, errAsset } - newAsset, errPut := s.assetRepository.Put(ctx, asset, content) + newAsset, errPut := s.repository.Put(ctx, asset, content) if errPut != nil { return domain.Asset{}, errPut } @@ -60,7 +60,7 @@ func (s assets) Get(ctx context.Context, uuid uuid.UUID) (domain.Asset, io.ReadS return domain.Asset{}, nil, domain.ErrUUIDInvalid } - asset, reader, errAsset := s.assetRepository.Get(ctx, uuid) + asset, reader, errAsset := s.repository.Get(ctx, uuid) if errAsset != nil { return asset, nil, errAsset } @@ -73,7 +73,7 @@ func (s assets) Delete(ctx context.Context, assetID uuid.UUID) (int64, error) { return 0, domain.ErrUUIDInvalid } - size, err := s.assetRepository.Delete(ctx, assetID) + size, err := s.repository.Delete(ctx, assetID) if err != nil { return 0, err } diff --git a/internal/auth/auth_usecase.go b/internal/auth/auth_usecase.go index d64b6080..1314caed 100644 --- a/internal/auth/auth_usecase.go +++ b/internal/auth/auth_usecase.go @@ -23,22 +23,22 @@ import ( const ctxKeyUserProfile = "user_profile" type auth struct { - authRepository domain.AuthRepository - configUsecase domain.ConfigUsecase - personUsecase domain.PersonUsecase - banUsecase domain.BanSteamUsecase - serverUsecase domain.ServersUsecase + auth domain.AuthRepository + config domain.ConfigUsecase + persons domain.PersonUsecase + bans domain.BanSteamUsecase + servers domain.ServersUsecase } -func NewAuthUsecase(authRepository domain.AuthRepository, configUsecase domain.ConfigUsecase, personUsecase domain.PersonUsecase, - banUsecase domain.BanSteamUsecase, serversUsecase domain.ServersUsecase, +func NewAuthUsecase(repository domain.AuthRepository, config domain.ConfigUsecase, persons domain.PersonUsecase, + bans domain.BanSteamUsecase, servers domain.ServersUsecase, ) domain.AuthUsecase { return &auth{ - authRepository: authRepository, - configUsecase: configUsecase, - personUsecase: personUsecase, - banUsecase: banUsecase, - serverUsecase: serversUsecase, + auth: repository, + config: config, + persons: persons, + bans: bans, + servers: servers, } } @@ -48,7 +48,7 @@ func (u *auth) Start(ctx context.Context) { for { select { case <-ticker.C: - if err := u.authRepository.PrunePersonAuth(ctx); err != nil && !errors.Is(err, domain.ErrNoResult) { + if err := u.auth.PrunePersonAuth(ctx); err != nil && !errors.Is(err, domain.ErrNoResult) { slog.Error("Error pruning expired refresh tokens", log.ErrAttr(err)) } case <-ctx.Done(): @@ -60,11 +60,11 @@ func (u *auth) Start(ctx context.Context) { } func (u *auth) DeletePersonAuth(ctx context.Context, authID int64) error { - return u.authRepository.DeletePersonAuth(ctx, authID) + return u.auth.DeletePersonAuth(ctx, authID) } func (u *auth) GetPersonAuthByRefreshToken(ctx context.Context, token string, auth *domain.PersonAuth) error { - return u.authRepository.GetPersonAuthByFingerprint(ctx, token, auth) + return u.auth.GetPersonAuthByFingerprint(ctx, token, auth) } // MakeToken generates new jwt auth tokens @@ -88,7 +88,7 @@ func (u *auth) MakeToken(ctx *gin.Context, cookieKey string, sid steamid.SteamID personAuth := domain.NewPersonAuth(sid, ipAddr, accessToken) - if saveErr := u.authRepository.SavePersonAuth(ctx, &personAuth); saveErr != nil { + if saveErr := u.auth.SavePersonAuth(ctx, &personAuth); saveErr != nil { return domain.UserTokens{}, errors.Join(saveErr, domain.ErrSaveToken) } @@ -96,7 +96,7 @@ func (u *auth) MakeToken(ctx *gin.Context, cookieKey string, sid steamid.SteamID } func (u *auth) AuthMiddleware(level domain.Privilege) gin.HandlerFunc { - cookieKey := u.configUsecase.Config().HTTPCookieKey + cookieKey := u.config.Config().HTTPCookieKey return func(ctx *gin.Context) { var token string @@ -130,7 +130,7 @@ func (u *auth) AuthMiddleware(level domain.Privilege) gin.HandlerFunc { return } - loggedInPerson, errGetPerson := u.personUsecase.GetOrCreatePersonBySteamID(ctx, sid) + loggedInPerson, errGetPerson := u.persons.GetOrCreatePersonBySteamID(ctx, sid) if errGetPerson != nil { slog.Error("Failed to load person during auth", log.ErrAttr(errGetPerson)) ctx.AbortWithStatus(http.StatusForbidden) @@ -144,7 +144,7 @@ func (u *auth) AuthMiddleware(level domain.Privilege) gin.HandlerFunc { return } - bannedPerson, errBan := u.banUsecase.GetBySteamID(ctx, sid, false, true) + bannedPerson, errBan := u.bans.GetBySteamID(ctx, sid, false, true) if errBan != nil { if !errors.Is(errBan, domain.ErrNoResult) { slog.Error("Failed to fetch authed user ban", log.ErrAttr(errBan)) @@ -166,7 +166,7 @@ func (u *auth) AuthMiddleware(level domain.Privilege) gin.HandlerFunc { ctx.Set(ctxKeyUserProfile, profile) - if u.configUsecase.Config().Sentry.SentryDSN != "" { + if u.config.Config().Sentry.SentryDSN != "" { if hub := sentrygin.GetHubFromContext(ctx); hub != nil { hub.WithScope(func(scope *sentry.Scope) { scope.SetUser(sentry.User{ @@ -213,7 +213,7 @@ func (u *auth) AuthServerMiddleWare() gin.HandlerFunc { } var server domain.Server - if errServer := u.serverUsecase.GetServerByPassword(ctx, reqAuthHeader, &server, false, false); errServer != nil { + if errServer := u.servers.GetServerByPassword(ctx, reqAuthHeader, &server, false, false); errServer != nil { slog.Error("Failed to load server during auth", log.ErrAttr(errServer), slog.String("token", reqAuthHeader), slog.String("IP", ctx.ClientIP())) ctx.AbortWithStatus(http.StatusUnauthorized) @@ -222,7 +222,7 @@ func (u *auth) AuthServerMiddleWare() gin.HandlerFunc { ctx.Set("server_id", server.ServerID) - if u.configUsecase.Config().Sentry.SentryDSN != "" { + if u.config.Config().Sentry.SentryDSN != "" { if hub := sentrygin.GetHubFromContext(ctx); hub != nil { hub.WithScope(func(scope *sentry.Scope) { scope.SetUser(sentry.User{ @@ -240,7 +240,7 @@ func (u *auth) AuthServerMiddleWare() gin.HandlerFunc { func (u *auth) NewUserToken(steamID steamid.SteamID, cookieKey string, fingerPrint string, validDuration time.Duration) (string, error) { nowTime := time.Now() - conf := u.configUsecase.Config() + conf := u.config.Config() claims := domain.UserAuthClaims{ Fingerprint: FingerprintHash(fingerPrint), RegisteredClaims: jwt.RegisteredClaims{ diff --git a/internal/ban/ban_asn_usecase.go b/internal/ban/ban_asn_usecase.go index e955c4a3..cc183ba1 100644 --- a/internal/ban/ban_asn_usecase.go +++ b/internal/ban/ban_asn_usecase.go @@ -10,22 +10,22 @@ import ( ) type banASN struct { - repository domain.BanASNRepository - discordUsecase domain.DiscordUsecase - networkUsecase domain.NetworkUsecase - config domain.ConfigUsecase - person domain.PersonUsecase + repository domain.BanASNRepository + discord domain.DiscordUsecase + networks domain.NetworkUsecase + config domain.ConfigUsecase + person domain.PersonUsecase } -func NewBanASNUsecase(repository domain.BanASNRepository, discordUsecase domain.DiscordUsecase, - networkUsecase domain.NetworkUsecase, config domain.ConfigUsecase, person domain.PersonUsecase, +func NewBanASNUsecase(repository domain.BanASNRepository, discord domain.DiscordUsecase, + network domain.NetworkUsecase, config domain.ConfigUsecase, person domain.PersonUsecase, ) domain.BanASNUsecase { return banASN{ - repository: repository, - discordUsecase: discordUsecase, - networkUsecase: networkUsecase, - config: config, - person: person, + repository: repository, + discord: discord, + networks: network, + config: config, + person: person, } } @@ -50,7 +50,7 @@ func (s banASN) Ban(ctx context.Context, banASN *domain.BanASN) error { return errors.Join(errSave, domain.ErrSaveBan) } - s.discordUsecase.SendPayload(domain.ChannelBanLog, discord.BanASNMessage(*banASN, author, s.config.Config())) + s.discord.SendPayload(domain.ChannelBanLog, discord.BanASNMessage(*banASN, author, s.config.Config())) return nil } @@ -70,7 +70,7 @@ func (s banASN) Unban(ctx context.Context, asnNum string) (bool, error) { return false, errors.Join(errDrop, domain.ErrDropASNBan) } - s.discordUsecase.SendPayload(domain.ChannelModLog, discord.UnbanASNMessage(asNum)) + s.discord.SendPayload(domain.ChannelModLog, discord.UnbanASNMessage(asNum)) return true, nil } diff --git a/internal/ban/ban_net_usecase.go b/internal/ban/ban_net_usecase.go index a66f400d..95495795 100644 --- a/internal/ban/ban_net_usecase.go +++ b/internal/ban/ban_net_usecase.go @@ -21,12 +21,12 @@ type banNet struct { state domain.StateUsecase } -func NewBanNetUsecase(repository domain.BanNetRepository, personUsecase domain.PersonUsecase, - configUsecase domain.ConfigUsecase, discordUsecase domain.DiscordUsecase, stateUsecase domain.StateUsecase, +func NewBanNetUsecase(repository domain.BanNetRepository, persons domain.PersonUsecase, + config domain.ConfigUsecase, discord domain.DiscordUsecase, state domain.StateUsecase, ) domain.BanNetUsecase { return &banNet{ - repository: repository, persons: personUsecase, config: configUsecase, - discord: discordUsecase, state: stateUsecase, + repository: repository, persons: persons, config: config, + discord: discord, state: state, } } diff --git a/internal/ban/ban_steam_usecase.go b/internal/ban/ban_steam_usecase.go index ffdff43b..4407abb7 100644 --- a/internal/ban/ban_steam_usecase.go +++ b/internal/ban/ban_steam_usecase.go @@ -25,17 +25,16 @@ type banSteamUsecase struct { reports domain.ReportUsecase } -func NewBanSteamUsecase(repository domain.BanSteamRepository, personUsecase domain.PersonUsecase, - configUsecase domain.ConfigUsecase, discordUsecase domain.DiscordUsecase, - reportUsecase domain.ReportUsecase, stateUsecase domain.StateUsecase, +func NewBanSteamUsecase(repository domain.BanSteamRepository, person domain.PersonUsecase, + config domain.ConfigUsecase, discord domain.DiscordUsecase, reports domain.ReportUsecase, state domain.StateUsecase, ) domain.BanSteamUsecase { return &banSteamUsecase{ banRepo: repository, - persons: personUsecase, - config: configUsecase, - discord: discordUsecase, - reports: reportUsecase, - state: stateUsecase, + persons: person, + config: config, + discord: discord, + reports: reports, + state: state, } } diff --git a/internal/blocklist/blocklist_usecase.go b/internal/blocklist/blocklist_usecase.go index a5ae0208..3c31397d 100644 --- a/internal/blocklist/blocklist_usecase.go +++ b/internal/blocklist/blocklist_usecase.go @@ -22,18 +22,18 @@ import ( ) type blocklistUsecase struct { - blocklistRepo domain.BlocklistRepository - bansSteam domain.BanSteamUsecase - bansGroup domain.BanGroupUsecase - cidrRx *regexp.Regexp + repository domain.BlocklistRepository + bans domain.BanSteamUsecase + bansGroup domain.BanGroupUsecase + cidrRx *regexp.Regexp } func NewBlocklistUsecase(br domain.BlocklistRepository, banUsecase domain.BanSteamUsecase, banGroupUsecase domain.BanGroupUsecase) domain.BlocklistUsecase { return &blocklistUsecase{ - blocklistRepo: br, - bansSteam: banUsecase, - bansGroup: banGroupUsecase, - cidrRx: regexp.MustCompile(`^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/(3[0-2]|2[0-9]|1[0-9]|[0-9]))?$`), + repository: br, + bans: banUsecase, + bansGroup: banGroupUsecase, + cidrRx: regexp.MustCompile(`^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/(3[0-2]|2[0-9]|1[0-9]|[0-9]))?$`), } } @@ -78,7 +78,7 @@ func (b blocklistUsecase) syncBlocklists(ctx context.Context) { go func() { defer waitGroup.Done() - if err := b.bansSteam.UpdateCache(ctx); err != nil { + if err := b.bans.UpdateCache(ctx); err != nil { slog.Error("failed to update banned friends", log.ErrAttr(err)) return @@ -163,11 +163,11 @@ func (b blocklistUsecase) updateSource(ctx context.Context, list domain.CIDRBloc blocks = append(blocks, netip.MustParsePrefix("192.168.0.0/24")) - if err := b.blocklistRepo.TruncateCachedEntries(ctx); err != nil { + if err := b.repository.TruncateCachedEntries(ctx); err != nil { return err } - if err := b.blocklistRepo.InsertCache(ctx, list, blocks); err != nil { + if err := b.repository.InsertCache(ctx, list, blocks); err != nil { return err } @@ -175,7 +175,7 @@ func (b blocklistUsecase) updateSource(ctx context.Context, list domain.CIDRBloc } func (b blocklistUsecase) CreateSteamBlockWhitelists(ctx context.Context, steamID steamid.SteamID) (domain.WhitelistSteam, error) { - whitelist, err := b.blocklistRepo.CreateSteamBlockWhitelists(ctx, steamID) + whitelist, err := b.repository.CreateSteamBlockWhitelists(ctx, steamID) if err != nil { return domain.WhitelistSteam{}, err } @@ -186,11 +186,11 @@ func (b blocklistUsecase) CreateSteamBlockWhitelists(ctx context.Context, steamI } func (b blocklistUsecase) GetSteamBlockWhitelists(ctx context.Context) ([]domain.WhitelistSteam, error) { - return b.blocklistRepo.GetSteamBlockWhitelists(ctx) + return b.repository.GetSteamBlockWhitelists(ctx) } func (b blocklistUsecase) DeleteSteamBlockWhitelists(ctx context.Context, steamID steamid.SteamID) error { - if err := b.blocklistRepo.DeleteSteamBlockWhitelists(ctx, steamID); err != nil { + if err := b.repository.DeleteSteamBlockWhitelists(ctx, steamID); err != nil { return err } @@ -200,11 +200,11 @@ func (b blocklistUsecase) DeleteSteamBlockWhitelists(ctx context.Context, steamI } func (b blocklistUsecase) GetCIDRBlockSources(ctx context.Context) ([]domain.CIDRBlockSource, error) { - return b.blocklistRepo.GetCIDRBlockSources(ctx) + return b.repository.GetCIDRBlockSources(ctx) } func (b blocklistUsecase) GetCIDRBlockSource(ctx context.Context, sourceID int, block *domain.CIDRBlockSource) error { - return b.blocklistRepo.GetCIDRBlockSource(ctx, sourceID, block) + return b.repository.GetCIDRBlockSource(ctx, sourceID, block) } func (b blocklistUsecase) CreateCIDRBlockSources(ctx context.Context, name string, listURL string, enabled bool) (domain.CIDRBlockSource, error) { @@ -224,7 +224,7 @@ func (b blocklistUsecase) CreateCIDRBlockSources(ctx context.Context, name strin TimeStamped: domain.NewTimeStamped(), } - if err := b.blocklistRepo.SaveCIDRBlockSources(ctx, &blockList); err != nil { + if err := b.repository.SaveCIDRBlockSources(ctx, &blockList); err != nil { return domain.CIDRBlockSource{}, domain.ErrInternal } @@ -248,7 +248,7 @@ func (b blocklistUsecase) UpdateCIDRBlockSource(ctx context.Context, sourceID in blockSource.Name = name blockSource.URL = url - if err := b.blocklistRepo.SaveCIDRBlockSources(ctx, &blockSource); err != nil { + if err := b.repository.SaveCIDRBlockSources(ctx, &blockSource); err != nil { return blockSource, err } @@ -258,7 +258,7 @@ func (b blocklistUsecase) UpdateCIDRBlockSource(ctx context.Context, sourceID in } func (b blocklistUsecase) DeleteCIDRBlockSources(ctx context.Context, blockSourceID int) error { - if err := b.blocklistRepo.DeleteCIDRBlockSources(ctx, blockSourceID); err != nil { + if err := b.repository.DeleteCIDRBlockSources(ctx, blockSourceID); err != nil { return err } @@ -268,11 +268,11 @@ func (b blocklistUsecase) DeleteCIDRBlockSources(ctx context.Context, blockSourc } func (b blocklistUsecase) GetCIDRBlockWhitelists(ctx context.Context) ([]domain.WhitelistIP, error) { - return b.blocklistRepo.GetCIDRBlockWhitelists(ctx) + return b.repository.GetCIDRBlockWhitelists(ctx) } func (b blocklistUsecase) GetCIDRBlockWhitelist(ctx context.Context, whitelistID int, whitelist *domain.WhitelistIP) error { - return b.blocklistRepo.GetCIDRBlockWhitelist(ctx, whitelistID, whitelist) + return b.repository.GetCIDRBlockWhitelist(ctx, whitelistID, whitelist) } func (b blocklistUsecase) CreateCIDRBlockWhitelist(ctx context.Context, address string) (domain.WhitelistIP, error) { @@ -290,7 +290,7 @@ func (b blocklistUsecase) CreateCIDRBlockWhitelist(ctx context.Context, address TimeStamped: domain.NewTimeStamped(), } - if errSave := b.blocklistRepo.SaveCIDRBlockWhitelist(ctx, &whitelist); errSave != nil { + if errSave := b.repository.SaveCIDRBlockWhitelist(ctx, &whitelist); errSave != nil { return domain.WhitelistIP{}, errSave } @@ -312,7 +312,7 @@ func (b blocklistUsecase) UpdateCIDRBlockWhitelist(ctx context.Context, whitelis whitelist.Address = cidr - if errSave := b.blocklistRepo.SaveCIDRBlockWhitelist(ctx, &whitelist); errSave != nil { + if errSave := b.repository.SaveCIDRBlockWhitelist(ctx, &whitelist); errSave != nil { return domain.WhitelistIP{}, errSave } @@ -322,7 +322,7 @@ func (b blocklistUsecase) UpdateCIDRBlockWhitelist(ctx context.Context, whitelis } func (b blocklistUsecase) DeleteCIDRBlockWhitelist(ctx context.Context, whitelistID int) error { - if err := b.blocklistRepo.DeleteCIDRBlockWhitelist(ctx, whitelistID); err != nil { + if err := b.repository.DeleteCIDRBlockWhitelist(ctx, whitelistID); err != nil { return err } diff --git a/internal/config/config_usecase.go b/internal/config/config_usecase.go index afb2e3c4..0be26d79 100644 --- a/internal/config/config_usecase.go +++ b/internal/config/config_usecase.go @@ -21,22 +21,22 @@ import ( ) type configUsecase struct { - configRepo domain.ConfigRepository + repository domain.ConfigRepository static domain.StaticConfig configMu sync.RWMutex currentConfig domain.Config } func NewConfigUsecase(static domain.StaticConfig, repository domain.ConfigRepository) domain.ConfigUsecase { - return &configUsecase{static: static, configRepo: repository} + return &configUsecase{static: static, repository: repository} } func (c *configUsecase) Init(ctx context.Context) error { - return c.configRepo.Init(ctx) + return c.repository.Init(ctx) } func (c *configUsecase) Write(ctx context.Context, config domain.Config) error { - if err := c.configRepo.Write(ctx, config); err != nil { + if err := c.repository.Write(ctx, config); err != nil { slog.Error("Failed to write new config", log.ErrAttr(err)) return err @@ -69,7 +69,7 @@ func (c *configUsecase) Config() domain.Config { } func (c *configUsecase) Reload(ctx context.Context) error { - config, errConfig := c.configRepo.Read(ctx) + config, errConfig := c.repository.Read(ctx) if errConfig != nil { return errConfig } diff --git a/internal/contest/contest_service.go b/internal/contest/contest_service.go index d0b344ae..be1c3a5e 100644 --- a/internal/contest/contest_service.go +++ b/internal/contest/contest_service.go @@ -17,24 +17,24 @@ import ( ) type contestHandler struct { - contestUsecase domain.ContestUsecase - configUsecase domain.ConfigUsecase - assetUsecase domain.AssetUsecase + contests domain.ContestUsecase + config domain.ConfigUsecase + assets domain.AssetUsecase } -func NewContestHandler(engine *gin.Engine, cu domain.ContestUsecase, - configUsecase domain.ConfigUsecase, assetUsecase domain.AssetUsecase, ath domain.AuthUsecase, +func NewContestHandler(engine *gin.Engine, contests domain.ContestUsecase, + config domain.ConfigUsecase, assets domain.AssetUsecase, auth domain.AuthUsecase, ) { handler := &contestHandler{ - contestUsecase: cu, - configUsecase: configUsecase, - assetUsecase: assetUsecase, + contests: contests, + config: config, + assets: assets, } // opt optGrp := engine.Group("/") { - opt := optGrp.Use(ath.AuthMiddleware(domain.PGuest)) + opt := optGrp.Use(auth.AuthMiddleware(domain.PGuest)) opt.GET("/api/contests", handler.onAPIGetContests()) opt.GET("/api/contests/:contest_id", handler.onAPIGetContest()) opt.GET("/api/contests/:contest_id/entries", handler.onAPIGetContestEntries()) @@ -43,7 +43,7 @@ func NewContestHandler(engine *gin.Engine, cu domain.ContestUsecase, // auth authGrp := engine.Group("/") { - authed := authGrp.Use(ath.AuthMiddleware(domain.PUser)) + authed := authGrp.Use(auth.AuthMiddleware(domain.PUser)) authed.POST("/api/contests/:contest_id/upload", handler.onAPISaveContestEntryMedia()) authed.GET("/api/contests/:contest_id/vote/:contest_entry_id/:direction", handler.onAPISaveContestEntryVote()) authed.POST("/api/contests/:contest_id/submit", handler.onAPISaveContestEntrySubmit()) @@ -53,7 +53,7 @@ func NewContestHandler(engine *gin.Engine, cu domain.ContestUsecase, // mods modGrp := engine.Group("/") { - mod := modGrp.Use(ath.AuthMiddleware(domain.PModerator)) + mod := modGrp.Use(auth.AuthMiddleware(domain.PModerator)) mod.POST("/api/contests", handler.onAPIPostContest()) mod.DELETE("/api/contests/:contest_id", handler.onAPIDeleteContest()) mod.PUT("/api/contests/:contest_id", handler.onAPIUpdateContest()) @@ -69,7 +69,7 @@ func (c *contestHandler) contestFromCtx(ctx *gin.Context) (domain.Contest, bool) } var contest domain.Contest - if errContests := c.contestUsecase.ContestByID(ctx, contestID, &contest); errContests != nil { + if errContests := c.contests.ContestByID(ctx, contestID, &contest); errContests != nil { httphelper.HandleErrInternal(ctx) return domain.Contest{}, false @@ -86,7 +86,7 @@ func (c *contestHandler) contestFromCtx(ctx *gin.Context) (domain.Contest, bool) func (c *contestHandler) onAPIGetContests() gin.HandlerFunc { return func(ctx *gin.Context) { - contests, errContests := c.contestUsecase.Contests(ctx, httphelper.CurrentUserProfile(ctx)) + contests, errContests := c.contests.Contests(ctx, httphelper.CurrentUserProfile(ctx)) if errContests != nil { httphelper.HandleErrInternal(ctx) @@ -117,7 +117,7 @@ func (c *contestHandler) onAPIGetContestEntries() gin.HandlerFunc { return } - entries, errEntries := c.contestUsecase.ContestEntries(ctx, contest.ContestID) + entries, errEntries := c.contests.ContestEntries(ctx, contest.ContestID) if errEntries != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to fetch contest entries", log.ErrAttr(errEntries)) @@ -136,7 +136,7 @@ func (c *contestHandler) onAPIPostContest() gin.HandlerFunc { return } - contest, errSave := c.contestUsecase.ContestSave(ctx, newContest) + contest, errSave := c.contests.ContestSave(ctx, newContest) if errSave != nil { httphelper.ErrorHandled(ctx, errSave) @@ -159,7 +159,7 @@ func (c *contestHandler) onAPIDeleteContest() gin.HandlerFunc { var contest domain.Contest - if errContest := c.contestUsecase.ContestByID(ctx, contestID, &contest); errContest != nil { + if errContest := c.contests.ContestByID(ctx, contestID, &contest); errContest != nil { if errors.Is(errContest, domain.ErrNoResult) { httphelper.ResponseErr(ctx, http.StatusNotFound, domain.ErrUnknownID) @@ -172,7 +172,7 @@ func (c *contestHandler) onAPIDeleteContest() gin.HandlerFunc { return } - if errDelete := c.contestUsecase.ContestDelete(ctx, contest.ContestID); errDelete != nil { + if errDelete := c.contests.ContestDelete(ctx, contest.ContestID); errDelete != nil { httphelper.HandleErrInternal(ctx) slog.Error("Error deleting contest", log.ErrAttr(errDelete)) @@ -194,7 +194,7 @@ func (c *contestHandler) onAPIUpdateContest() gin.HandlerFunc { return } - contest, errSave := c.contestUsecase.ContestSave(ctx, req) + contest, errSave := c.contests.ContestSave(ctx, req) if errSave != nil { httphelper.ErrorHandled(ctx, errSave) slog.Error("Error updating contest", log.ErrAttr(errSave)) @@ -245,7 +245,7 @@ func (c *contestHandler) onAPISaveContestEntryMedia() gin.HandlerFunc { authorID := httphelper.CurrentUserProfile(ctx).SteamID - asset, errCreate := c.assetUsecase.Create(ctx, authorID, "media", req.Name, mediaFile) + asset, errCreate := c.assets.Create(ctx, authorID, "media", req.Name, mediaFile) if errHandle := httphelper.ErrorHandledWithReturn(ctx, errCreate); errHandle != nil { slog.Error("Failed to save user contest media", log.ErrAttr(errHandle)) @@ -290,7 +290,7 @@ func (c *contestHandler) onAPISaveContestEntryVote() gin.HandlerFunc { return } - if errVote := c.contestUsecase.ContestEntryVote(ctx, contestID, contestEntryID, httphelper.CurrentUserProfile(ctx), direction == "up"); errVote != nil { + if errVote := c.contests.ContestEntryVote(ctx, contestID, contestEntryID, httphelper.CurrentUserProfile(ctx), direction == "up"); errVote != nil { if errors.Is(errVote, domain.ErrVoteDeleted) { ctx.JSON(http.StatusOK, voteResult{""}) @@ -325,7 +325,7 @@ func (c *contestHandler) onAPISaveContestEntrySubmit() gin.HandlerFunc { return } - existingEntries, errEntries := c.contestUsecase.ContestEntries(ctx, contest.ContestID) + existingEntries, errEntries := c.contests.ContestEntries(ctx, contest.ContestID) if errEntries != nil && !errors.Is(errEntries, domain.ErrNoResult) { httphelper.ResponseErr(ctx, http.StatusInternalServerError, domain.ErrContestLoadEntries) @@ -348,7 +348,7 @@ func (c *contestHandler) onAPISaveContestEntrySubmit() gin.HandlerFunc { steamID := httphelper.CurrentUserProfile(ctx).SteamID - asset, _, errAsset := c.assetUsecase.Get(ctx, req.AssetID) + asset, _, errAsset := c.assets.Get(ctx, req.AssetID) if errAsset != nil { httphelper.ResponseErr(ctx, http.StatusInternalServerError, domain.ErrEntryCreate) @@ -368,7 +368,7 @@ func (c *contestHandler) onAPISaveContestEntrySubmit() gin.HandlerFunc { return } - if errSave := c.contestUsecase.ContestEntrySave(ctx, entry); errSave != nil { + if errSave := c.contests.ContestEntrySave(ctx, entry); errSave != nil { httphelper.ResponseErr(ctx, http.StatusInternalServerError, domain.ErrEntrySave) return @@ -393,7 +393,7 @@ func (c *contestHandler) onAPIDeleteContestEntry() gin.HandlerFunc { var entry domain.ContestEntry - if errContest := c.contestUsecase.ContestEntry(ctx, contestEntryID, &entry); errContest != nil { + if errContest := c.contests.ContestEntry(ctx, contestEntryID, &entry); errContest != nil { if errors.Is(errContest, domain.ErrNoResult) { httphelper.ResponseErr(ctx, http.StatusNotFound, domain.ErrUnknownID) @@ -416,7 +416,7 @@ func (c *contestHandler) onAPIDeleteContestEntry() gin.HandlerFunc { var contest domain.Contest - if errContest := c.contestUsecase.ContestByID(ctx, entry.ContestID, &contest); errContest != nil { + if errContest := c.contests.ContestByID(ctx, entry.ContestID, &contest); errContest != nil { if errors.Is(errContest, domain.ErrNoResult) { httphelper.ResponseErr(ctx, http.StatusNotFound, domain.ErrUnknownID) @@ -439,7 +439,7 @@ func (c *contestHandler) onAPIDeleteContestEntry() gin.HandlerFunc { return } - if errDelete := c.contestUsecase.ContestEntryDelete(ctx, entry.ContestEntryID); errDelete != nil { + if errDelete := c.contests.ContestEntryDelete(ctx, entry.ContestEntryID); errDelete != nil { httphelper.ResponseErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Error deleting contest entry", log.ErrAttr(errDelete)) diff --git a/internal/contest/contest_usecase.go b/internal/contest/contest_usecase.go index f5d9ec32..4b7ea263 100644 --- a/internal/contest/contest_usecase.go +++ b/internal/contest/contest_usecase.go @@ -11,11 +11,11 @@ import ( ) type contestUsecase struct { - contestRepo domain.ContestRepository + repository domain.ContestRepository } -func NewContestUsecase(contestRepository domain.ContestRepository) domain.ContestUsecase { - return &contestUsecase{contestRepo: contestRepository} +func NewContestUsecase(repository domain.ContestRepository) domain.ContestUsecase { + return &contestUsecase{repository: repository} } func (c *contestUsecase) ContestSave(ctx context.Context, contest domain.Contest) (domain.Contest, error) { @@ -28,7 +28,7 @@ func (c *contestUsecase) ContestSave(ctx context.Context, contest domain.Contest contest.ContestID = newID } - if errSave := c.contestRepo.ContestSave(ctx, &contest); errSave != nil { + if errSave := c.repository.ContestSave(ctx, &contest); errSave != nil { return contest, errSave } @@ -40,11 +40,11 @@ func (c *contestUsecase) ContestSave(ctx context.Context, contest domain.Contest } func (c *contestUsecase) ContestByID(ctx context.Context, contestID uuid.UUID, contest *domain.Contest) error { - return c.contestRepo.ContestByID(ctx, contestID, contest) + return c.repository.ContestByID(ctx, contestID, contest) } func (c *contestUsecase) ContestDelete(ctx context.Context, contestID uuid.UUID) error { - if err := c.contestRepo.ContestDelete(ctx, contestID); err != nil { + if err := c.repository.ContestDelete(ctx, contestID); err != nil { return err } @@ -54,27 +54,27 @@ func (c *contestUsecase) ContestDelete(ctx context.Context, contestID uuid.UUID) } func (c *contestUsecase) ContestEntryDelete(ctx context.Context, contestEntryID uuid.UUID) error { - return c.contestRepo.ContestEntryDelete(ctx, contestEntryID) + return c.repository.ContestEntryDelete(ctx, contestEntryID) } func (c *contestUsecase) Contests(ctx context.Context, user domain.PersonInfo) ([]domain.Contest, error) { - return c.contestRepo.Contests(ctx, !user.HasPermission(domain.PModerator)) + return c.repository.Contests(ctx, !user.HasPermission(domain.PModerator)) } func (c *contestUsecase) ContestEntry(ctx context.Context, contestID uuid.UUID, entry *domain.ContestEntry) error { - return c.contestRepo.ContestEntry(ctx, contestID, entry) + return c.repository.ContestEntry(ctx, contestID, entry) } func (c *contestUsecase) ContestEntrySave(ctx context.Context, entry domain.ContestEntry) error { - return c.contestRepo.ContestEntrySave(ctx, entry) + return c.repository.ContestEntrySave(ctx, entry) } func (c *contestUsecase) ContestEntries(ctx context.Context, contestID uuid.UUID) ([]*domain.ContestEntry, error) { - return c.contestRepo.ContestEntries(ctx, contestID) + return c.repository.ContestEntries(ctx, contestID) } func (c *contestUsecase) ContestEntryVoteGet(ctx context.Context, contestEntryID uuid.UUID, steamID steamid.SteamID, record *domain.ContentVoteRecord) error { - return c.contestRepo.ContestEntryVoteGet(ctx, contestEntryID, steamID, record) + return c.repository.ContestEntryVoteGet(ctx, contestEntryID, steamID, record) } func (c *contestUsecase) ContestEntryVote(ctx context.Context, contestID uuid.UUID, contestEntryID uuid.UUID, user domain.PersonInfo, vote bool) error { @@ -91,7 +91,7 @@ func (c *contestUsecase) ContestEntryVote(ctx context.Context, contestID uuid.UU return domain.ErrBadRequest } - if err := c.contestRepo.ContestEntryVote(ctx, contestEntryID, user.GetSteamID(), vote); err != nil { + if err := c.repository.ContestEntryVote(ctx, contestEntryID, user.GetSteamID(), vote); err != nil { return err } @@ -103,9 +103,9 @@ func (c *contestUsecase) ContestEntryVote(ctx context.Context, contestID uuid.UU } func (c *contestUsecase) ContestEntryVoteDelete(ctx context.Context, contestEntryVoteID int64) error { - return c.contestRepo.ContestEntryVoteDelete(ctx, contestEntryVoteID) + return c.repository.ContestEntryVoteDelete(ctx, contestEntryVoteID) } func (c *contestUsecase) ContestEntryVoteUpdate(ctx context.Context, contestEntryVoteID int64, newVote bool) error { - return c.contestRepo.ContestEntryVoteUpdate(ctx, contestEntryVoteID, newVote) + return c.repository.ContestEntryVoteUpdate(ctx, contestEntryVoteID, newVote) } diff --git a/internal/demo/demo_service.go b/internal/demo/demo_service.go index 0824fcf4..6ed33c7e 100644 --- a/internal/demo/demo_service.go +++ b/internal/demo/demo_service.go @@ -11,12 +11,12 @@ import ( ) type demoHandler struct { - du domain.DemoUsecase + demos domain.DemoUsecase } func NewDemoHandler(engine *gin.Engine, du domain.DemoUsecase) { handler := demoHandler{ - du: du, + demos: du, } engine.POST("/api/demos", handler.onAPIPostDemosQuery()) @@ -25,7 +25,7 @@ func NewDemoHandler(engine *gin.Engine, du domain.DemoUsecase) { func (h demoHandler) onAPIGetCleanup() gin.HandlerFunc { return func(ctx *gin.Context) { - h.du.TriggerCleanup() + h.demos.TriggerCleanup() ctx.JSON(http.StatusOK, gin.H{}) } @@ -33,7 +33,7 @@ func (h demoHandler) onAPIGetCleanup() gin.HandlerFunc { func (h demoHandler) onAPIPostDemosQuery() gin.HandlerFunc { return func(ctx *gin.Context) { - demos, errDemos := h.du.GetDemos(ctx) + demos, errDemos := h.demos.GetDemos(ctx) if errDemos != nil { httphelper.ResponseErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to query demos", log.ErrAttr(errDemos)) diff --git a/internal/demo/demo_usecase.go b/internal/demo/demo_usecase.go index 276df318..88a433d6 100644 --- a/internal/demo/demo_usecase.go +++ b/internal/demo/demo_usecase.go @@ -25,15 +25,15 @@ type demoUsecase struct { cleanupChan chan any } -func NewDemoUsecase(bucket domain.Bucket, demoRepository domain.DemoRepository, assetUsecase domain.AssetUsecase, - configUsecase domain.ConfigUsecase, serversUsecase domain.ServersUsecase, +func NewDemoUsecase(bucket domain.Bucket, repository domain.DemoRepository, assets domain.AssetUsecase, + config domain.ConfigUsecase, servers domain.ServersUsecase, ) domain.DemoUsecase { return &demoUsecase{ bucket: bucket, - repository: demoRepository, - asset: assetUsecase, - config: configUsecase, - servers: serversUsecase, + repository: repository, + asset: assets, + config: config, + servers: servers, cleanupChan: make(chan any), } } diff --git a/internal/discord/discord_service_oauth.go b/internal/discord/discord_service_oauth.go index 35ad2621..d381a26b 100644 --- a/internal/discord/discord_service_oauth.go +++ b/internal/discord/discord_service_oauth.go @@ -12,21 +12,21 @@ import ( ) type discordOAuthHandler struct { - authUsecase domain.AuthUsecase - configUsecase domain.ConfigUsecase - personUsecase domain.PersonUsecase - discordUsecase domain.DiscordOAuthUsecase + auth domain.AuthUsecase + config domain.ConfigUsecase + persons domain.PersonUsecase + discord domain.DiscordOAuthUsecase } // NewDiscordOAuthHandler provides handlers for authentication with discord connect. -func NewDiscordOAuthHandler(engine *gin.Engine, authUsecase domain.AuthUsecase, configUsecase domain.ConfigUsecase, - personUsecase domain.PersonUsecase, discordUsecase domain.DiscordOAuthUsecase, +func NewDiscordOAuthHandler(engine *gin.Engine, auth domain.AuthUsecase, config domain.ConfigUsecase, + persons domain.PersonUsecase, discord domain.DiscordOAuthUsecase, ) { handler := discordOAuthHandler{ - authUsecase: authUsecase, - configUsecase: configUsecase, - personUsecase: personUsecase, - discordUsecase: discordUsecase, + auth: auth, + config: config, + persons: persons, + discord: discord, } engine.GET("/discord/oauth", handler.onOAuthDiscordCallback()) @@ -34,10 +34,10 @@ func NewDiscordOAuthHandler(engine *gin.Engine, authUsecase domain.AuthUsecase, authGrp := engine.Group("/") { // authed - auth := authGrp.Use(authUsecase.AuthMiddleware(domain.PUser)) - auth.GET("/api/discord/login", handler.onLogin()) - auth.GET("/api/discord/logout", handler.onLogout()) - auth.GET("/api/discord/user", handler.onGetDiscordUser()) + authed := authGrp.Use(auth.AuthMiddleware(domain.PUser)) + authed.GET("/api/discord/login", handler.onLogin()) + authed.GET("/api/discord/logout", handler.onLogout()) + authed.GET("/api/discord/user", handler.onGetDiscordUser()) } } @@ -45,7 +45,7 @@ func (h discordOAuthHandler) onLogin() gin.HandlerFunc { return func(ctx *gin.Context) { currentUser := httphelper.CurrentUserProfile(ctx) - loginURL, errURL := h.discordUsecase.CreateStatefulLoginURL(currentUser.SteamID) + loginURL, errURL := h.discord.CreateStatefulLoginURL(currentUser.SteamID) if errURL != nil { httphelper.ResponseErr(ctx, http.StatusBadRequest, nil) slog.Error("Failed to get state from query") @@ -63,7 +63,7 @@ func (h discordOAuthHandler) onOAuthDiscordCallback() gin.HandlerFunc { code := ctx.Query("code") if code == "" { slog.Error("Failed to get code from query") - ctx.Redirect(http.StatusTemporaryRedirect, h.configUsecase.ExtURLRaw("/settings?section=connections")) + ctx.Redirect(http.StatusTemporaryRedirect, h.config.ExtURLRaw("/settings?section=connections")) return } @@ -71,16 +71,16 @@ func (h discordOAuthHandler) onOAuthDiscordCallback() gin.HandlerFunc { state := ctx.Query("state") if state == "" { slog.Error("Failed to get state from query") - ctx.Redirect(http.StatusTemporaryRedirect, h.configUsecase.ExtURLRaw("/settings?section=connections")) + ctx.Redirect(http.StatusTemporaryRedirect, h.config.ExtURLRaw("/settings?section=connections")) return } - if err := h.discordUsecase.HandleOAuthCode(ctx, code, state); err != nil { + if err := h.discord.HandleOAuthCode(ctx, code, state); err != nil { slog.Error("Failed to get access token", log.ErrAttr(err)) } - ctx.Redirect(http.StatusTemporaryRedirect, h.configUsecase.ExtURLRaw("/settings?section=connections")) + ctx.Redirect(http.StatusTemporaryRedirect, h.config.ExtURLRaw("/settings?section=connections")) } } @@ -88,7 +88,7 @@ func (h discordOAuthHandler) onGetDiscordUser() gin.HandlerFunc { return func(ctx *gin.Context) { user := httphelper.CurrentUserProfile(ctx) - discord, errUser := h.discordUsecase.GetUserDetail(ctx, user.SteamID) + discord, errUser := h.discord.GetUserDetail(ctx, user.SteamID) if errUser != nil { if errors.Is(errUser, domain.ErrNoResult) { httphelper.ResponseErr(ctx, http.StatusNotFound, domain.ErrNotFound) @@ -110,7 +110,7 @@ func (h discordOAuthHandler) onLogout() gin.HandlerFunc { return func(ctx *gin.Context) { user := httphelper.CurrentUserProfile(ctx) - errUser := h.discordUsecase.Logout(ctx, user.SteamID) + errUser := h.discord.Logout(ctx, user.SteamID) if errUser != nil { if errors.Is(errUser, domain.ErrNoResult) { ctx.JSON(http.StatusOK, gin.H{}) diff --git a/internal/discord/discord_usecase.go b/internal/discord/discord_usecase.go index 5141dcb0..9ee5ba7f 100644 --- a/internal/discord/discord_usecase.go +++ b/internal/discord/discord_usecase.go @@ -11,28 +11,28 @@ import ( ) type discordUsecase struct { - dr domain.DiscordRepository - wfu domain.WordFilterUsecase + repository domain.DiscordRepository + wordFilters domain.WordFilterUsecase } -func NewDiscordUsecase(repository domain.DiscordRepository, wfu domain.WordFilterUsecase) domain.DiscordUsecase { - return &discordUsecase{dr: repository, wfu: wfu} +func NewDiscordUsecase(repository domain.DiscordRepository, wordFilters domain.WordFilterUsecase) domain.DiscordUsecase { + return &discordUsecase{repository: repository, wordFilters: wordFilters} } func (d discordUsecase) Shutdown(guildID string) { - d.dr.Shutdown(guildID) + d.repository.Shutdown(guildID) } func (d discordUsecase) RegisterHandler(cmd domain.Cmd, handler domain.SlashCommandHandler) error { - return d.dr.RegisterHandler(cmd, handler) + return d.repository.RegisterHandler(cmd, handler) } func (d discordUsecase) Start() error { - return d.dr.Start() + return d.repository.Start() } func (d discordUsecase) SendPayload(channelID domain.DiscordChannel, embed *discordgo.MessageEmbed) { - d.dr.SendPayload(channelID, embed) + d.repository.SendPayload(channelID, embed) } func (d discordUsecase) FilterAdd(ctx context.Context, user domain.PersonInfo, pattern string, isRegex bool) (*discordgo.MessageEmbed, error) { @@ -52,7 +52,7 @@ func (d discordUsecase) FilterAdd(ctx context.Context, user domain.PersonInfo, p UpdatedOn: time.Now(), } - filter, errFilterAdd := d.wfu.Create(ctx, user, newFilter) + filter, errFilterAdd := d.wordFilters.Create(ctx, user, newFilter) if errFilterAdd != nil { return nil, domain.ErrCommandFailed diff --git a/internal/discord/discord_usecase_oauth.go b/internal/discord/discord_usecase_oauth.go index fc20026b..c51870c8 100644 --- a/internal/discord/discord_usecase_oauth.go +++ b/internal/discord/discord_usecase_oauth.go @@ -17,16 +17,16 @@ import ( ) type discordOAuthUsecase struct { - configUsecase domain.ConfigUsecase - stateTracker *util.LoginStateTracker - repository domain.DiscordOAuthRepository + config domain.ConfigUsecase + state *util.LoginStateTracker + repository domain.DiscordOAuthRepository } -func NewDiscordOAuthUsecase(repository domain.DiscordOAuthRepository, configUsecase domain.ConfigUsecase) domain.DiscordOAuthUsecase { +func NewDiscordOAuthUsecase(repository domain.DiscordOAuthRepository, config domain.ConfigUsecase) domain.DiscordOAuthUsecase { return &discordOAuthUsecase{ - repository: repository, - configUsecase: configUsecase, - stateTracker: util.NewLoginStateTracker(), + repository: repository, + config: config, + state: util.NewLoginStateTracker(), } } @@ -78,7 +78,7 @@ func (d discordOAuthUsecase) RefreshOldTokens(ctx context.Context) { } func (d discordOAuthUsecase) fetchRefresh(ctx context.Context, credentials domain.DiscordCredential) (domain.DiscordCredential, error) { - conf := d.configUsecase.Config() + conf := d.config.Config() form := url.Values{} form.Set("client_id", conf.Discord.AppID) @@ -145,7 +145,7 @@ func (d discordOAuthUsecase) Logout(ctx context.Context, steamID steamid.SteamID return nil } - conf := d.configUsecase.Config() + conf := d.config.Config() form := url.Values{} form.Set("client_id", conf.Discord.AppID) @@ -173,7 +173,7 @@ func (d discordOAuthUsecase) Logout(ctx context.Context, steamID steamid.SteamID } func (d discordOAuthUsecase) CreateStatefulLoginURL(steamID steamid.SteamID) (string, error) { - config := d.configUsecase.Config() + config := d.config.Config() inviteLink, errParse := url.Parse("https://discord.com/oauth2/authorize") if errParse != nil { @@ -183,7 +183,7 @@ func (d discordOAuthUsecase) CreateStatefulLoginURL(steamID steamid.SteamID) (st values := inviteLink.Query() values.Set("client_id", config.Discord.AppID) values.Set("scope", "identify") - values.Set("state", d.stateTracker.Create(steamID)) + values.Set("state", d.state.Create(steamID)) values.Set("redirect_uri", config.ExtURLRaw("/discord/oauth")) values.Set("response_type", "code") @@ -195,7 +195,7 @@ func (d discordOAuthUsecase) CreateStatefulLoginURL(steamID steamid.SteamID) (st func (d discordOAuthUsecase) HandleOAuthCode(ctx context.Context, code string, state string) error { client := util.NewHTTPClient() - steamID, found := d.stateTracker.Get(state) + steamID, found := d.state.Get(state) if !found { return domain.ErrNotFound } @@ -262,7 +262,7 @@ func (d discordOAuthUsecase) fetchDiscordUser(ctx context.Context, client *http. } func (d discordOAuthUsecase) fetchToken(ctx context.Context, client *http.Client, code string) (domain.DiscordCredential, error) { - conf := d.configUsecase.Config() + conf := d.config.Config() form := url.Values{} form.Set("client_id", conf.Discord.AppID) diff --git a/internal/forum/forum_service.go b/internal/forum/forum_service.go index d4a32dab..98d11cb1 100644 --- a/internal/forum/forum_service.go +++ b/internal/forum/forum_service.go @@ -16,12 +16,12 @@ import ( ) type forumHandler struct { - fuc domain.ForumUsecase + forums domain.ForumUsecase } -func NewForumHandler(engine *gin.Engine, fuc domain.ForumUsecase, ath domain.AuthUsecase) { +func NewForumHandler(engine *gin.Engine, forums domain.ForumUsecase, auth domain.AuthUsecase) { handler := &forumHandler{ - fuc: fuc, + forums: forums, } engine.GET("/api/forum/active_users", handler.onAPIActiveUsers()) @@ -29,7 +29,7 @@ func NewForumHandler(engine *gin.Engine, fuc domain.ForumUsecase, ath domain.Aut // opt optGrp := engine.Group("/") { - opt := optGrp.Use(ath.AuthMiddleware(domain.PGuest)) + opt := optGrp.Use(auth.AuthMiddleware(domain.PGuest)) opt.GET("/api/forum/overview", handler.onAPIForumOverview()) opt.GET("/api/forum/messages/recent", handler.onAPIForumMessagesRecent()) opt.POST("/api/forum/threads", handler.onAPIForumThreads()) @@ -41,7 +41,7 @@ func NewForumHandler(engine *gin.Engine, fuc domain.ForumUsecase, ath domain.Aut // auth authedGrp := engine.Group("/") { - authed := authedGrp.Use(ath.AuthMiddleware(domain.PUser)) + authed := authedGrp.Use(auth.AuthMiddleware(domain.PUser)) authed.POST("/api/forum/forum/:forum_id/thread", handler.onAPIThreadCreate()) authed.POST("/api/forum/thread/:forum_thread_id/message", handler.onAPIThreadCreateReply()) authed.POST("/api/forum/message/:forum_message_id", handler.onAPIThreadMessageUpdate()) @@ -52,7 +52,7 @@ func NewForumHandler(engine *gin.Engine, fuc domain.ForumUsecase, ath domain.Aut // mod modGrp := engine.Group("/") { - mod := modGrp.Use(ath.AuthMiddleware(domain.PModerator)) + mod := modGrp.Use(auth.AuthMiddleware(domain.PModerator)) mod.POST("/api/forum/category", handler.onAPICreateForumCategory()) mod.GET("/api/forum/category/:forum_category_id", handler.onAPIForumCategory()) mod.POST("/api/forum/category/:forum_category_id", handler.onAPIUpdateForumCategory()) @@ -71,7 +71,7 @@ func (f *forumHandler) onAPIForumMessagesRecent() gin.HandlerFunc { return func(ctx *gin.Context) { user := httphelper.CurrentUserProfile(ctx) - messages, errThreads := f.fuc.ForumRecentActivity(ctx, 5, user.PermissionLevel) + messages, errThreads := f.forums.ForumRecentActivity(ctx, 5, user.PermissionLevel) if errThreads != nil { httphelper.HandleErrInternal(ctx) slog.Error("Could not load thread messages", log.ErrAttr(errThreads)) @@ -101,7 +101,7 @@ func (f *forumHandler) onAPICreateForumCategory() gin.HandlerFunc { TimeStamped: domain.NewTimeStamped(), } - if errSave := f.fuc.ForumCategorySave(ctx, &category); errSave != nil { + if errSave := f.forums.ForumCategorySave(ctx, &category); errSave != nil { httphelper.HandleErrInternal(ctx) slog.Error("Error creating new forum category", log.ErrAttr(errSave)) @@ -124,7 +124,7 @@ func (f *forumHandler) onAPIForumCategory() gin.HandlerFunc { var category domain.ForumCategory - if errGet := f.fuc.ForumCategory(ctx, forumCategoryID, &category); errGet != nil { + if errGet := f.forums.ForumCategory(ctx, forumCategoryID, &category); errGet != nil { httphelper.HandleErrInternal(ctx) slog.Error("Error fetching forum category", log.ErrAttr(errGet)) @@ -146,7 +146,7 @@ func (f *forumHandler) onAPIUpdateForumCategory() gin.HandlerFunc { } var category domain.ForumCategory - if errGet := f.fuc.ForumCategory(ctx, categoryID, &category); errGet != nil { + if errGet := f.forums.ForumCategory(ctx, categoryID, &category); errGet != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to get forum category", log.ErrAttr(errGet)) @@ -162,7 +162,7 @@ func (f *forumHandler) onAPIUpdateForumCategory() gin.HandlerFunc { category.Description = util.SanitizeUGC(req.Description) category.Ordering = req.Ordering - if errSave := f.fuc.ForumCategorySave(ctx, &category); errSave != nil { + if errSave := f.forums.ForumCategorySave(ctx, &category); errSave != nil { httphelper.HandleErrInternal(ctx) slog.Error("Error creating new forum category", log.ErrAttr(errSave)) @@ -195,7 +195,7 @@ func (f *forumHandler) onAPICreateForumForum() gin.HandlerFunc { TimeStamped: domain.NewTimeStamped(), } - if errSave := f.fuc.ForumSave(ctx, &forum); errSave != nil { + if errSave := f.forums.ForumSave(ctx, &forum); errSave != nil { httphelper.HandleErrInternal(ctx) slog.Error("Error creating new forum", log.ErrAttr(errSave)) @@ -217,7 +217,7 @@ func (f *forumHandler) onAPIUpdateForumForum() gin.HandlerFunc { } var forum domain.Forum - if errGet := f.fuc.Forum(ctx, forumID, &forum); errGet != nil { + if errGet := f.forums.Forum(ctx, forumID, &forum); errGet != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to update forum", log.ErrAttr(errGet), slog.Int("forum_id", forum.ForumID)) @@ -235,7 +235,7 @@ func (f *forumHandler) onAPIUpdateForumForum() gin.HandlerFunc { forum.Ordering = req.Ordering forum.PermissionLevel = req.PermissionLevel - if errSave := f.fuc.ForumSave(ctx, &forum); errSave != nil { + if errSave := f.forums.ForumSave(ctx, &forum); errSave != nil { httphelper.HandleErrInternal(ctx) slog.Error("Error updating forum", log.ErrAttr(errSave)) @@ -262,7 +262,7 @@ func (f *forumHandler) onAPIThreadCreate() gin.HandlerFunc { return func(ctx *gin.Context) { user := httphelper.CurrentUserProfile(ctx) - f.fuc.Touch(user) + f.forums.Touch(user) forumID, errForumID := httphelper.GetIntParam(ctx, "forum_id") if errForumID != nil { @@ -290,7 +290,7 @@ func (f *forumHandler) onAPIThreadCreate() gin.HandlerFunc { } var forum domain.Forum - if errForum := f.fuc.Forum(ctx, forumID, &forum); errForum != nil { + if errForum := f.forums.Forum(ctx, forumID, &forum); errForum != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to get forum", log.ErrAttr(errForum)) @@ -301,7 +301,7 @@ func (f *forumHandler) onAPIThreadCreate() gin.HandlerFunc { thread.Sticky = req.Sticky thread.Locked = req.Locked - if errSaveThread := f.fuc.ForumThreadSave(ctx, &thread); errSaveThread != nil { + if errSaveThread := f.forums.ForumThreadSave(ctx, &thread); errSaveThread != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to save new thread", log.ErrAttr(errSaveThread)) @@ -310,10 +310,10 @@ func (f *forumHandler) onAPIThreadCreate() gin.HandlerFunc { message := thread.NewMessage(user.SteamID, req.BodyMD) - if errSaveMessage := f.fuc.ForumMessageSave(ctx, &message); errSaveMessage != nil { + if errSaveMessage := f.forums.ForumMessageSave(ctx, &message); errSaveMessage != nil { // Drop created thread. // TODO transaction - if errRollback := f.fuc.ForumThreadDelete(ctx, thread.ForumThreadID); errRollback != nil { + if errRollback := f.forums.ForumThreadDelete(ctx, thread.ForumThreadID); errRollback != nil { slog.Error("Failed to rollback new thread", log.ErrAttr(errRollback)) } @@ -324,7 +324,7 @@ func (f *forumHandler) onAPIThreadCreate() gin.HandlerFunc { return } - if errIncr := f.fuc.ForumIncrMessageCount(ctx, forum.ForumID, true); errIncr != nil { + if errIncr := f.forums.ForumIncrMessageCount(ctx, forum.ForumID, true); errIncr != nil { httphelper.ResponseErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to increment message count", log.ErrAttr(errIncr)) @@ -371,7 +371,7 @@ func (f *forumHandler) onAPIThreadUpdate() gin.HandlerFunc { } var thread domain.ForumThread - if errGet := f.fuc.ForumThread(ctx, forumThreadID, &thread); errGet != nil { + if errGet := f.forums.ForumThread(ctx, forumThreadID, &thread); errGet != nil { if errors.Is(errGet, domain.ErrNoResult) { httphelper.ResponseErr(ctx, http.StatusNotFound, domain.ErrNotFound) slog.Warn("Requested unknown forum thread", log.ErrAttr(errGet)) @@ -393,7 +393,7 @@ func (f *forumHandler) onAPIThreadUpdate() gin.HandlerFunc { thread.Sticky = req.Sticky thread.Locked = req.Locked - if errDelete := f.fuc.ForumThreadSave(ctx, &thread); errDelete != nil { + if errDelete := f.forums.ForumThreadSave(ctx, &thread); errDelete != nil { httphelper.ResponseErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to update thread", log.ErrAttr(errDelete)) @@ -415,7 +415,7 @@ func (f *forumHandler) onAPIThreadDelete() gin.HandlerFunc { } var thread domain.ForumThread - if errGet := f.fuc.ForumThread(ctx, forumThreadID, &thread); errGet != nil { + if errGet := f.forums.ForumThread(ctx, forumThreadID, &thread); errGet != nil { if errors.Is(errGet, domain.ErrNoResult) { httphelper.HandleErrNotFound(ctx) slog.Warn("Failed to get thread", slog.Int64("forum_thread_id", forumThreadID)) @@ -427,7 +427,7 @@ func (f *forumHandler) onAPIThreadDelete() gin.HandlerFunc { return } - if errDelete := f.fuc.ForumThreadDelete(ctx, thread.ForumThreadID); errDelete != nil { + if errDelete := f.forums.ForumThreadDelete(ctx, thread.ForumThreadID); errDelete != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to delete thread", log.ErrAttr(errDelete)) @@ -435,7 +435,7 @@ func (f *forumHandler) onAPIThreadDelete() gin.HandlerFunc { } var forum domain.Forum - if errForum := f.fuc.Forum(ctx, thread.ForumID, &forum); errForum != nil { + if errForum := f.forums.Forum(ctx, thread.ForumID, &forum); errForum != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to load forum", log.ErrAttr(errForum)) @@ -444,7 +444,7 @@ func (f *forumHandler) onAPIThreadDelete() gin.HandlerFunc { forum.CountThreads-- - if errSave := f.fuc.ForumSave(ctx, &forum); errSave != nil { + if errSave := f.forums.ForumSave(ctx, &forum); errSave != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to save thread count", log.ErrAttr(errSave)) @@ -463,7 +463,7 @@ func (f *forumHandler) onAPIThreadMessageUpdate() gin.HandlerFunc { return func(ctx *gin.Context) { currentUser := httphelper.CurrentUserProfile(ctx) - f.fuc.Touch(currentUser) + f.forums.Touch(currentUser) forumMessageID, errForumMessageID := httphelper.GetInt64Param(ctx, "forum_message_id") if errForumMessageID != nil { @@ -479,7 +479,7 @@ func (f *forumHandler) onAPIThreadMessageUpdate() gin.HandlerFunc { } var message domain.ForumMessage - if errMessage := f.fuc.ForumMessage(ctx, forumMessageID, &message); errMessage != nil { + if errMessage := f.forums.ForumMessage(ctx, forumMessageID, &message); errMessage != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to load forum message", log.ErrAttr(errMessage)) @@ -502,7 +502,7 @@ func (f *forumHandler) onAPIThreadMessageUpdate() gin.HandlerFunc { message.BodyMD = req.BodyMD - if errSave := f.fuc.ForumMessageSave(ctx, &message); errSave != nil { + if errSave := f.forums.ForumMessageSave(ctx, &message); errSave != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to update forum message", slog.Int64("forum_message_id", message.ForumMessageID)) @@ -524,7 +524,7 @@ func (f *forumHandler) onAPIMessageDelete() gin.HandlerFunc { } var message domain.ForumMessage - if err := f.fuc.ForumMessage(ctx, forumMessageID, &message); err != nil { + if err := f.forums.ForumMessage(ctx, forumMessageID, &message); err != nil { if errors.Is(err, domain.ErrNoResult) { httphelper.HandleErrNotFound(ctx) slog.Warn("Cannot get message, does not exist", slog.Int64("forum_message_id", forumMessageID)) @@ -537,7 +537,7 @@ func (f *forumHandler) onAPIMessageDelete() gin.HandlerFunc { } var thread domain.ForumThread - if err := f.fuc.ForumThread(ctx, message.ForumThreadID, &thread); err != nil { + if err := f.forums.ForumThread(ctx, message.ForumThreadID, &thread); err != nil { if errors.Is(err, domain.ErrNoResult) { httphelper.HandleErrNotFound(ctx) slog.Warn("Failed to load forum thread. Does not exist.", slog.Int64("forum_thread_id", message.ForumThreadID)) @@ -555,7 +555,7 @@ func (f *forumHandler) onAPIMessageDelete() gin.HandlerFunc { return } - messages, errMessage := f.fuc.ForumMessages(ctx, domain.ThreadMessagesQuery{ForumThreadID: message.ForumThreadID}) + messages, errMessage := f.forums.ForumMessages(ctx, domain.ThreadMessagesQuery{ForumThreadID: message.ForumThreadID}) if errMessage != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to fetch forum messages", log.ErrAttr(errMessage)) @@ -566,7 +566,7 @@ func (f *forumHandler) onAPIMessageDelete() gin.HandlerFunc { isThreadParent := messages[0].ForumMessageID == message.ForumMessageID if isThreadParent { - if err := f.fuc.ForumThreadDelete(ctx, message.ForumThreadID); err != nil { + if err := f.forums.ForumThreadDelete(ctx, message.ForumThreadID); err != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to delete forum thread", log.ErrAttr(err), slog.Int64("forum_thread_id", message.ForumThreadID)) @@ -575,7 +575,7 @@ func (f *forumHandler) onAPIMessageDelete() gin.HandlerFunc { // Delete the thread if it's the first message var forum domain.Forum - if errForum := f.fuc.Forum(ctx, thread.ForumID, &forum); errForum != nil { + if errForum := f.forums.Forum(ctx, thread.ForumID, &forum); errForum != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to load forum", log.ErrAttr(errForum), slog.Int("forum_id", thread.ForumID)) @@ -584,7 +584,7 @@ func (f *forumHandler) onAPIMessageDelete() gin.HandlerFunc { forum.CountThreads-- - if errSave := f.fuc.ForumSave(ctx, &forum); errSave != nil { + if errSave := f.forums.ForumSave(ctx, &forum); errSave != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to save thread count", log.ErrAttr(errSave)) @@ -593,7 +593,7 @@ func (f *forumHandler) onAPIMessageDelete() gin.HandlerFunc { slog.Error("Thread deleted due to parent deletion", slog.Int64("forum_thread_id", thread.ForumThreadID)) } else { - if errDelete := f.fuc.ForumMessageDelete(ctx, message.ForumMessageID); errDelete != nil { + if errDelete := f.forums.ForumMessageDelete(ctx, message.ForumMessageID); errDelete != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to delete message", log.ErrAttr(errDelete)) @@ -613,7 +613,7 @@ func (f *forumHandler) onAPIThreadCreateReply() gin.HandlerFunc { return func(ctx *gin.Context) { currentUser := httphelper.CurrentUserProfile(ctx) - f.fuc.Touch(currentUser) + f.forums.Touch(currentUser) forumThreadID, errForumID := httphelper.GetInt64Param(ctx, "forum_thread_id") if errForumID != nil { @@ -624,7 +624,7 @@ func (f *forumHandler) onAPIThreadCreateReply() gin.HandlerFunc { } var thread domain.ForumThread - if errThread := f.fuc.ForumThread(ctx, forumThreadID, &thread); errThread != nil { + if errThread := f.forums.ForumThread(ctx, forumThreadID, &thread); errThread != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to load forum thread", log.ErrAttr(errThread), slog.Int64("forum_thread_id", forumThreadID)) @@ -651,7 +651,7 @@ func (f *forumHandler) onAPIThreadCreateReply() gin.HandlerFunc { } newMessage := thread.NewMessage(currentUser.SteamID, req.BodyMD) - if errSave := f.fuc.ForumMessageSave(ctx, &newMessage); errSave != nil { + if errSave := f.forums.ForumMessageSave(ctx, &newMessage); errSave != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to same forum message", log.ErrAttr(errSave)) @@ -659,14 +659,14 @@ func (f *forumHandler) onAPIThreadCreateReply() gin.HandlerFunc { } var message domain.ForumMessage - if errFetch := f.fuc.ForumMessage(ctx, newMessage.ForumMessageID, &message); errFetch != nil { + if errFetch := f.forums.ForumMessage(ctx, newMessage.ForumMessageID, &message); errFetch != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to load forum message", log.ErrAttr(errFetch)) return } - if errIncr := f.fuc.ForumIncrMessageCount(ctx, thread.ForumID, true); errIncr != nil { + if errIncr := f.forums.ForumIncrMessageCount(ctx, thread.ForumID, true); errIncr != nil { httphelper.HandleErrInternal(ctx) slog.Error("Failed to increment message count", log.ErrAttr(errIncr)) } @@ -688,9 +688,9 @@ func (f *forumHandler) onAPIForumOverview() gin.HandlerFunc { return func(ctx *gin.Context) { currentUser := httphelper.CurrentUserProfile(ctx) - f.fuc.Touch(currentUser) + f.forums.Touch(currentUser) - categories, errCats := f.fuc.ForumCategories(ctx) + categories, errCats := f.forums.ForumCategories(ctx) if errCats != nil { httphelper.HandleErrInternal(ctx) slog.Error("Could not load categories", log.ErrAttr(errCats)) @@ -698,7 +698,7 @@ func (f *forumHandler) onAPIForumOverview() gin.HandlerFunc { return } - currentForums, errForums := f.fuc.Forums(ctx) + currentForums, errForums := f.forums.Forums(ctx) if errForums != nil { httphelper.ResponseErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Could not load forums", log.ErrAttr(errForums)) @@ -730,14 +730,14 @@ func (f *forumHandler) onAPIForumThreads() gin.HandlerFunc { return func(ctx *gin.Context) { currentUser := httphelper.CurrentUserProfile(ctx) - f.fuc.Touch(currentUser) + f.forums.Touch(currentUser) var tqf domain.ThreadQueryFilter if !httphelper.Bind(ctx, &tqf) { return } - threads, errThreads := f.fuc.ForumThreads(ctx, tqf) + threads, errThreads := f.forums.ForumThreads(ctx, tqf) if errThreads != nil { httphelper.HandleErrInternal(ctx) slog.Error("Could not load threads", log.ErrAttr(errThreads), slog.Int("forum_id", tqf.ForumID)) @@ -746,7 +746,7 @@ func (f *forumHandler) onAPIForumThreads() gin.HandlerFunc { } var forum domain.Forum - if err := f.fuc.Forum(ctx, tqf.ForumID, &forum); err != nil { + if err := f.forums.Forum(ctx, tqf.ForumID, &forum); err != nil { httphelper.HandleErrInternal(ctx) slog.Error("Could not load forum", log.ErrAttr(errThreads), slog.Int("forum_id", tqf.ForumID)) @@ -768,7 +768,7 @@ func (f *forumHandler) onAPIForumThread() gin.HandlerFunc { return func(ctx *gin.Context) { currentUser := httphelper.CurrentUserProfile(ctx) - f.fuc.Touch(currentUser) + f.forums.Touch(currentUser) forumThreadID, errID := httphelper.GetInt64Param(ctx, "forum_thread_id") if errID != nil { @@ -779,7 +779,7 @@ func (f *forumHandler) onAPIForumThread() gin.HandlerFunc { } var thread domain.ForumThread - if errThreads := f.fuc.ForumThread(ctx, forumThreadID, &thread); errThreads != nil { + if errThreads := f.forums.ForumThread(ctx, forumThreadID, &thread); errThreads != nil { if errors.Is(errThreads, domain.ErrNoResult) { httphelper.HandleErrNotFound(ctx) } else { @@ -792,7 +792,7 @@ func (f *forumHandler) onAPIForumThread() gin.HandlerFunc { ctx.JSON(http.StatusOK, thread) - if err := f.fuc.ForumThreadIncrView(ctx, forumThreadID); err != nil { + if err := f.forums.ForumThreadIncrView(ctx, forumThreadID); err != nil { slog.Error("Failed to increment thread view count", log.ErrAttr(err), slog.Int64("forum_thread_id", forumThreadID)) } } @@ -812,7 +812,7 @@ func (f *forumHandler) onAPIForum() gin.HandlerFunc { var forum domain.Forum - if errForum := f.fuc.Forum(ctx, forumID, &forum); errForum != nil { + if errForum := f.forums.Forum(ctx, forumID, &forum); errForum != nil { httphelper.HandleErrInternal(ctx) slog.Error("Could not load forum", log.ErrAttr(errForum), slog.Int("forum_id", forumID)) @@ -836,7 +836,7 @@ func (f *forumHandler) onAPIForumMessages() gin.HandlerFunc { return } - messages, errMessages := f.fuc.ForumMessages(ctx, queryFilter) + messages, errMessages := f.forums.ForumMessages(ctx, queryFilter) if errMessages != nil { httphelper.HandleErrInternal(ctx) slog.Error("Could not load thread messages", log.ErrAttr(errMessages)) @@ -844,7 +844,7 @@ func (f *forumHandler) onAPIForumMessages() gin.HandlerFunc { return } - activeUsers := f.fuc.Current() + activeUsers := f.forums.Current() for idx := range messages { for _, activity := range activeUsers { @@ -871,7 +871,7 @@ func (f *forumHandler) onAPIActiveUsers() gin.HandlerFunc { return func(ctx *gin.Context) { var results []userActivity - for _, act := range f.fuc.Current() { + for _, act := range f.forums.Current() { results = append(results, userActivity{ SteamID: act.Person.SteamID, Personaname: act.Person.Name, diff --git a/internal/match/match_repository.go b/internal/match/match_repository.go index 3e275e70..6659e15b 100644 --- a/internal/match/match_repository.go +++ b/internal/match/match_repository.go @@ -16,32 +16,32 @@ import ( ) type matchRepository struct { - database database.Database - personUsecase domain.PersonUsecase - discordUsecase domain.DiscordUsecase - serversUsecase domain.ServersUsecase - stateUsecase domain.StateUsecase - summarizer *Summarizer - wm fp.MutexMap[logparse.Weapon, int] - events chan logparse.ServerEvent - broadcaster *fp.Broadcaster[logparse.EventType, logparse.ServerEvent] - matchUUIDMap fp.MutexMap[int, uuid.UUID] + database database.Database + persons domain.PersonUsecase + discord domain.DiscordUsecase + servers domain.ServersUsecase + state domain.StateUsecase + summarizer *Summarizer + wm fp.MutexMap[logparse.Weapon, int] + events chan logparse.ServerEvent + broadcaster *fp.Broadcaster[logparse.EventType, logparse.ServerEvent] + matchUUIDMap fp.MutexMap[int, uuid.UUID] } func NewMatchRepository(broadcaster *fp.Broadcaster[logparse.EventType, logparse.ServerEvent], - database database.Database, personUsecase domain.PersonUsecase, serversUsecase domain.ServersUsecase, discordUsecase domain.DiscordUsecase, - stu domain.StateUsecase, weaponMap fp.MutexMap[logparse.Weapon, int], + database database.Database, personUsecase domain.PersonUsecase, servers domain.ServersUsecase, discord domain.DiscordUsecase, + state domain.StateUsecase, weaponMap fp.MutexMap[logparse.Weapon, int], ) domain.MatchRepository { matchRepo := &matchRepository{ - database: database, - personUsecase: personUsecase, - serversUsecase: serversUsecase, - discordUsecase: discordUsecase, - stateUsecase: stu, - wm: weaponMap, - broadcaster: broadcaster, - matchUUIDMap: fp.NewMutexMap[int, uuid.UUID](), - events: make(chan logparse.ServerEvent), + database: database, + persons: personUsecase, + servers: servers, + discord: discord, + state: state, + wm: weaponMap, + broadcaster: broadcaster, + matchUUIDMap: fp.NewMutexMap[int, uuid.UUID](), + events: make(chan logparse.ServerEvent), } matchRepo.summarizer = newMatchSummarizer(matchRepo.events, matchRepo.onMatchComplete) @@ -60,13 +60,13 @@ func (r *matchRepository) EndMatch(endTrigger domain.MatchTrigger) { func (r *matchRepository) onMatchComplete(ctx context.Context, matchContext *activeMatchContext) error { const minPlayers = 6 - server, found := r.stateUsecase.ByServerID(matchContext.server.ServerID) + server, found := r.state.ByServerID(matchContext.server.ServerID) if found && server.Name != "" { matchContext.match.Title = server.Name } - fullServer, err := r.serversUsecase.GetServer(ctx, server.ServerID) + fullServer, err := r.servers.GetServer(ctx, server.ServerID) if err != nil { return errors.Join(err, domain.ErrLoadServer) } @@ -96,7 +96,7 @@ func (r *matchRepository) onMatchComplete(ctx context.Context, matchContext *act return errors.Join(errResult, domain.ErrLoadMatch) } - go r.discordUsecase.SendPayload(domain.ChannelPublicMatchLog, discord.MatchMessage(result, "")) + go r.discord.SendPayload(domain.ChannelPublicMatchLog, discord.MatchMessage(result, "")) return nil } @@ -652,7 +652,7 @@ func (r *matchRepository) MatchSave(ctx context.Context, match *logparse.Match, continue } - _, errPlayer := r.personUsecase.GetOrCreatePersonBySteamID(ctx, player.SteamID) + _, errPlayer := r.persons.GetOrCreatePersonBySteamID(ctx, player.SteamID) if errPlayer != nil { if errRollback := transaction.Rollback(ctx); errRollback != nil { return errors.Join(errRollback, domain.ErrTxRollback) diff --git a/internal/match/match_service.go b/internal/match/match_service.go index cfec5f3c..879821bf 100644 --- a/internal/match/match_service.go +++ b/internal/match/match_service.go @@ -22,7 +22,7 @@ type matchHandler struct { // todo move data updaters to repository. func NewMatchHandler(ctx context.Context, engine *gin.Engine, matches domain.MatchUsecase, servers domain.ServersUsecase, - ath domain.AuthUsecase, config domain.ConfigUsecase, + auth domain.AuthUsecase, config domain.ConfigUsecase, ) { handler := matchHandler{matches: matches, servers: servers, config: config} @@ -31,7 +31,7 @@ func NewMatchHandler(ctx context.Context, engine *gin.Engine, matches domain.Mat // authed authedGrp := engine.Group("/") { - authed := authedGrp.Use(ath.AuthMiddleware(domain.PUser)) + authed := authedGrp.Use(auth.AuthMiddleware(domain.PUser)) authed.POST("/api/logs", handler.onAPIGetMatches()) authed.GET("/api/log/:match_id", handler.onAPIGetMatch()) authed.GET("/api/stats/weapons", handler.onAPIGetStatsWeaponsOverall(ctx)) diff --git a/internal/match/match_usecase.go b/internal/match/match_usecase.go index af97ff0a..ecdec1f1 100644 --- a/internal/match/match_usecase.go +++ b/internal/match/match_usecase.go @@ -12,20 +12,20 @@ import ( ) type matchUsecase struct { - mr domain.MatchRepository - su domain.StateUsecase - sv domain.ServersUsecase - du domain.DiscordUsecase + repository domain.MatchRepository + state domain.StateUsecase + servers domain.ServersUsecase + discord domain.DiscordUsecase } -func NewMatchUsecase(matchRepository domain.MatchRepository, stateUsecase domain.StateUsecase, serversUsecase domain.ServersUsecase, - discordUsecase domain.DiscordUsecase, +func NewMatchUsecase(repository domain.MatchRepository, state domain.StateUsecase, servers domain.ServersUsecase, + discord domain.DiscordUsecase, ) domain.MatchUsecase { return &matchUsecase{ - mr: matchRepository, - su: stateUsecase, - sv: serversUsecase, - du: discordUsecase, + repository: repository, + state: state, + servers: servers, + discord: discord, } } @@ -43,23 +43,23 @@ func (m matchUsecase) StartMatch(server domain.Server, mapName string, demoName DemoName: demoName, } - m.mr.StartMatch(trigger) + m.repository.StartMatch(trigger) return matchUUID, nil } func (m matchUsecase) EndMatch(ctx context.Context, serverID int) (uuid.UUID, error) { - matchID, found := m.mr.GetMatchIDFromServerID(serverID) + matchID, found := m.repository.GetMatchIDFromServerID(serverID) if !found { return matchID, domain.ErrLoadMatch } - server, errServer := m.sv.GetServer(ctx, serverID) + server, errServer := m.servers.GetServer(ctx, serverID) if errServer != nil { return matchID, errors.Join(errServer, domain.ErrUnknownServer) } - m.mr.EndMatch(domain.MatchTrigger{ + m.repository.EndMatch(domain.MatchTrigger{ Type: domain.MatchTriggerEnd, UUID: matchID, Server: server, @@ -69,90 +69,90 @@ func (m matchUsecase) EndMatch(ctx context.Context, serverID int) (uuid.UUID, er } func (m matchUsecase) GetMatchIDFromServerID(serverID int) (uuid.UUID, bool) { - return m.mr.GetMatchIDFromServerID(serverID) + return m.repository.GetMatchIDFromServerID(serverID) } func (m matchUsecase) Matches(ctx context.Context, opts domain.MatchesQueryOpts) ([]domain.MatchSummary, int64, error) { - return m.mr.Matches(ctx, opts) + return m.repository.Matches(ctx, opts) } func (m matchUsecase) MatchGetByID(ctx context.Context, matchID uuid.UUID, match *domain.MatchResult) error { - return m.mr.MatchGetByID(ctx, matchID, match) + return m.repository.MatchGetByID(ctx, matchID, match) } // todo hide. func (m matchUsecase) MatchSave(ctx context.Context, match *logparse.Match, weaponMap fp.MutexMap[logparse.Weapon, int]) error { - return m.mr.MatchSave(ctx, match, weaponMap) + return m.repository.MatchSave(ctx, match, weaponMap) } func (m matchUsecase) StatsPlayerClass(ctx context.Context, sid64 steamid.SteamID) (domain.PlayerClassStatsCollection, error) { - return m.mr.StatsPlayerClass(ctx, sid64) + return m.repository.StatsPlayerClass(ctx, sid64) } func (m matchUsecase) StatsPlayerWeapons(ctx context.Context, sid64 steamid.SteamID) ([]domain.PlayerWeaponStats, error) { - return m.mr.StatsPlayerWeapons(ctx, sid64) + return m.repository.StatsPlayerWeapons(ctx, sid64) } func (m matchUsecase) StatsPlayerKillstreaks(ctx context.Context, sid64 steamid.SteamID) ([]domain.PlayerKillstreakStats, error) { - return m.mr.StatsPlayerKillstreaks(ctx, sid64) + return m.repository.StatsPlayerKillstreaks(ctx, sid64) } func (m matchUsecase) StatsPlayerMedic(ctx context.Context, sid64 steamid.SteamID) ([]domain.PlayerMedicStats, error) { - return m.mr.StatsPlayerMedic(ctx, sid64) + return m.repository.StatsPlayerMedic(ctx, sid64) } func (m matchUsecase) PlayerStats(ctx context.Context, steamID steamid.SteamID, stats *domain.PlayerStats) error { - return m.mr.PlayerStats(ctx, steamID, stats) + return m.repository.PlayerStats(ctx, steamID, stats) } func (m matchUsecase) WeaponsOverall(ctx context.Context) ([]domain.WeaponsOverallResult, error) { - return m.mr.WeaponsOverall(ctx) + return m.repository.WeaponsOverall(ctx) } func (m matchUsecase) GetMapUsageStats(ctx context.Context) ([]domain.MapUseDetail, error) { - return m.mr.GetMapUsageStats(ctx) + return m.repository.GetMapUsageStats(ctx) } func (m matchUsecase) Weapons(ctx context.Context) ([]domain.Weapon, error) { - return m.mr.Weapons(ctx) + return m.repository.Weapons(ctx) } func (m matchUsecase) SaveWeapon(ctx context.Context, weapon *domain.Weapon) error { - return m.mr.SaveWeapon(ctx, weapon) + return m.repository.SaveWeapon(ctx, weapon) } func (m matchUsecase) GetWeaponByKey(ctx context.Context, key logparse.Weapon, weapon *domain.Weapon) error { - return m.mr.GetWeaponByKey(ctx, key, weapon) + return m.repository.GetWeaponByKey(ctx, key, weapon) } func (m matchUsecase) GetWeaponByID(ctx context.Context, weaponID int, weapon *domain.Weapon) error { - return m.mr.GetWeaponByID(ctx, weaponID, weapon) + return m.repository.GetWeaponByID(ctx, weaponID, weapon) } func (m matchUsecase) LoadWeapons(ctx context.Context, weaponMap fp.MutexMap[logparse.Weapon, int]) error { - return m.mr.LoadWeapons(ctx, weaponMap) + return m.repository.LoadWeapons(ctx, weaponMap) } func (m matchUsecase) WeaponsOverallTopPlayers(ctx context.Context, weaponID int) ([]domain.PlayerWeaponResult, error) { - return m.mr.WeaponsOverallTopPlayers(ctx, weaponID) + return m.repository.WeaponsOverallTopPlayers(ctx, weaponID) } func (m matchUsecase) WeaponsOverallByPlayer(ctx context.Context, steamID steamid.SteamID) ([]domain.WeaponsOverallResult, error) { - return m.mr.WeaponsOverallByPlayer(ctx, steamID) + return m.repository.WeaponsOverallByPlayer(ctx, steamID) } func (m matchUsecase) PlayersOverallByKills(ctx context.Context, count int) ([]domain.PlayerWeaponResult, error) { - return m.mr.PlayersOverallByKills(ctx, count) + return m.repository.PlayersOverallByKills(ctx, count) } func (m matchUsecase) HealersOverallByHealing(ctx context.Context, count int) ([]domain.HealingOverallResult, error) { - return m.mr.HealersOverallByHealing(ctx, count) + return m.repository.HealersOverallByHealing(ctx, count) } func (m matchUsecase) PlayerOverallClassStats(ctx context.Context, steamID steamid.SteamID) ([]domain.PlayerClassOverallResult, error) { - return m.mr.PlayerOverallClassStats(ctx, steamID) + return m.repository.PlayerOverallClassStats(ctx, steamID) } func (m matchUsecase) PlayerOverallStats(ctx context.Context, steamID steamid.SteamID, por *domain.PlayerOverallResult) error { - return m.mr.PlayerOverallStats(ctx, steamID, por) + return m.repository.PlayerOverallStats(ctx, steamID, por) } diff --git a/internal/network/network_usecase.go b/internal/network/network_usecase.go index 9802a6a5..d2ef64fb 100644 --- a/internal/network/network_usecase.go +++ b/internal/network/network_usecase.go @@ -19,20 +19,20 @@ import ( ) type networkUsecase struct { - nr domain.NetworkRepository - pu domain.PersonUsecase - config domain.ConfigUsecase - eb *fp.Broadcaster[logparse.EventType, logparse.ServerEvent] + repository domain.NetworkRepository + persons domain.PersonUsecase + config domain.ConfigUsecase + eb *fp.Broadcaster[logparse.EventType, logparse.ServerEvent] } func NewNetworkUsecase(broadcaster *fp.Broadcaster[logparse.EventType, logparse.ServerEvent], - repository domain.NetworkRepository, personUsecase domain.PersonUsecase, config domain.ConfigUsecase, + repository domain.NetworkRepository, persons domain.PersonUsecase, config domain.ConfigUsecase, ) domain.NetworkUsecase { return networkUsecase{ - nr: repository, - eb: broadcaster, - pu: personUsecase, - config: config, + repository: repository, + eb: broadcaster, + persons: persons, + config: config, } } @@ -68,7 +68,7 @@ func (u networkUsecase) Start(ctx context.Context) { } // Maybe ignore these and wait for connect call to create? - _, errPerson := u.pu.GetOrCreatePersonBySteamID(ctx, newServerEvent.SID) + _, errPerson := u.persons.GetOrCreatePersonBySteamID(ctx, newServerEvent.SID) if errPerson != nil && !errors.Is(errPerson, domain.ErrDuplicate) { slog.Error("Failed to fetch connecting person", slog.String("steam_id", newServerEvent.SID.String()), log.ErrAttr(errPerson)) @@ -84,7 +84,7 @@ func (u networkUsecase) Start(ctx context.Context) { } lCtx, cancel := context.WithTimeout(ctx, time.Second*5) - if errChat := u.nr.AddConnectionHistory(lCtx, &conn); errChat != nil { + if errChat := u.repository.AddConnectionHistory(lCtx, &conn); errChat != nil { slog.Error("Failed to add connection history", log.ErrAttr(errChat)) } @@ -94,11 +94,11 @@ func (u networkUsecase) Start(ctx context.Context) { } func (u networkUsecase) AddConnectionHistory(ctx context.Context, conn *domain.PersonConnection) error { - return u.nr.AddConnectionHistory(ctx, conn) + return u.repository.AddConnectionHistory(ctx, conn) } func (u networkUsecase) GetASNRecordsByNum(ctx context.Context, asNum int64) ([]domain.NetworkASN, error) { - return u.nr.GetASNRecordsByNum(ctx, asNum) + return u.repository.GetASNRecordsByNum(ctx, asNum) } func (u networkUsecase) importDatabase(ctx context.Context, dbName ip2location.DatabaseFile) error { @@ -107,11 +107,11 @@ func (u networkUsecase) importDatabase(ctx context.Context, dbName ip2location.D switch dbName { case ip2location.GeoDatabaseLocationFile4: - return ip2location.ReadLocationRecords(ctx, filePath, false, u.nr.LoadLocation) + return ip2location.ReadLocationRecords(ctx, filePath, false, u.repository.LoadLocation) case ip2location.GeoDatabaseASNFile4: - return ip2location.ReadASNRecords(ctx, filePath, false, u.nr.LoadASN) + return ip2location.ReadASNRecords(ctx, filePath, false, u.repository.LoadASN) case ip2location.GeoDatabaseProxyFile: - return ip2location.ReadProxyRecords(ctx, filePath, u.nr.LoadProxies) + return ip2location.ReadProxyRecords(ctx, filePath, u.repository.LoadProxies) default: return domain.ErrNetworkLocationUnknown } @@ -134,11 +134,11 @@ func (u networkUsecase) RefreshLocationData(ctx context.Context) error { } func (u networkUsecase) GetPersonIPHistory(ctx context.Context, sid64 steamid.SteamID, limit uint64) (domain.PersonConnections, error) { - return u.nr.GetPersonIPHistory(ctx, sid64, limit) + return u.repository.GetPersonIPHistory(ctx, sid64, limit) } func (u networkUsecase) GetPlayerMostRecentIP(ctx context.Context, steamID steamid.SteamID) net.IP { - return u.nr.GetPlayerMostRecentIP(ctx, steamID) + return u.repository.GetPlayerMostRecentIP(ctx, steamID) } func (u networkUsecase) QueryConnectionHistory(ctx context.Context, opts domain.ConnectionHistoryQuery) ([]domain.PersonConnection, int64, error) { @@ -169,7 +169,7 @@ func (u networkUsecase) QueryConnectionHistory(ctx context.Context, opts domain. return nil, 0, domain.ErrMissingParam } - return u.nr.QueryConnections(ctx, opts) + return u.repository.QueryConnections(ctx, opts) } func (u networkUsecase) QueryNetwork(ctx context.Context, address netip.Addr) (domain.NetworkDetails, error) { @@ -179,21 +179,21 @@ func (u networkUsecase) QueryNetwork(ctx context.Context, address netip.Addr) (d return details, domain.ErrNetworkInvalidIP } - location, errLocation := u.nr.GetLocationRecord(ctx, address) + location, errLocation := u.repository.GetLocationRecord(ctx, address) if errLocation != nil { return details, errors.Join(errLocation, domain.ErrNetworkLocationUnknown) } details.Location = location - asn, errASN := u.nr.GetASNRecordByIP(ctx, address) + asn, errASN := u.repository.GetASNRecordByIP(ctx, address) if errASN != nil { return details, errors.Join(errASN, domain.ErrNetworkASNUnknown) } details.Asn = asn - proxy, errProxy := u.nr.GetProxyRecord(ctx, address) + proxy, errProxy := u.repository.GetProxyRecord(ctx, address) if errProxy != nil && !errors.Is(errProxy, domain.ErrNoResult) { return details, errors.Join(errProxy, domain.ErrNetworkProxyUnknown) } diff --git a/internal/person/person_usecase.go b/internal/person/person_usecase.go index b464574b..50d671ae 100644 --- a/internal/person/person_usecase.go +++ b/internal/person/person_usecase.go @@ -17,14 +17,14 @@ import ( ) type personUsecase struct { - configUsecase domain.ConfigUsecase - personRepo domain.PersonRepository + config domain.ConfigUsecase + persons domain.PersonRepository } -func NewPersonUsecase(repository domain.PersonRepository, configUsecase domain.ConfigUsecase) domain.PersonUsecase { +func NewPersonUsecase(repository domain.PersonRepository, config domain.ConfigUsecase) domain.PersonUsecase { return &personUsecase{ - personRepo: repository, - configUsecase: configUsecase, + persons: repository, + config: config, } } @@ -135,7 +135,7 @@ func (u personUsecase) updateProfiles(ctx context.Context, people domain.People) person.DaysSinceLastBan = banState.DaysSinceLastBan } - if errSavePerson := u.personRepo.SavePerson(ctx, &person); errSavePerson != nil { + if errSavePerson := u.persons.SavePerson(ctx, &person); errSavePerson != nil { return 0, errors.Join(errSavePerson, domain.ErrUpdatePerson) } } @@ -161,7 +161,7 @@ func (u personUsecase) Start(ctx context.Context) { run <- true case <-run: localCtx, cancel := context.WithTimeout(ctx, time.Second*10) - people, errGetExpired := u.personRepo.GetExpiredProfiles(localCtx, 100) + people, errGetExpired := u.persons.GetExpiredProfiles(localCtx, 100) if errGetExpired != nil || len(people) == 0 { cancel() @@ -209,35 +209,35 @@ func (u personUsecase) SetSteam(ctx context.Context, sid64 steamid.SteamID, disc } func (u personUsecase) GetPersonBySteamID(ctx context.Context, sid64 steamid.SteamID) (domain.Person, error) { - return u.personRepo.GetPersonBySteamID(ctx, sid64) + return u.persons.GetPersonBySteamID(ctx, sid64) } func (u personUsecase) DropPerson(ctx context.Context, steamID steamid.SteamID) error { - return u.personRepo.DropPerson(ctx, steamID) + return u.persons.DropPerson(ctx, steamID) } func (u personUsecase) SavePerson(ctx context.Context, person *domain.Person) error { - return u.personRepo.SavePerson(ctx, person) + return u.persons.SavePerson(ctx, person) } func (u personUsecase) GetPeopleBySteamID(ctx context.Context, steamIDs steamid.Collection) (domain.People, error) { - return u.personRepo.GetPeopleBySteamID(ctx, steamIDs) + return u.persons.GetPeopleBySteamID(ctx, steamIDs) } func (u personUsecase) GetSteamsAtAddress(ctx context.Context, addr net.IP) (steamid.Collection, error) { - return u.personRepo.GetSteamsAtAddress(ctx, addr) + return u.persons.GetSteamsAtAddress(ctx, addr) } func (u personUsecase) GetPeople(ctx context.Context, filter domain.PlayerQuery) (domain.People, int64, error) { - return u.personRepo.GetPeople(ctx, filter) + return u.persons.GetPeople(ctx, filter) } func (u personUsecase) GetOrCreatePersonBySteamID(ctx context.Context, sid64 steamid.SteamID) (domain.Person, error) { - person, errGetPerson := u.personRepo.GetPersonBySteamID(ctx, sid64) + person, errGetPerson := u.persons.GetPersonBySteamID(ctx, sid64) if errGetPerson != nil && errors.Is(errGetPerson, domain.ErrNoResult) { person = domain.NewPerson(sid64) - if err := u.personRepo.SavePerson(ctx, &person); err != nil { + if err := u.persons.SavePerson(ctx, &person); err != nil { return person, err } } @@ -246,23 +246,23 @@ func (u personUsecase) GetOrCreatePersonBySteamID(ctx context.Context, sid64 ste } func (u personUsecase) GetPersonByDiscordID(ctx context.Context, discordID string) (domain.Person, error) { - return u.personRepo.GetPersonByDiscordID(ctx, discordID) + return u.persons.GetPersonByDiscordID(ctx, discordID) } func (u personUsecase) GetExpiredProfiles(ctx context.Context, limit uint64) ([]domain.Person, error) { - return u.personRepo.GetExpiredProfiles(ctx, limit) + return u.persons.GetExpiredProfiles(ctx, limit) } func (u personUsecase) GetPersonMessageByID(ctx context.Context, personMessageID int64) (domain.PersonMessage, error) { - return u.personRepo.GetPersonMessageByID(ctx, personMessageID) + return u.persons.GetPersonMessageByID(ctx, personMessageID) } func (u personUsecase) GetSteamIDsAbove(ctx context.Context, privilege domain.Privilege) (steamid.Collection, error) { - return u.personRepo.GetSteamIDsAbove(ctx, privilege) + return u.persons.GetSteamIDsAbove(ctx, privilege) } func (u personUsecase) GetPersonSettings(ctx context.Context, steamID steamid.SteamID) (domain.PersonSettings, error) { - return u.personRepo.GetPersonSettings(ctx, steamID) + return u.persons.GetPersonSettings(ctx, steamID) } func (u personUsecase) SavePersonSettings(ctx context.Context, user domain.PersonInfo, update domain.PersonSettingsUpdate) (domain.PersonSettings, error) { @@ -276,7 +276,7 @@ func (u personUsecase) SavePersonSettings(ctx context.Context, user domain.Perso settings.ForumSignature = util.SanitizeUGC(update.ForumSignature) settings.CenterProjectiles = update.CenterProjectiles - if errSave := u.personRepo.SavePersonSettings(ctx, &settings); errSave != nil { + if errSave := u.persons.SavePersonSettings(ctx, &settings); errSave != nil { return settings, errSave } @@ -290,7 +290,7 @@ func (u personUsecase) SetPermissionLevel(ctx context.Context, steamID steamid.S } // Don't let admins un-admin themselves. - if steamID == steamid.New(u.configUsecase.Config().Owner) { + if steamID == steamid.New(u.config.Config().Owner) { return domain.ErrPermissionDenied } @@ -300,5 +300,5 @@ func (u personUsecase) SetPermissionLevel(ctx context.Context, steamID steamid.S return errSave } - return u.personRepo.SavePerson(ctx, &person) + return u.persons.SavePerson(ctx, &person) } diff --git a/internal/report/report_service.go b/internal/report/report_service.go index 4ce8ce03..f8e10a4f 100644 --- a/internal/report/report_service.go +++ b/internal/report/report_service.go @@ -245,7 +245,7 @@ func (h reportHandler) onAPIGetReport() gin.HandlerFunc { } func (r reportUsecase) GetReportBySteamID(ctx context.Context, authorID steamid.SteamID, steamID steamid.SteamID) (domain.Report, error) { - return r.rr.GetReportBySteamID(ctx, authorID, steamID) + return r.repository.GetReportBySteamID(ctx, authorID, steamID) } func (h reportHandler) onAPIGetUserReports() gin.HandlerFunc { diff --git a/internal/report/report_usecase.go b/internal/report/report_usecase.go index 73643ceb..d76325ee 100644 --- a/internal/report/report_usecase.go +++ b/internal/report/report_usecase.go @@ -15,22 +15,22 @@ import ( ) type reportUsecase struct { - rr domain.ReportRepository - du domain.DiscordUsecase - cu domain.ConfigUsecase - pu domain.PersonUsecase - demoUsecase domain.DemoUsecase + repository domain.ReportRepository + discord domain.DiscordUsecase + config domain.ConfigUsecase + persons domain.PersonUsecase + demos domain.DemoUsecase } -func NewReportUsecase(repository domain.ReportRepository, discordUsecase domain.DiscordUsecase, - configUsecase domain.ConfigUsecase, personUsecase domain.PersonUsecase, demoUsecase domain.DemoUsecase, +func NewReportUsecase(repository domain.ReportRepository, discord domain.DiscordUsecase, + config domain.ConfigUsecase, persons domain.PersonUsecase, demos domain.DemoUsecase, ) domain.ReportUsecase { return &reportUsecase{ - du: discordUsecase, - rr: repository, - cu: configUsecase, - pu: personUsecase, - demoUsecase: demoUsecase, + discord: discord, + repository: repository, + config: config, + persons: persons, + demos: demos, } } @@ -87,7 +87,7 @@ func (r reportUsecase) Start(ctx context.Context) { } } - r.du.SendPayload(domain.ChannelMod, discord.ReportStatsMessage(meta, r.cu.ExtURLRaw("/admin/reports"))) + r.discord.SendPayload(domain.ChannelMod, discord.ReportStatsMessage(meta, r.config.ExtURLRaw("/admin/reports"))) case <-ctx.Done(): slog.Debug("showReportMeta shutting down") @@ -102,7 +102,7 @@ func (r reportUsecase) addAuthorsToReports(ctx context.Context, reports []domain peopleIDs = append(peopleIDs, report.SourceID, report.TargetID) } - people, errAuthors := r.pu.GetPeopleBySteamID(ctx, fp.Uniq(peopleIDs)) + people, errAuthors := r.persons.GetPeopleBySteamID(ctx, fp.Uniq(peopleIDs)) if errAuthors != nil { return nil, errAuthors } @@ -127,7 +127,7 @@ func (r reportUsecase) GetReportsBySteamID(ctx context.Context, steamID steamid. return nil, domain.ErrInvalidSID } - reports, errReports := r.rr.GetReports(ctx, steamID) + reports, errReports := r.repository.GetReports(ctx, steamID) if errReports != nil { if errors.Is(errReports, domain.ErrNoResult) { return nil, nil @@ -140,7 +140,7 @@ func (r reportUsecase) GetReportsBySteamID(ctx context.Context, steamID steamid. } func (r reportUsecase) GetReports(ctx context.Context) ([]domain.ReportWithAuthor, error) { - reports, errReports := r.rr.GetReports(ctx, steamid.SteamID{}) + reports, errReports := r.repository.GetReports(ctx, steamid.SteamID{}) if errReports != nil { if errors.Is(errReports, domain.ErrNoResult) { return nil, nil @@ -153,12 +153,12 @@ func (r reportUsecase) GetReports(ctx context.Context) ([]domain.ReportWithAutho } func (r reportUsecase) GetReport(ctx context.Context, curUser domain.PersonInfo, reportID int64) (domain.ReportWithAuthor, error) { - report, err := r.rr.GetReport(ctx, reportID) + report, err := r.repository.GetReport(ctx, reportID) if err != nil { return domain.ReportWithAuthor{}, err } - author, errAuthor := r.pu.GetPersonBySteamID(ctx, report.SourceID) + author, errAuthor := r.persons.GetPersonBySteamID(ctx, report.SourceID) if errAuthor != nil { return domain.ReportWithAuthor{}, errAuthor } @@ -167,14 +167,14 @@ func (r reportUsecase) GetReport(ctx context.Context, curUser domain.PersonInfo, return domain.ReportWithAuthor{}, domain.ErrPermissionDenied } - target, errTarget := r.pu.GetPersonBySteamID(ctx, report.TargetID) + target, errTarget := r.persons.GetPersonBySteamID(ctx, report.TargetID) if errTarget != nil { return domain.ReportWithAuthor{}, errTarget } var demo domain.DemoFile if report.DemoID > 0 { - if errDemo := r.demoUsecase.GetDemoByID(ctx, report.DemoID, &demo); errDemo != nil { + if errDemo := r.demos.GetDemoByID(ctx, report.DemoID, &demo); errDemo != nil { slog.Error("Failed to load report demo", slog.Int64("report_id", report.ReportID)) } } @@ -188,23 +188,23 @@ func (r reportUsecase) GetReport(ctx context.Context, curUser domain.PersonInfo, } func (r reportUsecase) GetReportMessages(ctx context.Context, reportID int64) ([]domain.ReportMessage, error) { - return r.rr.GetReportMessages(ctx, reportID) + return r.repository.GetReportMessages(ctx, reportID) } func (r reportUsecase) GetReportMessageByID(ctx context.Context, reportMessageID int64) (domain.ReportMessage, error) { - return r.rr.GetReportMessageByID(ctx, reportMessageID) + return r.repository.GetReportMessageByID(ctx, reportMessageID) } func (r reportUsecase) DropReportMessage(ctx context.Context, message *domain.ReportMessage) error { - return r.rr.DropReportMessage(ctx, message) + return r.repository.DropReportMessage(ctx, message) } func (r reportUsecase) DropReport(ctx context.Context, report *domain.Report) error { - return r.rr.DropReport(ctx, report) + return r.repository.DropReport(ctx, report) } func (r reportUsecase) SaveReport(ctx context.Context, report *domain.Report) error { - if err := r.rr.SaveReport(ctx, report); err != nil { + if err := r.repository.SaveReport(ctx, report); err != nil { return err } @@ -214,5 +214,5 @@ func (r reportUsecase) SaveReport(ctx context.Context, report *domain.Report) er } func (r reportUsecase) SaveReportMessage(ctx context.Context, message *domain.ReportMessage) error { - return r.rr.SaveReportMessage(ctx, message) + return r.repository.SaveReportMessage(ctx, message) } diff --git a/internal/servers/servers_usecase.go b/internal/servers/servers_usecase.go index 229c278d..77942854 100644 --- a/internal/servers/servers_usecase.go +++ b/internal/servers/servers_usecase.go @@ -8,11 +8,11 @@ import ( ) type serversUsecase struct { - serversRepo domain.ServersRepository + servers domain.ServersRepository } func NewServersUsecase(repository domain.ServersRepository) domain.ServersUsecase { - return &serversUsecase{serversRepo: repository} + return &serversUsecase{servers: repository} } func (s *serversUsecase) GetServer(ctx context.Context, serverID int) (domain.Server, error) { @@ -20,29 +20,29 @@ func (s *serversUsecase) GetServer(ctx context.Context, serverID int) (domain.Se return domain.Server{}, domain.ErrGetServer } - return s.serversRepo.GetServer(ctx, serverID) + return s.servers.GetServer(ctx, serverID) } func (s *serversUsecase) GetServerPermissions(ctx context.Context) ([]domain.ServerPermission, error) { - return s.serversRepo.GetServerPermissions(ctx) + return s.servers.GetServerPermissions(ctx) } func (s *serversUsecase) GetServers(ctx context.Context, filter domain.ServerQueryFilter) ([]domain.Server, int64, error) { - return s.serversRepo.GetServers(ctx, filter) + return s.servers.GetServers(ctx, filter) } func (s *serversUsecase) GetServerByName(ctx context.Context, serverName string, server *domain.Server, disabledOk bool, deletedOk bool) error { - return s.serversRepo.GetServerByName(ctx, serverName, server, disabledOk, deletedOk) + return s.servers.GetServerByName(ctx, serverName, server, disabledOk, deletedOk) } func (s *serversUsecase) GetServerByPassword(ctx context.Context, serverPassword string, server *domain.Server, disabledOk bool, deletedOk bool) error { - return s.serversRepo.GetServerByPassword(ctx, serverPassword, server, disabledOk, deletedOk) + return s.servers.GetServerByPassword(ctx, serverPassword, server, disabledOk, deletedOk) } func (s *serversUsecase) SaveServer(ctx context.Context, server *domain.Server) error { isNew := server.ServerID == 0 - if err := s.serversRepo.SaveServer(ctx, server); err != nil { + if err := s.servers.SaveServer(ctx, server); err != nil { return err } diff --git a/internal/srcds/srcds_usecase.go b/internal/srcds/srcds_usecase.go index c04c46dc..c00bb69a 100644 --- a/internal/srcds/srcds_usecase.go +++ b/internal/srcds/srcds_usecase.go @@ -19,33 +19,33 @@ import ( ) type srcds struct { - banState domain.BanSteamUsecase - configUsecase domain.ConfigUsecase - serversUsecase domain.ServersUsecase - srcdsRepository domain.SRCDSRepository - personUsecase domain.PersonUsecase - reportUsecase domain.ReportUsecase - discordUsecase domain.DiscordUsecase - cookie string -} - -func NewSrcdsUsecase(srcdsRepository domain.SRCDSRepository, configUsecase domain.ConfigUsecase, serversUsecase domain.ServersUsecase, - personUsecase domain.PersonUsecase, reportUsecase domain.ReportUsecase, discordUsecase domain.DiscordUsecase, banUsecase domain.BanSteamUsecase, + repository domain.SRCDSRepository + bans domain.BanSteamUsecase + config domain.ConfigUsecase + servers domain.ServersUsecase + persons domain.PersonUsecase + reports domain.ReportUsecase + discord domain.DiscordUsecase + cookie string +} + +func NewSrcdsUsecase(repository domain.SRCDSRepository, config domain.ConfigUsecase, servers domain.ServersUsecase, + persons domain.PersonUsecase, reports domain.ReportUsecase, discord domain.DiscordUsecase, bans domain.BanSteamUsecase, ) domain.SRCDSUsecase { return &srcds{ - configUsecase: configUsecase, - serversUsecase: serversUsecase, - personUsecase: personUsecase, - reportUsecase: reportUsecase, - discordUsecase: discordUsecase, - banState: banUsecase, - srcdsRepository: srcdsRepository, - cookie: configUsecase.Config().HTTPCookieKey, + config: config, + servers: servers, + persons: persons, + reports: reports, + discord: discord, + bans: bans, + repository: repository, + cookie: config.Config().HTTPCookieKey, } } func (h srcds) GetBanState(ctx context.Context, steamID steamid.SteamID, ip netip.Addr) (domain.PlayerBanState, string, error) { - banState, errBanState := h.srcdsRepository.QueryBanState(ctx, steamID, ip) + banState, errBanState := h.repository.QueryBanState(ctx, steamID, ip) if errBanState != nil || banState.BanID == 0 { return banState, "", errBanState } @@ -61,7 +61,7 @@ func (h srcds) GetBanState(ctx context.Context, steamID steamid.SteamID, ip neti appealURL := "n/a" if banState.BanSource == domain.BanSourceSteam { - appealURL = h.configUsecase.ExtURLRaw("/appeal/%d", banState.BanID) + appealURL = h.config.ExtURLRaw("/appeal/%d", banState.BanID) } if banState.BanID > 0 && banState.BanType >= domain.NoComm { @@ -89,15 +89,15 @@ func (h srcds) GetBanState(ctx context.Context, steamID steamid.SteamID, ip neti } func (h srcds) GetOverride(ctx context.Context, overrideID int) (domain.SMOverrides, error) { - return h.srcdsRepository.GetOverride(ctx, overrideID) + return h.repository.GetOverride(ctx, overrideID) } func (h srcds) GetGroupImmunityByID(ctx context.Context, groupImmunityID int) (domain.SMGroupImmunity, error) { - return h.srcdsRepository.GetGroupImmunityByID(ctx, groupImmunityID) + return h.repository.GetGroupImmunityByID(ctx, groupImmunityID) } func (h srcds) GetGroupImmunities(ctx context.Context) ([]domain.SMGroupImmunity, error) { - return h.srcdsRepository.GetGroupImmunities(ctx) + return h.repository.GetGroupImmunities(ctx) } func (h srcds) AddGroupImmunity(ctx context.Context, groupID int, otherID int) (domain.SMGroupImmunity, error) { @@ -115,7 +115,7 @@ func (h srcds) AddGroupImmunity(ctx context.Context, groupID int, otherID int) ( return domain.SMGroupImmunity{}, errOther } - return h.srcdsRepository.AddGroupImmunity(ctx, group, other) + return h.repository.AddGroupImmunity(ctx, group, other) } func (h srcds) DelGroupImmunity(ctx context.Context, groupImmunityID int) error { @@ -124,7 +124,7 @@ func (h srcds) DelGroupImmunity(ctx context.Context, groupImmunityID int) error return errImmunity } - if err := h.srcdsRepository.DelGroupImmunity(ctx, immunity); err != nil { + if err := h.repository.DelGroupImmunity(ctx, immunity); err != nil { return err } @@ -144,7 +144,7 @@ func (h srcds) AddGroupOverride(ctx context.Context, groupID int, name string, o now := time.Now() - override, err := h.srcdsRepository.AddGroupOverride(ctx, domain.SMGroupOverrides{ + override, err := h.repository.AddGroupOverride(ctx, domain.SMGroupOverrides{ GroupID: groupID, Type: overrideType, Name: name, @@ -169,11 +169,11 @@ func (h srcds) DelGroupOverride(ctx context.Context, groupOverrideID int) error return errOverride } - return h.srcdsRepository.DelGroupOverride(ctx, override) + return h.repository.DelGroupOverride(ctx, override) } func (h srcds) GetGroupOverride(ctx context.Context, groupOverrideID int) (domain.SMGroupOverrides, error) { - return h.srcdsRepository.GetGroupOverride(ctx, groupOverrideID) + return h.repository.GetGroupOverride(ctx, groupOverrideID) } func (h srcds) SaveGroupOverride(ctx context.Context, override domain.SMGroupOverrides) (domain.SMGroupOverrides, error) { @@ -185,7 +185,7 @@ func (h srcds) SaveGroupOverride(ctx context.Context, override domain.SMGroupOve return domain.SMGroupOverrides{}, domain.ErrInvalidParameter } - return h.srcdsRepository.SaveGroupOverride(ctx, override) + return h.repository.SaveGroupOverride(ctx, override) } func (h srcds) GroupOverrides(ctx context.Context, groupID int) ([]domain.SMGroupOverrides, error) { @@ -194,11 +194,11 @@ func (h srcds) GroupOverrides(ctx context.Context, groupID int) ([]domain.SMGrou return []domain.SMGroupOverrides{}, errGroup } - return h.srcdsRepository.GroupOverrides(ctx, group) + return h.repository.GroupOverrides(ctx, group) } func (h srcds) Overrides(ctx context.Context) ([]domain.SMOverrides, error) { - return h.srcdsRepository.Overrides(ctx) + return h.repository.Overrides(ctx) } func (h srcds) SaveOverride(ctx context.Context, override domain.SMOverrides) (domain.SMOverrides, error) { @@ -206,7 +206,7 @@ func (h srcds) SaveOverride(ctx context.Context, override domain.SMOverrides) (d return domain.SMOverrides{}, domain.ErrInvalidParameter } - return h.srcdsRepository.SaveOverride(ctx, override) + return h.repository.SaveOverride(ctx, override) } func (h srcds) AddOverride(ctx context.Context, name string, overrideType domain.OverrideType, flags string) (domain.SMOverrides, error) { @@ -216,7 +216,7 @@ func (h srcds) AddOverride(ctx context.Context, name string, overrideType domain now := time.Now() - return h.srcdsRepository.AddOverride(ctx, domain.SMOverrides{ + return h.repository.AddOverride(ctx, domain.SMOverrides{ Type: overrideType, Name: name, Flags: flags, @@ -228,12 +228,12 @@ func (h srcds) AddOverride(ctx context.Context, name string, overrideType domain } func (h srcds) DelOverride(ctx context.Context, overrideID int) error { - override, errOverride := h.srcdsRepository.GetOverride(ctx, overrideID) + override, errOverride := h.repository.GetOverride(ctx, overrideID) if errOverride != nil { return errOverride } - return h.srcdsRepository.DelOverride(ctx, override) + return h.repository.DelOverride(ctx, override) } func (h srcds) DelAdminGroup(ctx context.Context, adminID int, groupID int) (domain.SMAdmin, error) { @@ -256,7 +256,7 @@ func (h srcds) DelAdminGroup(ctx context.Context, adminID int, groupID int) (dom return admin, domain.ErrSMAdminGroupExists } - if err := h.srcdsRepository.DeleteAdminGroup(ctx, admin, group); err != nil { + if err := h.repository.DeleteAdminGroup(ctx, admin, group); err != nil { return domain.SMAdmin{}, err } @@ -287,7 +287,7 @@ func (h srcds) AddAdminGroup(ctx context.Context, adminID int, groupID int) (dom return admin, domain.ErrSMAdminGroupExists } - if err := h.srcdsRepository.InsertAdminGroup(ctx, admin, group, len(existing)+1); err != nil { + if err := h.repository.InsertAdminGroup(ctx, admin, group, len(existing)+1); err != nil { return domain.SMAdmin{}, err } @@ -297,7 +297,7 @@ func (h srcds) AddAdminGroup(ctx context.Context, adminID int, groupID int) (dom } func (h srcds) GetAdminGroups(ctx context.Context, admin domain.SMAdmin) ([]domain.SMGroups, error) { - return h.srcdsRepository.GetAdminGroups(ctx, admin) + return h.repository.GetAdminGroups(ctx, admin) } func (h srcds) Report(ctx context.Context, currentUser domain.UserProfile, req domain.CreateReportReq) (*domain.Report, error) { @@ -324,12 +324,12 @@ func (h srcds) Report(ctx context.Context, currentUser domain.UserProfile, req d return nil, domain.ErrSelfReport } - personSource, errCreatePerson := h.personUsecase.GetPersonBySteamID(ctx, req.SourceID) + personSource, errCreatePerson := h.persons.GetPersonBySteamID(ctx, req.SourceID) if errCreatePerson != nil { return nil, domain.ErrInternal } - personTarget, errCreatePerson := h.personUsecase.GetOrCreatePersonBySteamID(ctx, req.TargetID) + personTarget, errCreatePerson := h.persons.GetOrCreatePersonBySteamID(ctx, req.TargetID) if errCreatePerson != nil { return nil, domain.ErrInternal } @@ -338,14 +338,14 @@ func (h srcds) Report(ctx context.Context, currentUser domain.UserProfile, req d if err := thirdparty.UpdatePlayerSummary(ctx, &personTarget); err != nil { slog.Error("Failed to update target player", log.ErrAttr(err)) } else { - if errSave := h.personUsecase.SavePerson(ctx, &personTarget); errSave != nil { + if errSave := h.persons.SavePerson(ctx, &personTarget); errSave != nil { slog.Error("Failed to save target player update", log.ErrAttr(err)) } } } // Ensure the user doesn't already have an open report against the user - existing, errReports := h.reportUsecase.GetReportBySteamID(ctx, personSource.SteamID, req.TargetID) + existing, errReports := h.reports.GetReportBySteamID(ctx, personSource.SteamID, req.TargetID) if errReports != nil { if !errors.Is(errReports, domain.ErrNoResult) { return nil, errReports @@ -367,31 +367,31 @@ func (h srcds) Report(ctx context.Context, currentUser domain.UserProfile, req d report.DemoTick = req.DemoTick report.PersonMessageID = req.PersonMessageID - if errReportSave := h.reportUsecase.SaveReport(ctx, &report); errReportSave != nil { + if errReportSave := h.reports.SaveReport(ctx, &report); errReportSave != nil { return nil, errReportSave } slog.Info("New report created successfully", slog.Int64("report_id", report.ReportID)) - conf := h.configUsecase.Config() + conf := h.config.Config() demoURL := "" msg := discord.NewInGameReportResponse(report, conf.ExtURL(report), currentUser, conf.ExtURL(currentUser), demoURL) - h.discordUsecase.SendPayload(domain.ChannelModLog, msg) + h.discord.SendPayload(domain.ChannelModLog, msg) return &report, nil } func (h srcds) SetAdminGroups(ctx context.Context, authType domain.AuthType, identity string, groups ...domain.SMGroups) error { - admin, errAdmin := h.srcdsRepository.GetAdminByIdentity(ctx, authType, identity) + admin, errAdmin := h.repository.GetAdminByIdentity(ctx, authType, identity) if errAdmin != nil { return errAdmin } // Delete existing groups. - if errDelete := h.srcdsRepository.DeleteAdminGroups(ctx, admin); errDelete != nil && !errors.Is(errDelete, domain.ErrNoResult) { + if errDelete := h.repository.DeleteAdminGroups(ctx, admin); errDelete != nil && !errors.Is(errDelete, domain.ErrNoResult) { return errDelete } @@ -401,7 +401,7 @@ func (h srcds) SetAdminGroups(ctx context.Context, authType domain.AuthType, ide } for i := range groups { - if errInsert := h.srcdsRepository.InsertAdminGroup(ctx, admin, groups[i], i); errInsert != nil { + if errInsert := h.repository.InsertAdminGroup(ctx, admin, groups[i], i); errInsert != nil { return errInsert } } @@ -410,12 +410,12 @@ func (h srcds) SetAdminGroups(ctx context.Context, authType domain.AuthType, ide } func (h srcds) DelGroup(ctx context.Context, groupID int) error { - group, errGroup := h.srcdsRepository.GetGroupByID(ctx, groupID) + group, errGroup := h.repository.GetGroupByID(ctx, groupID) if errGroup != nil { return errGroup } - return h.srcdsRepository.DeleteGroup(ctx, group) + return h.repository.DeleteGroup(ctx, group) } const validFlags = "zabcdefghijklmnopqrst" @@ -435,7 +435,7 @@ func (h srcds) AddGroup(ctx context.Context, name string, flags string, immunity } } - return h.srcdsRepository.AddGroup(ctx, domain.SMGroups{ + return h.repository.AddGroup(ctx, domain.SMGroups{ Flags: flags, Name: name, ImmunityLevel: immunityLevel, @@ -469,16 +469,16 @@ func validateAuthIdentity(ctx context.Context, authType domain.AuthType, identit } func (h srcds) DelAdmin(ctx context.Context, adminID int) error { - admin, errAdmin := h.srcdsRepository.GetAdminByID(ctx, adminID) + admin, errAdmin := h.repository.GetAdminByID(ctx, adminID) if errAdmin != nil { return errAdmin } - return h.srcdsRepository.DelAdmin(ctx, admin) + return h.repository.DelAdmin(ctx, admin) } func (h srcds) GetAdminByID(ctx context.Context, adminID int) (domain.SMAdmin, error) { - return h.srcdsRepository.GetAdminByID(ctx, adminID) + return h.repository.GetAdminByID(ctx, adminID) } func (h srcds) SaveAdmin(ctx context.Context, admin domain.SMAdmin) (domain.SMAdmin, error) { @@ -494,7 +494,7 @@ func (h srcds) SaveAdmin(ctx context.Context, admin domain.SMAdmin) (domain.SMAd var steamID steamid.SteamID if admin.AuthType == domain.AuthTypeSteam { steamID = steamid.New(realIdentity) - if _, err := h.personUsecase.GetOrCreatePersonBySteamID(ctx, steamID); err != nil { + if _, err := h.persons.GetOrCreatePersonBySteamID(ctx, steamID); err != nil { return domain.SMAdmin{}, domain.ErrGetPerson } @@ -502,7 +502,7 @@ func (h srcds) SaveAdmin(ctx context.Context, admin domain.SMAdmin) (domain.SMAd admin.SteamID = steamID } - return h.srcdsRepository.SaveAdmin(ctx, admin) + return h.repository.SaveAdmin(ctx, admin) } func (h srcds) AddAdmin(ctx context.Context, alias string, authType domain.AuthType, identity string, flags string, immunity int, password string) (domain.SMAdmin, error) { @@ -515,7 +515,7 @@ func (h srcds) AddAdmin(ctx context.Context, alias string, authType domain.AuthT return domain.SMAdmin{}, domain.ErrSMImmunity } - admin, errAdmin := h.srcdsRepository.GetAdminByIdentity(ctx, authType, realIdentity) + admin, errAdmin := h.repository.GetAdminByIdentity(ctx, authType, realIdentity) if errAdmin != nil && !errors.Is(errAdmin, domain.ErrNoResult) { return domain.SMAdmin{}, errAdmin } @@ -527,14 +527,14 @@ func (h srcds) AddAdmin(ctx context.Context, alias string, authType domain.AuthT var steamID steamid.SteamID if authType == domain.AuthTypeSteam { steamID = steamid.New(realIdentity) - if _, err := h.personUsecase.GetOrCreatePersonBySteamID(ctx, steamID); err != nil { + if _, err := h.persons.GetOrCreatePersonBySteamID(ctx, steamID); err != nil { return domain.SMAdmin{}, domain.ErrGetPerson } identity = string(steamID.Steam3()) } - return h.srcdsRepository.AddAdmin(ctx, domain.SMAdmin{ + return h.repository.AddAdmin(ctx, domain.SMAdmin{ SteamID: steamID, AuthType: authType, Identity: identity, @@ -547,15 +547,15 @@ func (h srcds) AddAdmin(ctx context.Context, alias string, authType domain.AuthT } func (h srcds) Admins(ctx context.Context) ([]domain.SMAdmin, error) { - return h.srcdsRepository.Admins(ctx) + return h.repository.Admins(ctx) } func (h srcds) Groups(ctx context.Context) ([]domain.SMGroups, error) { - return h.srcdsRepository.Groups(ctx) + return h.repository.Groups(ctx) } func (h srcds) GetGroupByID(ctx context.Context, groupID int) (domain.SMGroups, error) { - return h.srcdsRepository.GetGroupByID(ctx, groupID) + return h.repository.GetGroupByID(ctx, groupID) } func (h srcds) SaveGroup(ctx context.Context, group domain.SMGroups) (domain.SMGroups, error) { @@ -573,5 +573,5 @@ func (h srcds) SaveGroup(ctx context.Context, group domain.SMGroups) (domain.SMG } } - return h.srcdsRepository.SaveGroup(ctx, group) + return h.repository.SaveGroup(ctx, group) } diff --git a/internal/state/state_usecase.go b/internal/state/state_usecase.go index 9ec5fede..7df88b7b 100644 --- a/internal/state/state_usecase.go +++ b/internal/state/state_usecase.go @@ -31,13 +31,13 @@ type stateUsecase struct { // NewStateUsecase created a interface to interact with server state and exec rcon commands // TODO ensure started. func NewStateUsecase(broadcaster *fp.Broadcaster[logparse.EventType, logparse.ServerEvent], - repository domain.StateRepository, configUsecase domain.ConfigUsecase, serversUsecase domain.ServersUsecase, + repository domain.StateRepository, config domain.ConfigUsecase, servers domain.ServersUsecase, ) domain.StateUsecase { return &stateUsecase{ state: repository, - config: configUsecase, + config: config, broadcaster: broadcaster, - servers: serversUsecase, + servers: servers, logFileChan: make(chan domain.LogFilePayload), } } diff --git a/internal/steamgroup/steamgroup_usecase.go b/internal/steamgroup/steamgroup_usecase.go index 1a964c43..92841062 100644 --- a/internal/steamgroup/steamgroup_usecase.go +++ b/internal/steamgroup/steamgroup_usecase.go @@ -15,21 +15,20 @@ import ( ) type banGroupUsecase struct { - banGroupRepository domain.BanGroupRepository - personUsecase domain.PersonUsecase - discord domain.DiscordUsecase - config domain.ConfigUsecase + repository domain.BanGroupRepository + persons domain.PersonUsecase + discord domain.DiscordUsecase + config domain.ConfigUsecase } -func NewBanGroupUsecase(banGroupRepository domain.BanGroupRepository, personUsecase domain.PersonUsecase, - discord domain.DiscordUsecase, - config domain.ConfigUsecase, +func NewBanGroupUsecase(repository domain.BanGroupRepository, persons domain.PersonUsecase, + discord domain.DiscordUsecase, config domain.ConfigUsecase, ) domain.BanGroupUsecase { return &banGroupUsecase{ - banGroupRepository: banGroupRepository, - personUsecase: personUsecase, - discord: discord, - config: config, + repository: repository, + persons: persons, + discord: discord, + config: config, } } @@ -39,7 +38,7 @@ func (s banGroupUsecase) UpdateCache(ctx context.Context) error { return errGroups } - if err := s.banGroupRepository.TruncateCache(ctx); err != nil { + if err := s.repository.TruncateCache(ctx); err != nil { return err } @@ -81,13 +80,13 @@ func (s banGroupUsecase) UpdateCache(ctx context.Context) error { } // Statisfy FK - _, errCreate := s.personUsecase.GetOrCreatePersonBySteamID(ctx, steamID) + _, errCreate := s.persons.GetOrCreatePersonBySteamID(ctx, steamID) if errCreate != nil { return errCreate } } - if err := s.banGroupRepository.InsertCache(ctx, groupID, list.Members.SteamID64); err != nil { + if err := s.repository.InsertCache(ctx, groupID, list.Members.SteamID64); err != nil { return err } } @@ -96,31 +95,31 @@ func (s banGroupUsecase) UpdateCache(ctx context.Context) error { } func (s banGroupUsecase) Save(ctx context.Context, banGroup *domain.BanGroup) error { - return s.banGroupRepository.Save(ctx, banGroup) + return s.repository.Save(ctx, banGroup) } func (s banGroupUsecase) GetByGID(ctx context.Context, groupID steamid.SteamID, banGroup *domain.BanGroup) error { - return s.banGroupRepository.GetByGID(ctx, groupID, banGroup) + return s.repository.GetByGID(ctx, groupID, banGroup) } func (s banGroupUsecase) GetByID(ctx context.Context, banGroupID int64, banGroup *domain.BanGroup) error { - return s.banGroupRepository.GetByID(ctx, banGroupID, banGroup) + return s.repository.GetByID(ctx, banGroupID, banGroup) } func (s banGroupUsecase) Get(ctx context.Context, filter domain.GroupBansQueryFilter) ([]domain.BannedGroupPerson, error) { - return s.banGroupRepository.Get(ctx, filter) + return s.repository.Get(ctx, filter) } func (s banGroupUsecase) Delete(ctx context.Context, banGroup *domain.BanGroup) error { - return s.banGroupRepository.Delete(ctx, banGroup) + return s.repository.Delete(ctx, banGroup) } func (s banGroupUsecase) GetMembersList(ctx context.Context, parentID int64, list *domain.MembersList) error { - return s.banGroupRepository.GetMembersList(ctx, parentID, list) + return s.repository.GetMembersList(ctx, parentID, list) } func (s banGroupUsecase) SaveMembersList(ctx context.Context, list *domain.MembersList) error { - return s.banGroupRepository.SaveMembersList(ctx, list) + return s.repository.SaveMembersList(ctx, list) } func (s banGroupUsecase) Ban(ctx context.Context, banGroup *domain.BanGroup) error { @@ -129,12 +128,12 @@ func (s banGroupUsecase) Ban(ctx context.Context, banGroup *domain.BanGroup) err return errors.Join(membersErr, domain.ErrGroupValidate) } - author, errAuthor := s.personUsecase.GetPersonBySteamID(ctx, banGroup.SourceID) + author, errAuthor := s.persons.GetPersonBySteamID(ctx, banGroup.SourceID) if errAuthor != nil { return errors.Join(membersErr, domain.ErrGetPerson) } - if err := s.banGroupRepository.Ban(ctx, banGroup); err != nil { + if err := s.repository.Ban(ctx, banGroup); err != nil { return errors.Join(err, domain.ErrSaveBan) } diff --git a/internal/votes/vote_service.go b/internal/votes/vote_service.go index 982c621a..c86c9ad2 100644 --- a/internal/votes/vote_service.go +++ b/internal/votes/vote_service.go @@ -10,20 +10,20 @@ import ( "github.com/leighmacdonald/gbans/pkg/log" ) -func NewVoteHandler(engine *gin.Engine, voteUsecase domain.VoteUsecase, authUsecase domain.AuthUsecase) { - handler := voteHandler{votes: voteUsecase} +type voteHandler struct { + votes domain.VoteUsecase +} + +func NewVoteHandler(engine *gin.Engine, votes domain.VoteUsecase, auth domain.AuthUsecase) { + handler := voteHandler{votes: votes} modGrp := engine.Group("/") { - mod := modGrp.Use(authUsecase.AuthMiddleware(domain.PModerator)) + mod := modGrp.Use(auth.AuthMiddleware(domain.PModerator)) mod.POST("/api/votes", handler.onVotes()) } } -type voteHandler struct { - votes domain.VoteUsecase -} - func (h voteHandler) onVotes() gin.HandlerFunc { return func(ctx *gin.Context) { var req domain.VoteQueryFilter diff --git a/internal/votes/vote_usecase.go b/internal/votes/vote_usecase.go index 8aaf256d..ce489fb7 100644 --- a/internal/votes/vote_usecase.go +++ b/internal/votes/vote_usecase.go @@ -13,27 +13,27 @@ import ( ) type voteUsecase struct { - votes domain.VoteRepository + repository domain.VoteRepository persons domain.PersonUsecase matches domain.MatchUsecase discord domain.DiscordUsecase broadcaster *fp.Broadcaster[logparse.EventType, logparse.ServerEvent] } -func NewVoteUsecase(voteRepository domain.VoteRepository, personUsecase domain.PersonUsecase, matchUsecase domain.MatchUsecase, - discordUsecase domain.DiscordUsecase, broadcaster *fp.Broadcaster[logparse.EventType, logparse.ServerEvent], +func NewVoteUsecase(repository domain.VoteRepository, persons domain.PersonUsecase, matched domain.MatchUsecase, + discord domain.DiscordUsecase, broadcaster *fp.Broadcaster[logparse.EventType, logparse.ServerEvent], ) domain.VoteUsecase { return &voteUsecase{ - votes: voteRepository, - persons: personUsecase, - matches: matchUsecase, - discord: discordUsecase, + repository: repository, + persons: persons, + matches: matched, + discord: discord, broadcaster: broadcaster, } } func (u voteUsecase) Query(ctx context.Context, filter domain.VoteQueryFilter) ([]domain.VoteResult, int64, error) { - return u.votes.Query(ctx, filter) + return u.repository.Query(ctx, filter) } // Start will begin ingesting vote events and record them to the database. @@ -149,7 +149,7 @@ func (u voteUsecase) Start(ctx context.Context) { continue } - if err := u.votes.AddResult(ctx, result); err != nil { + if err := u.repository.AddResult(ctx, result); err != nil { slog.Error("Failed to add vote result", log.ErrAttr(err)) } diff --git a/internal/wiki/wiki_service.go b/internal/wiki/wiki_service.go index 4200c793..aeba7704 100644 --- a/internal/wiki/wiki_service.go +++ b/internal/wiki/wiki_service.go @@ -9,11 +9,11 @@ import ( ) type wikiHandler struct { - wikiUsecase domain.WikiUsecase + wiki domain.WikiUsecase } -func NewWIkiHandler(engine *gin.Engine, wikiUsecase domain.WikiUsecase, ath domain.AuthUsecase) { - handler := &wikiHandler{wikiUsecase: wikiUsecase} +func NewWIkiHandler(engine *gin.Engine, wiki domain.WikiUsecase, ath domain.AuthUsecase) { + handler := &wikiHandler{wiki: wiki} // optional optGrp := engine.Group("/") @@ -32,7 +32,7 @@ func NewWIkiHandler(engine *gin.Engine, wikiUsecase domain.WikiUsecase, ath doma func (w *wikiHandler) onAPIGetWikiSlug() gin.HandlerFunc { return func(ctx *gin.Context) { - page, err := w.wikiUsecase.GetWikiPageBySlug(ctx, httphelper.CurrentUserProfile(ctx), ctx.Param("slug")) + page, err := w.wiki.GetWikiPageBySlug(ctx, httphelper.CurrentUserProfile(ctx), ctx.Param("slug")) if err != nil { httphelper.ErrorHandled(ctx, err) @@ -50,7 +50,7 @@ func (w *wikiHandler) onAPISaveWikiSlug() gin.HandlerFunc { return } - page, err := w.wikiUsecase.SaveWikiPage(ctx, httphelper.CurrentUserProfile(ctx), req.Slug, req.BodyMD, req.PermissionLevel) + page, err := w.wiki.SaveWikiPage(ctx, httphelper.CurrentUserProfile(ctx), req.Slug, req.BodyMD, req.PermissionLevel) if err != nil { httphelper.ErrorHandled(ctx, err) diff --git a/internal/wiki/wiki_usecase.go b/internal/wiki/wiki_usecase.go index 538ac513..abdf8d3a 100644 --- a/internal/wiki/wiki_usecase.go +++ b/internal/wiki/wiki_usecase.go @@ -10,11 +10,11 @@ import ( ) type wikiUsecase struct { - wikiRepo domain.WikiRepository + repository domain.WikiRepository } func NewWikiUsecase(repository domain.WikiRepository) domain.WikiUsecase { - return &wikiUsecase{wikiRepo: repository} + return &wikiUsecase{repository: repository} } func (w *wikiUsecase) GetWikiPageBySlug(ctx context.Context, user domain.PersonInfo, slug string) (domain.WikiPage, error) { @@ -23,7 +23,7 @@ func (w *wikiUsecase) GetWikiPageBySlug(ctx context.Context, user domain.PersonI slug = slug[1:] } - page, errGetWikiSlug := w.wikiRepo.GetWikiPageBySlug(ctx, slug) + page, errGetWikiSlug := w.repository.GetWikiPageBySlug(ctx, slug) if errGetWikiSlug != nil { return page, errGetWikiSlug } @@ -36,7 +36,7 @@ func (w *wikiUsecase) GetWikiPageBySlug(ctx context.Context, user domain.PersonI } func (w *wikiUsecase) DeleteWikiPageBySlug(ctx context.Context, slug string) error { - return w.wikiRepo.DeleteWikiPageBySlug(ctx, slug) + return w.repository.DeleteWikiPageBySlug(ctx, slug) } func (w *wikiUsecase) SaveWikiPage(ctx context.Context, user domain.PersonInfo, slug string, body string, level domain.Privilege) (domain.WikiPage, error) { @@ -60,7 +60,7 @@ func (w *wikiUsecase) SaveWikiPage(ctx context.Context, user domain.PersonInfo, page.PermissionLevel = level page.BodyMD = body - if errSave := w.wikiRepo.SaveWikiPage(ctx, &page); errSave != nil { + if errSave := w.repository.SaveWikiPage(ctx, &page); errSave != nil { return page, errSave } diff --git a/internal/wordfilter/wordfilter_service.go b/internal/wordfilter/wordfilter_service.go index b082bd9b..484ac1de 100644 --- a/internal/wordfilter/wordfilter_service.go +++ b/internal/wordfilter/wordfilter_service.go @@ -17,17 +17,17 @@ type wordFilterHandler struct { config domain.ConfigUsecase } -func NewWordFilterHandler(engine *gin.Engine, confUsecase domain.ConfigUsecase, wfu domain.WordFilterUsecase, cu domain.ChatUsecase, ath domain.AuthUsecase) { +func NewWordFilterHandler(engine *gin.Engine, config domain.ConfigUsecase, wordFilters domain.WordFilterUsecase, chat domain.ChatUsecase, auth domain.AuthUsecase) { handler := wordFilterHandler{ - config: confUsecase, - filters: wfu, - chat: cu, + config: config, + filters: wordFilters, + chat: chat, } // editor modGroup := engine.Group("/") { - mod := modGroup.Use(ath.AuthMiddleware(domain.PModerator)) + mod := modGroup.Use(auth.AuthMiddleware(domain.PModerator)) mod.POST("/api/filters/query", handler.queryFilters()) mod.GET("/api/filters/state", handler.filterStates()) mod.POST("/api/filters", handler.createFilter()) diff --git a/internal/wordfilter/wordfilter_usecase.go b/internal/wordfilter/wordfilter_usecase.go index 9c15d43a..eba5346c 100644 --- a/internal/wordfilter/wordfilter_usecase.go +++ b/internal/wordfilter/wordfilter_usecase.go @@ -12,16 +12,16 @@ import ( ) type wordFilterUsecase struct { - filterRepository domain.WordFilterRepository - wordFilters *WordFilters + repository domain.WordFilterRepository + wordFilters *WordFilters } -func NewWordFilterUsecase(filterRepository domain.WordFilterRepository) domain.WordFilterUsecase { - return &wordFilterUsecase{filterRepository: filterRepository, wordFilters: NewWordFilters()} +func NewWordFilterUsecase(repository domain.WordFilterRepository) domain.WordFilterUsecase { + return &wordFilterUsecase{repository: repository, wordFilters: NewWordFilters()} } func (w *wordFilterUsecase) Import(ctx context.Context) error { - filters, errFilters := w.filterRepository.GetFilters(ctx) + filters, errFilters := w.repository.GetFilters(ctx) if errFilters != nil && !errors.Is(errFilters, domain.ErrNoResult) { return errFilters } @@ -36,7 +36,7 @@ func (w *wordFilterUsecase) Check(query string) []domain.Filter { } func (w *wordFilterUsecase) Edit(ctx context.Context, user domain.PersonInfo, filterID int64, filter domain.Filter) (domain.Filter, error) { - existingFilter, errGet := w.filterRepository.GetFilterByID(ctx, filterID) + existingFilter, errGet := w.repository.GetFilterByID(ctx, filterID) if errGet != nil { return domain.Filter{}, errGet } @@ -50,7 +50,7 @@ func (w *wordFilterUsecase) Edit(ctx context.Context, user domain.PersonInfo, fi existingFilter.Duration = filter.Duration existingFilter.Weight = filter.Weight - if errSave := w.filterRepository.SaveFilter(ctx, &existingFilter); errSave != nil { + if errSave := w.repository.SaveFilter(ctx, &existingFilter); errSave != nil { return domain.Filter{}, errSave } @@ -94,7 +94,7 @@ func (w *wordFilterUsecase) Create(ctx context.Context, user domain.PersonInfo, Weight: opts.Weight, } - if errSave := w.filterRepository.SaveFilter(ctx, &newFilter); errSave != nil { + if errSave := w.repository.SaveFilter(ctx, &newFilter); errSave != nil { if errors.Is(errSave, domain.ErrDuplicate) { return domain.Filter{}, domain.ErrDuplicate } @@ -112,7 +112,7 @@ func (w *wordFilterUsecase) Create(ctx context.Context, user domain.PersonInfo, } func (w *wordFilterUsecase) DropFilter(ctx context.Context, filter domain.Filter) error { - if err := w.filterRepository.DropFilter(ctx, filter); err != nil { + if err := w.repository.DropFilter(ctx, filter); err != nil { return err } @@ -122,13 +122,13 @@ func (w *wordFilterUsecase) DropFilter(ctx context.Context, filter domain.Filter } func (w *wordFilterUsecase) GetFilterByID(ctx context.Context, filterID int64) (domain.Filter, error) { - return w.filterRepository.GetFilterByID(ctx, filterID) + return w.repository.GetFilterByID(ctx, filterID) } func (w *wordFilterUsecase) GetFilters(ctx context.Context) ([]domain.Filter, error) { - return w.filterRepository.GetFilters(ctx) + return w.repository.GetFilters(ctx) } func (w *wordFilterUsecase) AddMessageFilterMatch(ctx context.Context, messageID int64, filterID int64) error { - return w.filterRepository.AddMessageFilterMatch(ctx, messageID, filterID) + return w.repository.AddMessageFilterMatch(ctx, messageID, filterID) }