refactor(channelserver): move remaining s.server.db calls into repositories

Eliminate the last three direct DB accesses from handler code:

- CharacterRepo.LoadSaveData: replaces db.Query in GetCharacterSaveData,
  using QueryRow instead of Query+Next for cleaner single-row access
- EventRepo.GetEventQuests, UpdateEventQuestStartTime, BeginTx: moves
  event quest enumeration and rotation queries behind the repo layer
- UserRepo.BanUser: consolidates permanent/temporary ban upserts into a
  single method with nil/*time.Time semantics
This commit is contained in:
Houmgaor
2026-02-21 14:08:01 +01:00
parent 9a473260b2
commit a9cca84bc3
8 changed files with 66 additions and 21 deletions

View File

@@ -104,14 +104,12 @@ func parseChatCommand(s *Session, command string) {
uid, uname, err := s.server.userRepo.GetByIDAndUsername(cid)
if err == nil {
if expiry.IsZero() {
if _, err := s.server.db.Exec(`INSERT INTO bans VALUES ($1)
ON CONFLICT (user_id) DO UPDATE SET expires=NULL`, uid); err != nil {
if err := s.server.userRepo.BanUser(uid, nil); err != nil {
s.logger.Error("Failed to ban user", zap.Error(err))
}
sendServerChatMessage(s, fmt.Sprintf(s.server.i18n.commands.ban.success, uname))
} else {
if _, err := s.server.db.Exec(`INSERT INTO bans VALUES ($1, $2)
ON CONFLICT (user_id) DO UPDATE SET expires=$2`, uid, expiry); err != nil {
if err := s.server.userRepo.BanUser(uid, &expiry); err != nil {
s.logger.Error("Failed to ban user with expiry", zap.Error(err))
}
sendServerChatMessage(s, fmt.Sprintf(s.server.i18n.commands.ban.success, uname)+fmt.Sprintf(s.server.i18n.commands.ban.length, expiry.Format(time.DateTime)))