mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-27 10:03:06 +01:00
refactor(channelserver): extract Goocoo, Diva, Misc, Scenario, and Mercenary repositories
Move remaining raw s.server.db.* queries from handler files into dedicated repository structs, completing the repository extraction effort. Also adds SaveCharacterData and SaveHouseData to CharacterRepository. Fixes guild_hunts query to select both cats_used and start columns to match the existing two-column Scan call. Adds slot index validation in GoocooRepository to prevent SQL injection via fmt.Sprintf.
This commit is contained in:
32
server/channelserver/repo_diva.go
Normal file
32
server/channelserver/repo_diva.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package channelserver
|
||||
|
||||
import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
// DivaRepository centralizes all database access for diva defense events.
|
||||
type DivaRepository struct {
|
||||
db *sqlx.DB
|
||||
}
|
||||
|
||||
// NewDivaRepository creates a new DivaRepository.
|
||||
func NewDivaRepository(db *sqlx.DB) *DivaRepository {
|
||||
return &DivaRepository{db: db}
|
||||
}
|
||||
|
||||
// DeleteEvents removes all diva events.
|
||||
func (r *DivaRepository) DeleteEvents() error {
|
||||
_, err := r.db.Exec("DELETE FROM events WHERE event_type='diva'")
|
||||
return err
|
||||
}
|
||||
|
||||
// InsertEvent creates a new diva event with the given start epoch.
|
||||
func (r *DivaRepository) InsertEvent(startEpoch uint32) error {
|
||||
_, err := r.db.Exec("INSERT INTO events (event_type, start_time) VALUES ('diva', to_timestamp($1)::timestamp without time zone)", startEpoch)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetEvents returns all diva events with their ID and start_time epoch.
|
||||
func (r *DivaRepository) GetEvents() (*sqlx.Rows, error) {
|
||||
return r.db.Queryx("SELECT id, (EXTRACT(epoch FROM start_time)::int) as start_time FROM events WHERE event_type='diva'")
|
||||
}
|
||||
Reference in New Issue
Block a user