feat(model,service): add folder_path and user_id to FileResponse, add user_id filter to ListFiles
- FileResponse gains folder_path ("/" for root) and user_id fields
- folder_id no longer uses omitempty, root files return null
- ListFiles accepts optional userID parameter for filtering by owner
- New buildFileResponse helper populates folder_path from FolderStore
- New GetFileResponse method wraps GetFileMetadata + buildFileResponse
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -78,7 +78,7 @@ func setupFileTestDB(t *testing.T) *gorm.DB {
|
||||
if err != nil {
|
||||
t.Fatalf("open sqlite: %v", err)
|
||||
}
|
||||
if err := db.AutoMigrate(&model.File{}, &model.FileBlob{}); err != nil {
|
||||
if err := db.AutoMigrate(&model.File{}, &model.FileBlob{}, &model.Folder{}); err != nil {
|
||||
t.Fatalf("migrate: %v", err)
|
||||
}
|
||||
return db
|
||||
@@ -88,7 +88,7 @@ func setupFileService(t *testing.T) (*FileService, *mockFileStorage, *gorm.DB) {
|
||||
t.Helper()
|
||||
db := setupFileTestDB(t)
|
||||
ms := &mockFileStorage{}
|
||||
svc := NewFileService(ms, store.NewBlobStore(db), store.NewFileStore(db), "test-bucket", db, zap.NewNop())
|
||||
svc := NewFileService(ms, store.NewBlobStore(db), store.NewFileStore(db), store.NewFolderStore(db), "test-bucket", db, zap.NewNop())
|
||||
return svc, ms, db
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func createTestFile(t *testing.T, db *gorm.DB, name, blobSHA256 string, folderID
|
||||
func TestListFiles_Empty(t *testing.T) {
|
||||
svc, _, _ := setupFileService(t)
|
||||
|
||||
files, total, err := svc.ListFiles(context.Background(), nil, 1, 10, "")
|
||||
files, total, err := svc.ListFiles(context.Background(), nil, nil, 1, 10, "")
|
||||
if err != nil {
|
||||
t.Fatalf("ListFiles: %v", err)
|
||||
}
|
||||
@@ -142,7 +142,7 @@ func TestListFiles_WithFiles(t *testing.T) {
|
||||
createTestFile(t, db, "file1.txt", blob.SHA256, nil)
|
||||
createTestFile(t, db, "file2.txt", blob.SHA256, nil)
|
||||
|
||||
files, total, err := svc.ListFiles(context.Background(), nil, 1, 10, "")
|
||||
files, total, err := svc.ListFiles(context.Background(), nil, nil, 1, 10, "")
|
||||
if err != nil {
|
||||
t.Fatalf("ListFiles: %v", err)
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func TestListFiles_Search(t *testing.T) {
|
||||
createTestFile(t, db, "document.pdf", "sha256other", nil)
|
||||
createTestBlob(t, db, "sha256other", "blobs/other", "application/pdf", 512, 1)
|
||||
|
||||
files, total, err := svc.ListFiles(context.Background(), nil, 1, 10, "photo")
|
||||
files, total, err := svc.ListFiles(context.Background(), nil, nil, 1, 10, "photo")
|
||||
if err != nil {
|
||||
t.Fatalf("ListFiles: %v", err)
|
||||
}
|
||||
@@ -446,7 +446,7 @@ func TestListFiles_WithFolderFilter(t *testing.T) {
|
||||
createTestFile(t, db, "in_folder.txt", blob.SHA256, &folderID)
|
||||
createTestFile(t, db, "root.txt", blob.SHA256, nil)
|
||||
|
||||
files, total, err := svc.ListFiles(context.Background(), &folderID, 1, 10, "")
|
||||
files, total, err := svc.ListFiles(context.Background(), &folderID, nil, 1, 10, "")
|
||||
if err != nil {
|
||||
t.Fatalf("ListFiles: %v", err)
|
||||
}
|
||||
@@ -460,7 +460,7 @@ func TestListFiles_WithFolderFilter(t *testing.T) {
|
||||
t.Errorf("expected in_folder.txt, got %s", files[0].Name)
|
||||
}
|
||||
|
||||
rootFiles, rootTotal, err := svc.ListFiles(context.Background(), nil, 1, 10, "")
|
||||
rootFiles, rootTotal, err := svc.ListFiles(context.Background(), nil, nil, 1, 10, "")
|
||||
if err != nil {
|
||||
t.Fatalf("ListFiles root: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user