feat(handler): update GetFile and ListFiles handlers for new FileResponse fields
- GetFile uses new GetFileResponse instead of manual FileResponse construction - ListFiles handler parses optional user_id query parameter - Wire FolderStore into FileService in app.go, testenv, and file_test Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -18,14 +18,19 @@ import (
|
||||
)
|
||||
|
||||
type mockFileService struct {
|
||||
listFilesFn func(ctx context.Context, folderID *int64, page, pageSize int, search string) ([]model.FileResponse, int64, error)
|
||||
listFilesFn func(ctx context.Context, folderID *int64, userID *int64, page, pageSize int, search string) ([]model.FileResponse, int64, error)
|
||||
getFileResponseFn func(ctx context.Context, fileID int64) (*model.FileResponse, error)
|
||||
getFileMetadataFn func(ctx context.Context, fileID int64) (*model.File, *model.FileBlob, error)
|
||||
downloadFileFn func(ctx context.Context, fileID int64, rangeHeader string) (io.ReadCloser, *model.File, *model.FileBlob, int64, int64, error)
|
||||
deleteFileFn func(ctx context.Context, fileID int64) error
|
||||
}
|
||||
|
||||
func (m *mockFileService) ListFiles(ctx context.Context, folderID *int64, page, pageSize int, search string) ([]model.FileResponse, int64, error) {
|
||||
return m.listFilesFn(ctx, folderID, page, pageSize, search)
|
||||
func (m *mockFileService) ListFiles(ctx context.Context, folderID *int64, userID *int64, page, pageSize int, search string) ([]model.FileResponse, int64, error) {
|
||||
return m.listFilesFn(ctx, folderID, userID, page, pageSize, search)
|
||||
}
|
||||
|
||||
func (m *mockFileService) GetFileResponse(ctx context.Context, fileID int64) (*model.FileResponse, error) {
|
||||
return m.getFileResponseFn(ctx, fileID)
|
||||
}
|
||||
|
||||
func (m *mockFileService) GetFileMetadata(ctx context.Context, fileID int64) (*model.File, *model.FileBlob, error) {
|
||||
@@ -67,7 +72,7 @@ func newFileHandlerSetup() *fileHandlerSetup {
|
||||
|
||||
func TestListFiles_Empty(t *testing.T) {
|
||||
s := newFileHandlerSetup()
|
||||
s.mock.listFilesFn = func(ctx context.Context, folderID *int64, page, pageSize int, search string) ([]model.FileResponse, int64, error) {
|
||||
s.mock.listFilesFn = func(ctx context.Context, folderID *int64, userID *int64, page, pageSize int, search string) ([]model.FileResponse, int64, error) {
|
||||
return []model.FileResponse{}, 0, nil
|
||||
}
|
||||
|
||||
@@ -97,7 +102,7 @@ func TestListFiles_Empty(t *testing.T) {
|
||||
func TestListFiles_WithFiles(t *testing.T) {
|
||||
s := newFileHandlerSetup()
|
||||
now := time.Now()
|
||||
s.mock.listFilesFn = func(ctx context.Context, folderID *int64, page, pageSize int, search string) ([]model.FileResponse, int64, error) {
|
||||
s.mock.listFilesFn = func(ctx context.Context, folderID *int64, userID *int64, page, pageSize int, search string) ([]model.FileResponse, int64, error) {
|
||||
return []model.FileResponse{
|
||||
{ID: 1, Name: "a.txt", Size: 100, MimeType: "text/plain", SHA256: "abc123", CreatedAt: now, UpdatedAt: now},
|
||||
{ID: 2, Name: "b.pdf", Size: 200, MimeType: "application/pdf", SHA256: "def456", CreatedAt: now, UpdatedAt: now},
|
||||
@@ -133,7 +138,7 @@ func TestListFiles_WithFiles(t *testing.T) {
|
||||
func TestListFiles_WithFolderID(t *testing.T) {
|
||||
s := newFileHandlerSetup()
|
||||
var capturedFolderID *int64
|
||||
s.mock.listFilesFn = func(ctx context.Context, folderID *int64, page, pageSize int, search string) ([]model.FileResponse, int64, error) {
|
||||
s.mock.listFilesFn = func(ctx context.Context, folderID *int64, userID *int64, page, pageSize int, search string) ([]model.FileResponse, int64, error) {
|
||||
capturedFolderID = folderID
|
||||
return []model.FileResponse{}, 0, nil
|
||||
}
|
||||
@@ -152,7 +157,7 @@ func TestListFiles_WithFolderID(t *testing.T) {
|
||||
|
||||
func TestListFiles_ServiceError(t *testing.T) {
|
||||
s := newFileHandlerSetup()
|
||||
s.mock.listFilesFn = func(ctx context.Context, folderID *int64, page, pageSize int, search string) ([]model.FileResponse, int64, error) {
|
||||
s.mock.listFilesFn = func(ctx context.Context, folderID *int64, userID *int64, page, pageSize int, search string) ([]model.FileResponse, int64, error) {
|
||||
return nil, 0, fmt.Errorf("db error")
|
||||
}
|
||||
|
||||
@@ -170,12 +175,11 @@ func TestListFiles_ServiceError(t *testing.T) {
|
||||
func TestGetFile_Found(t *testing.T) {
|
||||
s := newFileHandlerSetup()
|
||||
now := time.Now()
|
||||
s.mock.getFileMetadataFn = func(ctx context.Context, fileID int64) (*model.File, *model.FileBlob, error) {
|
||||
return &model.File{
|
||||
ID: 1, Name: "test.txt", BlobSHA256: "abc123", CreatedAt: now, UpdatedAt: now,
|
||||
}, &model.FileBlob{
|
||||
ID: 1, SHA256: "abc123", FileSize: 1024, MimeType: "text/plain", CreatedAt: now,
|
||||
}, nil
|
||||
rootPath := "/"
|
||||
s.mock.getFileResponseFn = func(ctx context.Context, fileID int64) (*model.FileResponse, error) {
|
||||
return &model.FileResponse{
|
||||
ID: 1, Name: "test.txt", SHA256: "abc123", FolderPath: &rootPath, CreatedAt: now, UpdatedAt: now,
|
||||
}, nil
|
||||
}
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
@@ -195,8 +199,8 @@ func TestGetFile_Found(t *testing.T) {
|
||||
|
||||
func TestGetFile_NotFound(t *testing.T) {
|
||||
s := newFileHandlerSetup()
|
||||
s.mock.getFileMetadataFn = func(ctx context.Context, fileID int64) (*model.File, *model.FileBlob, error) {
|
||||
return nil, nil, fmt.Errorf("file not found: 999")
|
||||
s.mock.getFileResponseFn = func(ctx context.Context, fileID int64) (*model.FileResponse, error) {
|
||||
return nil, fmt.Errorf("file not found: 999")
|
||||
}
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
Reference in New Issue
Block a user