mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-26 09:33:02 +01:00
refactor(channelserver): eliminate *sql.Rows from EventRepo.GetEventQuests
Return []EventQuest instead of a raw database cursor, removing the last *sql.Rows leak from the repository layer. The handler now iterates a slice, and makeEventQuest reads fields from the struct directly instead of scanning rows twice. This makes the method fully mockable and eliminates the risk of unclosed cursors.
This commit is contained in:
@@ -7,6 +7,19 @@ import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
// EventQuest represents a row from the event_quests table.
|
||||
type EventQuest struct {
|
||||
ID uint32 `db:"id"`
|
||||
MaxPlayers uint8 `db:"max_players"`
|
||||
QuestType uint8 `db:"quest_type"`
|
||||
QuestID int `db:"quest_id"`
|
||||
Mark uint32 `db:"mark"`
|
||||
Flags int `db:"flags"`
|
||||
StartTime time.Time `db:"start_time"`
|
||||
ActiveDays int `db:"active_days"`
|
||||
InactiveDays int `db:"inactive_days"`
|
||||
}
|
||||
|
||||
// EventRepository centralizes all database access for event-related tables.
|
||||
type EventRepository struct {
|
||||
db *sqlx.DB
|
||||
@@ -50,8 +63,10 @@ func (r *EventRepository) UpdateLoginBoost(charID uint32, weekReq uint8, expirat
|
||||
}
|
||||
|
||||
// GetEventQuests returns all event quest rows ordered by quest_id.
|
||||
func (r *EventRepository) GetEventQuests() (*sql.Rows, error) {
|
||||
return r.db.Query("SELECT id, COALESCE(max_players, 4) AS max_players, quest_type, quest_id, COALESCE(mark, 0) AS mark, COALESCE(flags, -1), start_time, COALESCE(active_days, 0) AS active_days, COALESCE(inactive_days, 0) AS inactive_days FROM event_quests ORDER BY quest_id")
|
||||
func (r *EventRepository) GetEventQuests() ([]EventQuest, error) {
|
||||
var result []EventQuest
|
||||
err := r.db.Select(&result, "SELECT id, COALESCE(max_players, 4) AS max_players, quest_type, quest_id, COALESCE(mark, 0) AS mark, COALESCE(flags, -1) AS flags, start_time, COALESCE(active_days, 0) AS active_days, COALESCE(inactive_days, 0) AS inactive_days FROM event_quests ORDER BY quest_id")
|
||||
return result, err
|
||||
}
|
||||
|
||||
// UpdateEventQuestStartTime updates the start_time for an event quest within a transaction.
|
||||
|
||||
Reference in New Issue
Block a user