Commit 8edc6b6a8c240322499356df96e1199bb6bbc872
1 parent
61833bcb
Exists in
master
and in
4 other branches
Add api for creating/listing/viewing groups
Showing
3 changed files
with
62 additions
and
1 deletions
Show diff stats
lib/api.rb
lib/api/entities.rb
... | ... | @@ -32,6 +32,16 @@ module Gitlab |
32 | 32 | end |
33 | 33 | end |
34 | 34 | |
35 | + class Group < Grape::Entity | |
36 | + expose :id, :name, :path, :name, :owner_id, :type | |
37 | + end | |
38 | + | |
39 | + class GroupDetail < Grape::Entity | |
40 | + expose :id, :name, :path, :name, :owner_id, :type | |
41 | + expose :projects, using: Entities::Project | |
42 | + end | |
43 | + | |
44 | + | |
35 | 45 | class RepoObject < Grape::Entity |
36 | 46 | expose :name, :commit |
37 | 47 | expose :protected do |repo, options| | ... | ... |
... | ... | @@ -0,0 +1,50 @@ |
1 | +module Gitlab | |
2 | + # groups API | |
3 | + class Groups < Grape::API | |
4 | + before { authenticate! } | |
5 | + | |
6 | + resource :groups do | |
7 | + # Get a groups list | |
8 | + # | |
9 | + # Example Request: | |
10 | + # GET /groups | |
11 | + get do | |
12 | + @groups = paginate Group | |
13 | + present @groups, with: Entities::Group | |
14 | + | |
15 | + end | |
16 | + | |
17 | + # Create group. Available only for admin | |
18 | + # | |
19 | + # Parameters: | |
20 | + # name (required) - Name | |
21 | + # path (required) - Path | |
22 | + # Example Request: | |
23 | + # POST /groups | |
24 | + post do | |
25 | + authenticated_as_admin! | |
26 | + attrs = attributes_for_keys [:name, :path] | |
27 | + @group = Group.new(attrs) | |
28 | + @group.owner = current_user | |
29 | + | |
30 | + if @group.save | |
31 | + present @group, with: Entities::Group | |
32 | + else | |
33 | + not_found! | |
34 | + end | |
35 | + end | |
36 | + | |
37 | + # Get a single group, with containing projects | |
38 | + # | |
39 | + # Parameters: | |
40 | + # id (required) - The ID of a group | |
41 | + # Example Request: | |
42 | + # GET /groups/:id | |
43 | + get ":id" do | |
44 | + @group = Group.find(params[:id]) | |
45 | + present @group, with: Entities::GroupDetail | |
46 | + end | |
47 | + | |
48 | + end | |
49 | + end | |
50 | +end | ... | ... |