mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-27 01:53:19 +01:00
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.
This commit is contained in:
22
server/entranceserver/repo_server.go
Normal file
22
server/entranceserver/repo_server.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package entranceserver
|
||||
|
||||
import "github.com/jmoiron/sqlx"
|
||||
|
||||
// EntranceServerRepository implements EntranceServerRepo with PostgreSQL.
|
||||
type EntranceServerRepository struct {
|
||||
db *sqlx.DB
|
||||
}
|
||||
|
||||
// NewEntranceServerRepository creates a new EntranceServerRepository.
|
||||
func NewEntranceServerRepository(db *sqlx.DB) *EntranceServerRepository {
|
||||
return &EntranceServerRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *EntranceServerRepository) GetCurrentPlayers(serverID int) (uint16, error) {
|
||||
var currentPlayers uint16
|
||||
err := r.db.QueryRow("SELECT current_players FROM servers WHERE server_id=$1", serverID).Scan(¤tPlayers)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return currentPlayers, nil
|
||||
}
|
||||
Reference in New Issue
Block a user