Skip to content

Commit bccb4b4

Browse files
committed
add pagination
1 parent b2c24bc commit bccb4b4

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

code/go/0chain.net/blobbercore/handler/handler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,11 @@ func ListShare(ctx context.Context, r *http.Request) (interface{}, error) {
663663
clientID = ctx.Value(constants.ContextKeyClient).(string)
664664
)
665665

666+
limit, err := common.GetOffsetLimitOrderParam(r.URL.Query())
667+
if err != nil {
668+
return nil, err
669+
}
670+
666671
allocationObj, err := storageHandler.verifyAllocation(ctx, allocationID, true)
667672
if err != nil {
668673
return nil, common.NewError("invalid_parameters", "Invalid allocation id passed."+err.Error())
@@ -679,7 +684,7 @@ func ListShare(ctx context.Context, r *http.Request) (interface{}, error) {
679684
return nil, common.NewError("invalid_client", "Client has no access to share file")
680685
}
681686

682-
shares, err := reference.ListShareInfoClientID(ctx, clientID)
687+
shares, err := reference.ListShareInfoClientID(ctx, clientID, limit)
683688
if err != nil {
684689
Logger.Error("failed_to_list_share", zap.Error(err))
685690
return nil, common.NewError("failed_to_list_share", "failed to list file share")

code/go/0chain.net/blobbercore/reference/shareinfo.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore"
8+
"github.com/0chain/blobber/code/go/0chain.net/core/common"
89
"gorm.io/gorm"
910
)
1011

@@ -30,17 +31,13 @@ func AddShareInfo(ctx context.Context, shareInfo *ShareInfo) error {
3031
return db.Model(&ShareInfo{}).Create(shareInfo).Error
3132
}
3233

33-
// ListShareInfo returns list of files I shared?? or list of files shared with??
34-
func ListShareInfoOwnerID(ctx context.Context, ownerID string) error {
35-
db := datastore.GetStore().GetTransaction(ctx)
36-
return db.Model(&ShareInfo{}).Where("owner_id=?", ownerID).Error // todo: fix
37-
}
38-
39-
// ListShareInfo returns list of files I shared?? or list of files shared with??
40-
func ListShareInfoClientID(ctx context.Context, clientID string) ([]ShareInfo, error) {
34+
// ListShareInfo returns list of files by a given clientID
35+
func ListShareInfoClientID(ctx context.Context, clientID string, limit common.Pagination) ([]ShareInfo, error) {
4136
db := datastore.GetStore().GetTransaction(ctx)
4237
var shares []ShareInfo
43-
err := db.Where("client_id <> ?", clientID).Find(&shares).Error
38+
query := db.Where("client_id = ?", clientID).Where("revoked = ?", false).Limit(limit.Limit).Offset(limit.Offset)
39+
40+
err := query.Find(&shares).Error
4441
return shares, err
4542
}
4643

0 commit comments

Comments
 (0)