mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
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:
@@ -2,6 +2,7 @@ package channelserver
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
@@ -218,3 +219,16 @@ func (r *UserRepository) GetByIDAndUsername(charID uint32) (userID uint32, usern
|
||||
).Scan(&userID, &username)
|
||||
return
|
||||
}
|
||||
|
||||
// BanUser inserts or updates a ban for the given user.
|
||||
// A nil expires means a permanent ban; non-nil sets a temporary ban with expiry.
|
||||
func (r *UserRepository) BanUser(userID uint32, expires *time.Time) error {
|
||||
if expires == nil {
|
||||
_, err := r.db.Exec(`INSERT INTO bans VALUES ($1)
|
||||
ON CONFLICT (user_id) DO UPDATE SET expires=NULL`, userID)
|
||||
return err
|
||||
}
|
||||
_, err := r.db.Exec(`INSERT INTO bans VALUES ($1, $2)
|
||||
ON CONFLICT (user_id) DO UPDATE SET expires=$2`, userID, *expires)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user