V3-975 Create db pagination query for team members (#871)
* V3-975 Create db pagination query for team members * fix go mod tidy * Methods renamed. Picked go.sum from storj/master. * fixing linter
This commit is contained in:
parent
a5aaf54e7d
commit
90f79e585c
@ -16,6 +16,8 @@ type ProjectMembers interface {
|
||||
GetByMemberID(ctx context.Context, memberID uuid.UUID) (*ProjectMember, error)
|
||||
// GetByProjectID is a method for querying project members from the database by projectID.
|
||||
GetByProjectID(ctx context.Context, projectID uuid.UUID) ([]ProjectMember, error)
|
||||
// GetByProjectIDPaged is a method for querying project members from the database by projectID, offset and limit.
|
||||
GetByProjectIDPaged(ctx context.Context, projectID uuid.UUID, limit, offset int64) ([]ProjectMember, error)
|
||||
// Insert is a method for inserting project member into the database.
|
||||
Insert(ctx context.Context, memberID, projectID uuid.UUID) (*ProjectMember, error)
|
||||
// Delete is a method for deleting project member by memberID and projectID from the database.
|
||||
|
@ -98,6 +98,10 @@ read one (
|
||||
select project_member
|
||||
where project_member.member_id = ?
|
||||
)
|
||||
read limitoffset (
|
||||
select project_member
|
||||
where project_member.project_id = ?
|
||||
)
|
||||
create project_member ( )
|
||||
delete project_member (
|
||||
where project_member.member_id = ?
|
||||
|
@ -1473,6 +1473,42 @@ func (obj *sqlite3Impl) Get_ProjectMember_By_MemberId(ctx context.Context,
|
||||
|
||||
}
|
||||
|
||||
func (obj *sqlite3Impl) Limited_ProjectMember_By_ProjectId(ctx context.Context,
|
||||
project_member_project_id ProjectMember_ProjectId_Field,
|
||||
limit int, offset int64) (
|
||||
rows []*ProjectMember, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("SELECT project_members.member_id, project_members.project_id, project_members.created_at FROM project_members WHERE project_members.project_id = ? LIMIT ? OFFSET ?")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, project_member_project_id.value())
|
||||
|
||||
__values = append(__values, limit, offset)
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
__rows, err := obj.driver.Query(__stmt, __values...)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
defer __rows.Close()
|
||||
|
||||
for __rows.Next() {
|
||||
project_member := &ProjectMember{}
|
||||
err = __rows.Scan(&project_member.MemberId, &project_member.ProjectId, &project_member.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
rows = append(rows, project_member)
|
||||
}
|
||||
if err := __rows.Err(); err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return rows, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *sqlite3Impl) Update_User_By_Id(ctx context.Context,
|
||||
user_id User_Id_Field,
|
||||
update User_Update_Fields) (
|
||||
@ -2145,6 +2181,17 @@ func (rx *Rx) Get_User_By_Id(ctx context.Context,
|
||||
return tx.Get_User_By_Id(ctx, user_id)
|
||||
}
|
||||
|
||||
func (rx *Rx) Limited_ProjectMember_By_ProjectId(ctx context.Context,
|
||||
project_member_project_id ProjectMember_ProjectId_Field,
|
||||
limit int, offset int64) (
|
||||
rows []*ProjectMember, err error) {
|
||||
var tx *Tx
|
||||
if tx, err = rx.getTx(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
return tx.Limited_ProjectMember_By_ProjectId(ctx, project_member_project_id, limit, offset)
|
||||
}
|
||||
|
||||
func (rx *Rx) Update_Company_By_UserId(ctx context.Context,
|
||||
company_user_id Company_UserId_Field,
|
||||
update Company_Update_Fields) (
|
||||
@ -2263,6 +2310,11 @@ type Methods interface {
|
||||
user_id User_Id_Field) (
|
||||
user *User, err error)
|
||||
|
||||
Limited_ProjectMember_By_ProjectId(ctx context.Context,
|
||||
project_member_project_id ProjectMember_ProjectId_Field,
|
||||
limit int, offset int64) (
|
||||
rows []*ProjectMember, err error)
|
||||
|
||||
Update_Company_By_UserId(ctx context.Context,
|
||||
company_user_id Company_UserId_Field,
|
||||
update Company_Update_Fields) (
|
||||
|
@ -39,6 +39,21 @@ func (pm *projectMembers) GetByProjectID(ctx context.Context, projectID uuid.UUI
|
||||
return projectMembersFromDbxSlice(projectMembersDbx)
|
||||
}
|
||||
|
||||
// GetByProjectIDPaged is a method for querying project members from the database by projectID, offset and limit.
|
||||
func (pm *projectMembers) GetByProjectIDPaged(ctx context.Context, projectID uuid.UUID, limit, offset int64) ([]satellite.ProjectMember, error) {
|
||||
projectMembersDbx, err := pm.db.Limited_ProjectMember_By_ProjectId(
|
||||
ctx,
|
||||
dbx.ProjectMember_ProjectId(projectID[:]),
|
||||
int(limit),
|
||||
offset)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return projectMembersFromDbxSlice(projectMembersDbx)
|
||||
}
|
||||
|
||||
// Insert is a method for inserting project member into the database.
|
||||
func (pm *projectMembers) Insert(ctx context.Context, memberID, projectID uuid.UUID) (*satellite.ProjectMember, error) {
|
||||
createdProjectMember, err := pm.db.Create_ProjectMember(ctx,
|
||||
|
@ -75,6 +75,26 @@ func TestProjectMembersRepository(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Get paged", func(t *testing.T) {
|
||||
members, err := projectMembers.GetByProjectIDPaged(ctx, createdProjects[0].ID, 1, 0)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, members)
|
||||
assert.Equal(t, 1, len(members))
|
||||
|
||||
members, err = projectMembers.GetByProjectIDPaged(ctx, createdProjects[0].ID, 2, 0)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, members)
|
||||
assert.Equal(t, 2, len(members))
|
||||
|
||||
members, err = projectMembers.GetByProjectIDPaged(ctx, createdProjects[0].ID, 1, 1)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, members)
|
||||
assert.Equal(t, 1, len(members))
|
||||
})
|
||||
|
||||
t.Run("Get member by memberID success", func(t *testing.T) {
|
||||
originalMember1 := createdUsers[0]
|
||||
selectedMember1, err := projectMembers.GetByMemberID(ctx, originalMember1.ID)
|
||||
|
@ -20,6 +20,9 @@ import (
|
||||
"storj.io/storj/pkg/utils"
|
||||
)
|
||||
|
||||
// TODO: Use maxLimit in future.
|
||||
//const maxLimit = 50
|
||||
|
||||
// Service is handling accounts related logic
|
||||
type Service struct {
|
||||
Signer
|
||||
@ -326,12 +329,16 @@ func (s *Service) DeleteProjectMember(ctx context.Context, projectID, userID uui
|
||||
}
|
||||
|
||||
// GetProjectMembers returns ProjectMembers for given Project
|
||||
// TODO: add limit and offset parameters
|
||||
func (s *Service) GetProjectMembers(ctx context.Context, projectID uuid.UUID) ([]ProjectMember, error) {
|
||||
_, err := GetAuth(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: check if limit < maxLimit const
|
||||
|
||||
// TODO: replace GetByProjectID with GetByProjectIDPaged and remove GetByProjectID as redundant
|
||||
return s.store.ProjectMembers().GetByProjectID(ctx, projectID)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user