Actually make fucking interfaces
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Package repositories provides database repository implementations
|
||||
// with a clean separation of concerns and proper interface abstractions.
|
||||
package repositories
|
||||
|
||||
import (
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// CacheRepository handles cache-related database operations
|
||||
// Implements CacheRepositoryInterface
|
||||
type CacheRepository struct {
|
||||
*BaseRepository
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// CharacterRepository handles character-related database operations
|
||||
// Implements CharacterRepositoryInterface
|
||||
type CharacterRepository struct {
|
||||
*BaseRepository
|
||||
}
|
||||
|
||||
@@ -14,10 +14,11 @@ import (
|
||||
)
|
||||
|
||||
// Database manages all repositories and provides a unified interface
|
||||
// Implements DatabaseInterface
|
||||
type Database struct {
|
||||
*gorm.DB
|
||||
Character *CharacterRepository
|
||||
Cache *CacheRepository
|
||||
character *CharacterRepository
|
||||
cache *CacheRepository
|
||||
}
|
||||
|
||||
// NewDatabase creates a new database instance with all repositories
|
||||
@@ -49,8 +50,8 @@ func NewDatabase() (*Database, error) {
|
||||
|
||||
database := &Database{
|
||||
DB: db,
|
||||
Character: characterRepo,
|
||||
Cache: cacheRepo,
|
||||
character: characterRepo,
|
||||
cache: cacheRepo,
|
||||
}
|
||||
|
||||
// Run migrations
|
||||
@@ -62,3 +63,13 @@ func NewDatabase() (*Database, error) {
|
||||
logger.Info("Database initialized successfully")
|
||||
return database, nil
|
||||
}
|
||||
|
||||
// Character returns the character repository
|
||||
func (d *Database) Character() CharacterRepositoryInterface {
|
||||
return d.character
|
||||
}
|
||||
|
||||
// Cache returns the cache repository
|
||||
func (d *Database) Cache() CacheRepositoryInterface {
|
||||
return d.cache
|
||||
}
|
||||
|
||||
@@ -7,3 +7,16 @@ type CharacterRepositoryInterface interface {
|
||||
GetCharacterByName(characterName string) (*types.Character, error)
|
||||
SaveCharacter(character *types.Character) error
|
||||
}
|
||||
|
||||
// CacheRepositoryInterface defines the interface for cache operations
|
||||
type CacheRepositoryInterface interface {
|
||||
GetCacheEntry(urlHash string) (*types.CacheEntry, error)
|
||||
SaveCacheEntry(entry *types.CacheEntry) error
|
||||
}
|
||||
|
||||
// DatabaseInterface defines the interface for database management
|
||||
type DatabaseInterface interface {
|
||||
Character() CharacterRepositoryInterface
|
||||
Cache() CacheRepositoryInterface
|
||||
AutoMigrate(dst ...interface{}) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user