- PostgreSQL metadata overlay layer on top of existing S3 storage - 3 new tables: folders, files, share_links - Folder CRUD: create, get with children, tree, rename, delete (cascade) - File operations: upload to folder, move between folders - Share links: create with optional password/expiry/download limit, public access - S3 compensation on PG write failure - Existing 14 endpoints untouched
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
|
|
"rag/file-system/internal/common"
|
|
"rag/file-system/internal/domain/model"
|
|
"rag/file-system/internal/domain/repository"
|
|
)
|
|
|
|
type GetFolderQuery struct {
|
|
FolderID string
|
|
OwnerID string
|
|
}
|
|
|
|
type GetFolderTreeQuery struct {
|
|
OwnerID string
|
|
}
|
|
|
|
type GetFolderHandler struct {
|
|
FolderRepo repository.FolderRepository
|
|
}
|
|
|
|
func NewGetFolderHandler(folderRepo repository.FolderRepository) *GetFolderHandler {
|
|
return &GetFolderHandler{FolderRepo: folderRepo}
|
|
}
|
|
|
|
func (h *GetFolderHandler) Handle(ctx context.Context, q GetFolderQuery) (*model.FolderWithChildren, error) {
|
|
result, err := h.FolderRepo.GetWithChildren(ctx, q.FolderID, q.OwnerID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if result == nil {
|
|
return nil, common.NewNotFoundError("目录不存在")
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
type GetFolderTreeHandler struct {
|
|
FolderRepo repository.FolderRepository
|
|
}
|
|
|
|
func NewGetFolderTreeHandler(folderRepo repository.FolderRepository) *GetFolderTreeHandler {
|
|
return &GetFolderTreeHandler{FolderRepo: folderRepo}
|
|
}
|
|
|
|
func (h *GetFolderTreeHandler) Handle(ctx context.Context, q GetFolderTreeQuery) ([]model.Folder, error) {
|
|
return h.FolderRepo.GetTree(ctx, q.OwnerID)
|
|
}
|