MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / List

Method List

app/controlplane/pkg/data/group.go:59–125  ·  view source on GitHub ↗
(ctx context.Context, orgID uuid.UUID, filterOpts *biz.ListGroupOpts, paginationOpts *pagination.OffsetPaginationOpts)

Source from the content-addressed store, hash-verified

57}
58
59func (g GroupRepo) List(ctx context.Context, orgID uuid.UUID, filterOpts *biz.ListGroupOpts, paginationOpts *pagination.OffsetPaginationOpts) ([]*biz.Group, int, error) {
60 ctx, span := otelx.Start(ctx, groupRepoTracer, "GroupRepo.List")
61 defer span.End()
62
63 if filterOpts == nil {
64 filterOpts = &biz.ListGroupOpts{}
65 }
66
67 query := g.data.DB.Group.Query().
68 Where(group.DeletedAtIsNil(), group.OrganizationIDEQ(orgID)).
69 WithGroupMemberships().WithOrganization()
70
71 // filter by UserID if provided. It will be applied on top of rest of filters
72 if filterOpts.UserID != nil {
73 query.Where(group.HasGroupMembershipsWith(
74 groupmembership.UserID(*filterOpts.UserID),
75 groupmembership.DeletedAtIsNil(),
76 ))
77 }
78
79 // Apply filters as ORs if any additional filter is provided
80 var predicates []predicate.Group
81 if filterOpts.Name != "" {
82 predicates = append(predicates, group.NameContains(filterOpts.Name))
83 }
84
85 if filterOpts.Description != "" {
86 predicates = append(predicates, group.DescriptionContains(filterOpts.Description))
87 }
88
89 if filterOpts.MemberEmail != "" {
90 predicates = append(predicates,
91 group.HasGroupMembershipsWith(
92 groupmembership.DeletedAtIsNil(),
93 groupmembership.HasUserWith(user.EmailContains(filterOpts.MemberEmail)),
94 ),
95 )
96 }
97
98 // Apply OR predicates if any exist
99 if len(predicates) > 0 {
100 query.Where(group.Or(predicates...))
101 }
102
103 // Get the count of all filtered rows without the limit and offset
104 count, err := query.Count(ctx)
105 if err != nil {
106 return nil, 0, err
107 }
108
109 // Apply pagination options and execute the query
110 groups, err := query.
111 Order(ent.Desc(group.FieldCreatedAt)).
112 Limit(paginationOpts.Limit()).
113 Offset(paginationOpts.Offset()).
114 All(ctx)
115 if err != nil {
116 return nil, 0, err

Callers

nothing calls this directly

Implementers 1

GroupRepoapp/controlplane/pkg/data/group.go

Calls 15

StartFunction · 0.92
DeletedAtIsNilFunction · 0.92
OrganizationIDEQFunction · 0.92
HasGroupMembershipsWithFunction · 0.92
UserIDFunction · 0.92
DeletedAtIsNilFunction · 0.92
NameContainsFunction · 0.92
DescriptionContainsFunction · 0.92
HasUserWithFunction · 0.92
EmailContainsFunction · 0.92
OrFunction · 0.92
DescFunction · 0.92

Tested by

no test coverage detected