gateway: add parentRef field to project group update api

and make all the request fields optional
This commit is contained in:
Simone Gotti 2019-10-01 09:37:13 +02:00
parent bd3852809c
commit 11da186913
3 changed files with 24 additions and 7 deletions

View File

@ -105,8 +105,10 @@ func (h *ActionHandler) CreateProjectGroup(ctx context.Context, req *CreateProje
}
type UpdateProjectGroupRequest struct {
Name string
Visibility cstypes.Visibility
Name *string
ParentRef *string
Visibility *cstypes.Visibility
}
func (h *ActionHandler) UpdateProjectGroup(ctx context.Context, projectGroupRef string, req *UpdateProjectGroupRequest) (*csapitypes.ProjectGroup, error) {
@ -123,8 +125,15 @@ func (h *ActionHandler) UpdateProjectGroup(ctx context.Context, projectGroupRef
return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
}
pg.Name = req.Name
pg.Visibility = req.Visibility
if req.Name != nil {
pg.Name = *req.Name
}
if req.ParentRef != nil {
pg.Parent.ID = *req.ParentRef
}
if req.Visibility != nil {
pg.Visibility = *req.Visibility
}
h.log.Infof("updating project group")
rp, resp, err := h.configstoreClient.UpdateProjectGroup(ctx, pg.ID, pg.ProjectGroup)

View File

@ -100,9 +100,16 @@ func (h *UpdateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
return
}
var visibility *cstypes.Visibility
if req.Visibility != nil {
v := cstypes.Visibility(*req.Visibility)
visibility = &v
}
areq := &action.UpdateProjectGroupRequest{
Name: req.Name,
Visibility: cstypes.Visibility(req.Visibility),
ParentRef: req.ParentRef,
Visibility: visibility,
}
projectGroup, err := h.ah.UpdateProjectGroup(ctx, projectGroupRef, areq)
if httpError(w, err) {

View File

@ -21,8 +21,9 @@ type CreateProjectGroupRequest struct {
}
type UpdateProjectGroupRequest struct {
Name string `json:"name,omitempty"`
Visibility Visibility `json:"visibility,omitempty"`
Name *string `json:"name,omitempty"`
ParentRef *string `json:"parent_ref,omitempty"`
Visibility *Visibility `json:"visibility,omitempty"`
}
type ProjectGroupResponse struct {