feat(dbfs): set default share shortcut for new users

This commit is contained in:
Aaron Liu
2025-05-23 15:39:57 +08:00
parent 9f5ebe11b6
commit c6ee3e5dcd
7 changed files with 104 additions and 7 deletions

View File

@@ -31,6 +31,8 @@ var (
type (
ShareClient interface {
TxOperator
// GetByIDs returns the shares with given ids.
GetByIDs(ctx context.Context, ids []int) ([]*ent.Share, error)
// GetByID returns the share with given id.
GetByID(ctx context.Context, id int) (*ent.Share, error)
// GetByIDUser returns the share with given id and user id.
@@ -67,6 +69,7 @@ type (
UserID int
FileID int
PublicOnly bool
ShareIDs []int
}
ListShareResult struct {
*PaginationResults
@@ -168,6 +171,15 @@ func (c *shareClient) GetByIDUser(ctx context.Context, id, uid int) (*ent.Share,
return s, nil
}
func (c *shareClient) GetByIDs(ctx context.Context, ids []int) ([]*ent.Share, error) {
s, err := withShareEagerLoading(ctx, c.client.Share.Query().Where(share.IDIn(ids...))).All(ctx)
if err != nil {
return nil, fmt.Errorf("failed to query shares %v: %w", ids, err)
}
return s, nil
}
func (c *shareClient) DeleteBatch(ctx context.Context, shareIds []int) error {
_, err := c.client.Share.Delete().Where(share.IDIn(shareIds...)).Exec(ctx)
return err
@@ -332,6 +344,10 @@ func (c *shareClient) listQuery(args *ListShareArgs) *ent.ShareQuery {
query.Where(share.HasFileWith(file.ID(args.FileID)))
}
if len(args.ShareIDs) > 0 {
query.Where(share.IDIn(args.ShareIDs...))
}
return query
}