Skip to content

Commit 25cb1ef

Browse files
New API routes added
1 parent 58bdff5 commit 25cb1ef

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

models/user.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,16 @@ func SearchUsers(opts *SearchUserOptions) (users []*User, _ int64, _ error) {
13601360
Find(&users)
13611361
}
13621362

1363+
func SearchUsersAPI(opts *SearchUserOptions) (users []*User,_ int64,_ error){
1364+
cond := opts.toConds()
1365+
count,err := x.Where(cond).Count(new(User))
1366+
if err!=nil{
1367+
return nil,0,fmt.Errorf("Count: %v",err)
1368+
}
1369+
users = make([]*User,0,count)
1370+
return users,count,x.Where(cond).OrderBy(opts.OrderBy.String()).Find(&users)
1371+
}
1372+
13631373
// GetStarredRepos returns the repos starred by a particular user
13641374
func GetStarredRepos(userID int64, private bool) ([]*Repository, error) {
13651375
sess := x.Where("star.uid=?", userID).

routers/api/v1/admin/org.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,20 @@ func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) {
6666

6767
ctx.JSON(201, convert.ToOrganization(org))
6868
}
69+
70+
func GetAllOrgs(ctx *context.APIContext){
71+
users,_,err := models.SearchUsersAPI(&models.SearchUserOptions{
72+
Type: models.UserTypeOrganization,
73+
OrderBy: models.SearchOrderByAlphabetically,
74+
Keyword: "",
75+
})
76+
if err != nil{
77+
ctx.Error(500,"SearchOrganizations",err)
78+
return
79+
}
80+
orgs := make([]*api.Organization,len(users))
81+
for i := range users{
82+
orgs[i] = convert.ToOrganization(users[i])
83+
}
84+
ctx.JSON(200,&orgs)
85+
}

routers/api/v1/admin/user.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,16 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
291291

292292
ctx.Status(204)
293293
}
294+
295+
func GetAllUsers(ctx *context.APIContext){
296+
users,_,err := models.SearchUsersAPI(&models.SearchUserOptions{
297+
Type: models.UserTypeIndividual,
298+
OrderBy: models.SearchOrderByAlphabetically,
299+
Keyword: "",
300+
})
301+
if err != nil {
302+
ctx.Error(500,"SearchUsers",err)
303+
return
304+
}
305+
ctx.JSON(200,&users)
306+
}

routers/api/v1/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,9 @@ func RegisterRoutes(m *macaron.Macaron) {
667667
})
668668

669669
m.Group("/admin", func() {
670+
m.Get("/orgs",admin.GetAllOrgs)
670671
m.Group("/users", func() {
672+
m.Get("",admin.GetAllUsers)
671673
m.Post("", bind(api.CreateUserOption{}), admin.CreateUser)
672674
m.Group("/:username", func() {
673675
m.Combo("").Patch(bind(api.EditUserOption{}), admin.EditUser).
@@ -676,6 +678,7 @@ func RegisterRoutes(m *macaron.Macaron) {
676678
m.Post("", bind(api.CreateKeyOption{}), admin.CreatePublicKey)
677679
m.Delete("/:id", admin.DeleteUserPublicKey)
678680
})
681+
m.Get("/orgs",org.ListUserOrgs)
679682
m.Post("/orgs", bind(api.CreateOrgOption{}), admin.CreateOrg)
680683
m.Post("/repos", bind(api.CreateRepoOption{}), admin.CreateRepo)
681684
})

0 commit comments

Comments
 (0)