List retrieves a list of groups within the current organization, with optional filters and pagination.
(ctx context.Context, req *pb.GroupServiceListRequest)
| 115 | |
| 116 | // List retrieves a list of groups within the current organization, with optional filters and pagination. |
| 117 | func (g *GroupService) List(ctx context.Context, req *pb.GroupServiceListRequest) (*pb.GroupServiceListResponse, error) { |
| 118 | currentOrg, err := requireCurrentOrg(ctx) |
| 119 | if err != nil { |
| 120 | return nil, err |
| 121 | } |
| 122 | |
| 123 | // Parse orgID |
| 124 | orgUUID, err := uuid.Parse(currentOrg.ID) |
| 125 | if err != nil { |
| 126 | return nil, errors.BadRequest("invalid", "invalid organization ID") |
| 127 | } |
| 128 | |
| 129 | // Initialize the pagination options, with default values |
| 130 | paginationOpts, err := initializePaginationOpts(req.GetPagination()) |
| 131 | if err != nil { |
| 132 | return nil, handleUseCaseErr(err, g.log) |
| 133 | } |
| 134 | |
| 135 | // Initialize the filters |
| 136 | filters := &biz.ListGroupOpts{} |
| 137 | |
| 138 | if req.GetName() != "" { |
| 139 | filters.Name = req.GetName() |
| 140 | } |
| 141 | |
| 142 | if req.GetDescription() != "" { |
| 143 | filters.Description = req.GetDescription() |
| 144 | } |
| 145 | |
| 146 | if req.GetMemberEmail() != "" { |
| 147 | filters.MemberEmail = req.GetMemberEmail() |
| 148 | } |
| 149 | |
| 150 | grs, count, err := g.groupUseCase.List(ctx, orgUUID, filters, paginationOpts) |
| 151 | if err != nil { |
| 152 | return nil, handleUseCaseErr(err, g.log) |
| 153 | } |
| 154 | |
| 155 | // Convert the groups to protobuf messages |
| 156 | result := make([]*pb.Group, 0, len(grs)) |
| 157 | for _, gr := range grs { |
| 158 | result = append(result, bizGroupToPb(gr)) |
| 159 | } |
| 160 | return &pb.GroupServiceListResponse{ |
| 161 | Groups: result, |
| 162 | Pagination: paginationToPb(count, paginationOpts.Offset(), paginationOpts.Limit()), |
| 163 | }, nil |
| 164 | } |
| 165 | |
| 166 | // Update updates an existing group in the organization. |
| 167 | func (g *GroupService) Update(ctx context.Context, req *pb.GroupServiceUpdateRequest) (*pb.GroupServiceUpdateResponse, error) { |
nothing calls this directly
no test coverage detected