Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions admin/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ type DB interface {
DeleteProjectAccessRequest(ctx context.Context, id string) error

FindBookmarks(ctx context.Context, projectID, resourceKind, resourceName, userID string) ([]*Bookmark, error)
FindBookmarksForProject(ctx context.Context, projectID, userID, afterID string, limit int) ([]*Bookmark, error)
FindBookmark(ctx context.Context, bookmarkID string) (*Bookmark, error)
FindDefaultBookmark(ctx context.Context, projectID, resourceKind, resourceName string) (*Bookmark, error)
InsertBookmark(ctx context.Context, opts *InsertBookmarkOptions) (*Bookmark, error)
Expand Down
23 changes: 23 additions & 0 deletions admin/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -2813,6 +2813,29 @@ func (c *connection) FindBookmarks(ctx context.Context, projectID, resourceKind,
return res, nil
}

func (c *connection) FindBookmarksForProject(ctx context.Context, projectID, userID, afterID string, limit int) ([]*database.Bookmark, error) {
var res []*database.Bookmark

var err error
if afterID != "" {
err = c.getDB(ctx).SelectContext(ctx, &res, `
SELECT * FROM bookmarks
WHERE project_id = $1 AND (user_id = $2 or shared = true or "default" = true) AND id > $3
ORDER BY id LIMIT $4
`, projectID, userID, afterID, limit)
} else {
err = c.getDB(ctx).SelectContext(ctx, &res, `
SELECT * FROM bookmarks
WHERE project_id = $1 AND (user_id = $2 or shared = true or "default" = true)
ORDER BY id LIMIT $3
`, projectID, userID, limit)
}
if err != nil {
return nil, parseErr("bookmarks", err)
}
return res, nil
}

// FindBookmark returns a bookmark for given bookmark id
func (c *connection) FindBookmark(ctx context.Context, bookmarkID string) (*database.Bookmark, error) {
res := &database.Bookmark{}
Expand Down
23 changes: 21 additions & 2 deletions admin/server/bookmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,37 @@ func (s *Server) ListBookmarks(ctx context.Context, req *adminv1.ListBookmarksRe
return nil, status.Error(codes.Unauthenticated, "not authenticated as a user")
}

bookmarks, err := s.admin.DB.FindBookmarks(ctx, req.ProjectId, req.ResourceKind, req.ResourceName, claims.OwnerID())
var bookmarks []*database.Bookmark
var err error

token, err := unmarshalPageToken(req.PageToken)
if err != nil {
return nil, err
}
pageSize := validPageSize(req.PageSize)

if req.ResourceName != "" {
bookmarks, err = s.admin.DB.FindBookmarks(ctx, req.ProjectId, req.ResourceKind, req.ResourceName, claims.OwnerID())
} else {
bookmarks, err = s.admin.DB.FindBookmarksForProject(ctx, req.ProjectId, claims.OwnerID(), token.Val, pageSize)
}
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

nextToken := ""
if len(bookmarks) >= pageSize {
nextToken = marshalPageToken(bookmarks[len(bookmarks)-1].ID)
}

dtos := make([]*adminv1.Bookmark, len(bookmarks))
for i, bookmark := range bookmarks {
dtos[i] = bookmarkToPB(bookmark)
}

return &adminv1.ListBookmarksResponse{
Bookmarks: dtos,
Bookmarks: dtos,
NextPageToken: nextToken,
}, nil
}

Expand Down
Loading
Loading