Add file management API with local storage backend
- Implement FileHandler with CRUD operations for files/directories - Add FileService with business logic and SHA-256 hashing - Create LocalStorage backend for filesystem persistence - Add database repository with pagination and name uniqueness constraints - Configure max upload size in storage settings - Include comprehensive tests for all layers
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/dhao2001/mygo/internal/config"
|
||||
"github.com/dhao2001/mygo/internal/repository"
|
||||
"github.com/dhao2001/mygo/internal/service"
|
||||
"github.com/dhao2001/mygo/internal/storage"
|
||||
)
|
||||
|
||||
// WebApp contains application-wide runtime dependencies and metadata.
|
||||
@@ -21,6 +22,8 @@ type WebApp struct {
|
||||
FileRepo repository.FileRepository
|
||||
CredentialRepo repository.CredentialRepository
|
||||
AuthService *service.AuthService
|
||||
FileService *service.FileService
|
||||
Storage storage.StorageBackend
|
||||
}
|
||||
|
||||
// Bootstrap creates a fully initialized WebApp from config.
|
||||
@@ -48,6 +51,13 @@ func Bootstrap(cfg *config.Config) (*WebApp, error) {
|
||||
cfg.JWT.RefreshTTL,
|
||||
)
|
||||
|
||||
store, err := storage.NewLocalStorage(cfg.Storage.Local.Path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("init storage: %w", err)
|
||||
}
|
||||
|
||||
fileService := service.NewFileService(fileRepo, store, cfg.Storage.MaxUploadSize)
|
||||
|
||||
return &WebApp{
|
||||
Config: cfg,
|
||||
Version: AppVersion,
|
||||
@@ -57,6 +67,8 @@ func Bootstrap(cfg *config.Config) (*WebApp, error) {
|
||||
FileRepo: fileRepo,
|
||||
CredentialRepo: credentialRepo,
|
||||
AuthService: authService,
|
||||
FileService: fileService,
|
||||
Storage: store,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -67,6 +79,8 @@ func NewWebApp(cfg *config.Config, db *gorm.DB,
|
||||
fileRepo repository.FileRepository,
|
||||
credentialRepo repository.CredentialRepository,
|
||||
authService *service.AuthService,
|
||||
fileService *service.FileService,
|
||||
store storage.StorageBackend,
|
||||
) *WebApp {
|
||||
return &WebApp{
|
||||
Config: cfg,
|
||||
@@ -77,6 +91,8 @@ func NewWebApp(cfg *config.Config, db *gorm.DB,
|
||||
FileRepo: fileRepo,
|
||||
CredentialRepo: credentialRepo,
|
||||
AuthService: authService,
|
||||
FileService: fileService,
|
||||
Storage: store,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
func TestNewWebApp(t *testing.T) {
|
||||
cfg := &config.Config{}
|
||||
|
||||
webApp := NewWebApp(cfg, nil, nil, nil, nil, nil, nil)
|
||||
webApp := NewWebApp(cfg, nil, nil, nil, nil, nil, nil, nil, nil)
|
||||
|
||||
if webApp.Config != cfg {
|
||||
t.Fatal("Config was not assigned")
|
||||
@@ -20,7 +20,7 @@ func TestNewWebApp(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCloseNilDB(t *testing.T) {
|
||||
webApp := NewWebApp(&config.Config{}, nil, nil, nil, nil, nil, nil)
|
||||
webApp := NewWebApp(&config.Config{}, nil, nil, nil, nil, nil, nil, nil, nil)
|
||||
if err := webApp.Close(); err != nil {
|
||||
t.Errorf("Close with nil DB should not error: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user