Files
Erupe/server/entranceserver/repo_session.go
Houmgaor 82b967b715 refactor: replace raw SQL with repository interfaces in entranceserver and API server
Extract all direct database calls from entranceserver (2 calls) and
API server (17 calls) into typed repository interfaces with PostgreSQL
implementations, matching the pattern established in signserver and
channelserver.

Entranceserver: EntranceServerRepo, EntranceSessionRepo
API server: APIUserRepo, APICharacterRepo, APISessionRepo

Also fix the 3 remaining fmt.Sprintf calls inside logger invocations
in handlers_commands.go and handlers_stage.go, replacing them with
structured zap fields.

Unskip 5 TestNewAuthData* tests that previously required a real
database — they now run with mock repos.
2026-02-22 17:04:58 +01:00

23 lines
660 B
Go

package entranceserver
import "github.com/jmoiron/sqlx"
// EntranceSessionRepository implements EntranceSessionRepo with PostgreSQL.
type EntranceSessionRepository struct {
db *sqlx.DB
}
// NewEntranceSessionRepository creates a new EntranceSessionRepository.
func NewEntranceSessionRepository(db *sqlx.DB) *EntranceSessionRepository {
return &EntranceSessionRepository{db: db}
}
func (r *EntranceSessionRepository) GetServerIDForCharacter(charID uint32) (uint16, error) {
var sid uint16
err := r.db.QueryRow("SELECT(SELECT server_id FROM sign_sessions WHERE char_id=$1) AS _", charID).Scan(&sid)
if err != nil {
return 0, err
}
return sid, nil
}