Skip to content

Commit 8ab25f0

Browse files
author
swann croiset
authored
Merge pull request #11 from peopledoc/api/group-parents
api /groups/{env} - add query parameter "?parent=1"
2 parents 6bb946a + 5572842 commit 8ab25f0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

api/handlers/groups.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ type groupsHandler struct {
1818
}
1919

2020
func (gH groupsHandler) list(w http.ResponseWriter, r *http.Request) {
21-
log.Trace("hosts path called")
2221
vars := mux.Vars(r)
22+
var parents bool
23+
if vars["parents"] == "1" {
24+
parents = true
25+
log.Trace("group (with parents) path called")
26+
} else {
27+
log.Trace("group path called")
28+
}
29+
2330
helperPath := path.Join(
2431
viper.GetString("environments.path"), viper.GetString("environments.helper"))
2532

@@ -44,7 +51,7 @@ func (gH groupsHandler) list(w http.ResponseWriter, r *http.Request) {
4451
}
4552
w.Header().Set("Content-Type", "application/json")
4653

47-
groups, err := manipulator.GetGroupsName(false)
54+
groups, err := manipulator.GetGroupsName(parents)
4855
if err != nil {
4956
logErrorToResponse(err, "groups", w)
5057
return

api/handlers/handlers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func API(log *log.Logger) http.Handler {
3131

3232
//groups
3333
gH := groupsHandler{log}
34+
router.HandleFunc("/groups/{env}", gH.list).
35+
Methods("GET").Queries("parents", "{parents:[01]}")
3436
router.HandleFunc("/groups/{env}", gH.list).
3537
Methods("GET")
3638

0 commit comments

Comments
 (0)