(ctx context.Context, orgID uuid.UUID, filterOpts *biz.ListGroupOpts, paginationOpts *pagination.OffsetPaginationOpts)
| 57 | } |
| 58 | |
| 59 | func (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 |
nothing calls this directly
no test coverage detected