mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +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:
@@ -27,7 +27,9 @@ type APIServer struct {
|
||||
sync.Mutex
|
||||
logger *zap.Logger
|
||||
erupeConfig *cfg.Config
|
||||
db *sqlx.DB
|
||||
userRepo APIUserRepo
|
||||
charRepo APICharacterRepo
|
||||
sessionRepo APISessionRepo
|
||||
httpServer *http.Server
|
||||
isShuttingDown bool
|
||||
}
|
||||
@@ -37,9 +39,13 @@ func NewAPIServer(config *Config) *APIServer {
|
||||
s := &APIServer{
|
||||
logger: config.Logger,
|
||||
erupeConfig: config.ErupeConfig,
|
||||
db: config.DB,
|
||||
httpServer: &http.Server{},
|
||||
}
|
||||
if config.DB != nil {
|
||||
s.userRepo = NewAPIUserRepository(config.DB)
|
||||
s.charRepo = NewAPICharacterRepository(config.DB)
|
||||
s.sessionRepo = NewAPISessionRepository(config.DB)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user