update: 更新模型列表查询接口以支持私有化过滤

This commit is contained in:
2026-05-12 14:08:29 +08:00
parent 37d3461983
commit adf1d0ae6e
4 changed files with 16 additions and 8 deletions

View File

@@ -90,7 +90,7 @@ func (d *modelDao) Get(ctx context.Context, id int64) (m *entity.AsynchModel, er
return
}
func (d *modelDao) List(ctx context.Context, pageNum, pageSize int, modelNameLike string, modelType int) (list []*entity.AsynchModel, total int64, err error) {
func (d *modelDao) List(ctx context.Context, pageNum, pageSize int, modelNameLike string, modelType int, isPrivate int) (list []*entity.AsynchModel, total int64, err error) {
model := gfdb.DB(ctx).Model(ctx, public.TableNameModel).
OrderDesc(entity.AsynchModelCol.CreatedAt)
if modelNameLike != "" {
@@ -99,6 +99,9 @@ func (d *modelDao) List(ctx context.Context, pageNum, pageSize int, modelNameLik
if modelType != 0 {
model = model.Where(entity.AsynchModelCol.ModelsType, modelType)
}
if isPrivate != 0 {
model = model.Where(entity.AsynchModelCol.IsPrivate, isPrivate)
}
if pageNum > 0 && pageSize > 0 {
model = model.Page(pageNum, pageSize)
}
@@ -148,7 +151,7 @@ func (d *modelDao) ListByCreatorAndPlatform(ctx context.Context, creator string,
return
}
func (d *modelDao) GetByCreatorAndPlatform(ctx context.Context, creator string, modelNameLike string, modelType int) (list []*entity.AsynchModel, err error) {
func (d *modelDao) GetByCreatorAndPlatform(ctx context.Context, creator string, modelNameLike string, modelType int, isPrivate int) (list []*entity.AsynchModel, err error) {
whereSQL := "deleted_at IS NULL AND (tenant_id = 1 OR creator = ?)"
args := []any{creator}
@@ -160,6 +163,10 @@ func (d *modelDao) GetByCreatorAndPlatform(ctx context.Context, creator string,
whereSQL += " AND models_type = ?"
args = append(args, modelType)
}
if isPrivate != 0 {
whereSQL += " AND is_private = ?"
args = append(args, isPrivate)
}
querySQL := fmt.Sprintf("SELECT * FROM %s WHERE %s ORDER BY created_at DESC", public.TableNameModel, whereSQL)