update
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"portal-mini-go/internal/pkg/errors"
|
||||
"portal-mini-go/internal/pkg/storage"
|
||||
"portal-mini-go/internal/pkg/types"
|
||||
"portal-mini-go/internal/repository/file"
|
||||
)
|
||||
|
||||
// 文件相关业务错误(业务码沿用现有 40xxx/41xxx/50xxx 段)。
|
||||
@@ -31,6 +32,7 @@ type FileRepository interface {
|
||||
Create(ctx context.Context, f *model.File) error
|
||||
GetByID(ctx context.Context, id uint64) (*model.File, error)
|
||||
Delete(ctx context.Context, id uint64) error
|
||||
List(ctx context.Context, filter file.ListFilter) ([]model.File, int64, error)
|
||||
}
|
||||
|
||||
// Service 文件上传业务服务。
|
||||
@@ -114,6 +116,33 @@ func (s *Service) Get(ctx context.Context, id uint64) (*model.File, error) {
|
||||
return s.repo.GetByID(ctx, id)
|
||||
}
|
||||
|
||||
// ListReq 文件列表查询条件。
|
||||
type ListReq struct {
|
||||
UploaderType string // 上传者类型(admin/ma),空表示不限
|
||||
UploaderID uint64 // 上传者主键,0 表示不限
|
||||
Keyword string // 模糊匹配 origin_name 或 filename
|
||||
Page int // 页码,从 1 开始
|
||||
Size int // 每页条数
|
||||
}
|
||||
|
||||
// List 分页查询文件,缺省第 1 页、每页 20 条。
|
||||
func (s *Service) List(ctx context.Context, req ListReq) ([]model.File, int64, error) {
|
||||
page, size := req.Page, req.Size
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
if size <= 0 {
|
||||
size = 20
|
||||
}
|
||||
return s.repo.List(ctx, file.ListFilter{
|
||||
UploaderType: req.UploaderType,
|
||||
UploaderID: req.UploaderID,
|
||||
Keyword: req.Keyword,
|
||||
Page: page,
|
||||
Size: size,
|
||||
})
|
||||
}
|
||||
|
||||
// Download 返回文件读取流与元数据;调用方负责关闭流。
|
||||
func (s *Service) Download(ctx context.Context, id uint64) (io.ReadCloser, *model.File, error) {
|
||||
f, err := s.repo.GetByID(ctx, id)
|
||||
|
||||
Reference in New Issue
Block a user