Skip to content

Commit 3b27e18

Browse files
authored
Merge pull request #46 from topcoder-platform/issues-313
Issues-313:add endpoint to pull all members for a group
2 parents 7f7d7b0 + 6d2723f commit 3b27e18

File tree

3 files changed

+109
-7
lines changed

3 files changed

+109
-7
lines changed

controllers/api/GroupsApiController.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,50 @@ public function post_members($id, array $body) {
202202
$this->groupModel->join($group->GroupID, $user->UserID, $watch, $follow);
203203
}
204204

205+
/**
206+
* Get all members of a group.
207+
*
208+
* @param int $id The ID of the group.
209+
* @throws NotFoundException if the group could not be found.
210+
* @return array
211+
*/
212+
public function get_members($id, array $query) {
213+
$this->permission();
214+
$in = $this->schema([
215+
'page:i?' => [
216+
'description' => 'Page number. See [Pagination](https://docs.vanillaforums.com/apiv2/#pagination).',
217+
'default' => 1,
218+
'minimum' => 1,
219+
],
220+
'limit:i?' => [
221+
'description' => 'Desired number of items per page.',
222+
'default' => 30,
223+
'minimum' => 1,
224+
'maximum' => 100,
225+
]
226+
], 'in')->setDescription('The list of group members.');
227+
228+
$out = $this->schema([
229+
':a' => [
230+
'userID:i', // The ID of the user.
231+
'name:s', // The username of the user.
232+
],
233+
], 'out');
234+
235+
$group = $this->groupModel->getID($id, DATASET_TYPE_ARRAY);
236+
if (!$group) {
237+
throw new NotFoundException('Group');
238+
}
239+
240+
$query = $in->validate($query);
241+
list($offset, $limit) = offsetLimit("p{$query['page']}", $query['limit']);
242+
$records = $this->groupModel->getMembers($id, [], '',$limit, $offset );
243+
$result = $out->validate($records);
244+
$paging = ApiUtils::morePagerInfo($result, '/api/v2/groups/'.$id.'/members', $query, $in);
245+
246+
return new Data($result, ['paging' => $paging]);
247+
}
248+
205249
/**
206250
* Archive a group.
207251
*

controllers/class.groupcontroller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function edit($groupID = false) {
201201

202202
// Set Type dropbox
203203
if($Group->Type == GroupModel::TYPE_REGULAR || $groupID === false) { // Regular Groups can be created from UI only
204-
$typesData = [GroupModel::TYPE_REGULAR => GroupModel::TYPE_REGULAR, GroupModel::TYPE_CHALLENGE => GroupModel::TYPE_CHALLENGE];
204+
$typesData = [GroupModel::TYPE_REGULAR => GroupModel::TYPE_REGULAR];
205205
} else if ($Group->Type == GroupModel::TYPE_CHALLENGE){
206206
$typesData = [GroupModel::TYPE_CHALLENGE => GroupModel::TYPE_CHALLENGE];
207207
}

openapi/groups.yml

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,29 @@ paths:
1414
type: string
1515
x-filter:
1616
field: ChallengeID
17-
- description: |
18-
Filter by group type.
17+
- description: Filter by group type.
1918
in: query
2019
name: type
20+
schema:
21+
type: string
22+
default: challenge
23+
enum:
24+
- challenge
25+
- regular
26+
x-filter:
27+
field: Type
28+
- description: Filter by group privacy.
29+
in: query
30+
name: privacy
2131
schema:
2232
type: string
2333
default: public
2434
enum:
25-
- public
26-
- private
27-
- secret
35+
- public
36+
- private
37+
- secret
2838
x-filter:
29-
field: Type
39+
field: Privacy
3040
- $ref: '#/components/parameters/Page'
3141
- description: |
3242
Desired number of items per page.
@@ -128,6 +138,42 @@ paths:
128138
- Groups
129139
summary: Remove a user from a group.
130140
'/groups/{id}/members':
141+
get:
142+
parameters:
143+
- description: The group ID.
144+
in: path
145+
name: id
146+
required: true
147+
schema:
148+
type: integer
149+
- description: |
150+
Page number. See [Pagination](https://docs.vanillaforums.com/apiv2/#pagination).
151+
in: query
152+
name: page
153+
schema:
154+
type: integer
155+
default: 1
156+
minimum: 1
157+
- description: Desired number of items per page.
158+
in: query
159+
name: limit
160+
schema:
161+
type: integer
162+
default: 30
163+
maximum: 100
164+
minimum: 1
165+
responses:
166+
'200':
167+
content:
168+
'application/json':
169+
schema:
170+
items:
171+
$ref: '#/components/schemas/GroupMember'
172+
type: array
173+
description: Success
174+
tags:
175+
- Groups
176+
summary: The list of group members.
131177
post:
132178
parameters:
133179
- description: The group ID.
@@ -280,3 +326,15 @@ components:
280326
required:
281327
- userID
282328
type: object
329+
GroupMember:
330+
properties:
331+
userID:
332+
description: The userID of an user.
333+
type: integer
334+
name:
335+
description: The name of an user.
336+
type: string
337+
required:
338+
- userID
339+
- name
340+
type: object

0 commit comments

Comments
 (0)