Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RPC endpoint to list child projects #3650

Merged
merged 1 commit into from
Jun 19, 2024
Merged
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
15 changes: 15 additions & 0 deletions database/mock/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions database/query/projects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ WITH RECURSIVE get_children AS (
)
SELECT * FROM get_children;

-- name: GetImmediateChildrenProjects :many

-- GetImmediateChildrenProjects is a query that returns all the immediate children of a project.

SELECT * FROM projects
WHERE parent_id = sqlc.arg(parent_id)::UUID;

-- name: DeleteProject :many
WITH RECURSIVE get_children AS (
Expand Down
24 changes: 24 additions & 0 deletions docs/docs/ref/proto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions internal/controlplane/handlers_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,79 @@ func (s *Server) ListProjects(
return &resp, nil
}

// ListChildProjects returns the list of subprojects for the current project
func (s *Server) ListChildProjects(
ctx context.Context,
req *minderv1.ListChildProjectsRequest,
) (*minderv1.ListChildProjectsResponse, error) {
entityCtx := engine.EntityFromContext(ctx)
projectID := entityCtx.Project.ID

var projs []*minderv1.Project
var err error

if req.Recursive {
projs, err = s.getChildProjects(ctx, projectID)
if err != nil {
return nil, status.Errorf(codes.Internal, "error getting subprojects: %v", err)
}
} else {
projs, err = s.getImmediateChildrenProjects(ctx, projectID)
if err != nil {
return nil, status.Errorf(codes.Internal, "error getting subprojects: %v", err)
}
}

resp := minderv1.ListChildProjectsResponse{
Projects: projs,
}
return &resp, nil
}

func (s *Server) getChildProjects(ctx context.Context, projectID uuid.UUID) ([]*minderv1.Project, error) {
projs, err := s.store.GetChildrenProjects(ctx, projectID)
if err != nil {
return nil, status.Errorf(codes.Internal, "error getting subprojects: %v", err)
}

out := make([]*minderv1.Project, 0, len(projs))
for _, project := range projs {
out = append(out, &minderv1.Project{
ProjectId: project.ID.String(),
Name: project.Name,
Description: "",
// TODO: We need to agree on how to handle metadata for subprojects
DisplayName: project.Name,
CreatedAt: timestamppb.New(project.CreatedAt),
UpdatedAt: timestamppb.New(project.UpdatedAt),
})
}

return out, nil
}

func (s *Server) getImmediateChildrenProjects(ctx context.Context, projectID uuid.UUID) ([]*minderv1.Project, error) {
projs, err := s.store.GetImmediateChildrenProjects(ctx, projectID)
if err != nil {
return nil, status.Errorf(codes.Internal, "error getting subprojects: %v", err)
}

out := make([]*minderv1.Project, 0, len(projs))
for _, project := range projs {
out = append(out, &minderv1.Project{
ProjectId: project.ID.String(),
Name: project.Name,
Description: "",
// TODO: We need to agree on how to handle metadata for subprojects
DisplayName: project.Name,
CreatedAt: timestamppb.New(project.CreatedAt),
UpdatedAt: timestamppb.New(project.UpdatedAt),
})
}

return out, nil
}

// CreateProject creates a new subproject
func (s *Server) CreateProject(
ctx context.Context,
Expand Down
39 changes: 39 additions & 0 deletions internal/db/projects.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/db/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions pkg/api/openapi/minder/v1/minder.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading