gateway: add parentRef field to project update api

and make all the request fields optional
This commit is contained in:
Simone Gotti 2019-09-24 15:19:17 +02:00
parent 7e6a143e40
commit 8b9464486d
3 changed files with 24 additions and 7 deletions

View File

@ -180,8 +180,10 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq
} }
type UpdateProjectRequest struct { type UpdateProjectRequest struct {
Name string Name *string
Visibility cstypes.Visibility ParentRef *string
Visibility *cstypes.Visibility
} }
func (h *ActionHandler) UpdateProject(ctx context.Context, projectRef string, req *UpdateProjectRequest) (*csapitypes.Project, error) { func (h *ActionHandler) UpdateProject(ctx context.Context, projectRef string, req *UpdateProjectRequest) (*csapitypes.Project, error) {
@ -198,8 +200,15 @@ func (h *ActionHandler) UpdateProject(ctx context.Context, projectRef string, re
return nil, util.NewErrForbidden(errors.Errorf("user not authorized")) return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
} }
p.Name = req.Name if req.Name != nil {
p.Visibility = req.Visibility p.Name = *req.Name
}
if req.ParentRef != nil {
p.Parent.ID = *req.ParentRef
}
if req.Visibility != nil {
p.Visibility = *req.Visibility
}
h.log.Infof("updating project") h.log.Infof("updating project")
rp, resp, err := h.configstoreClient.UpdateProject(ctx, p.ID, p.Project) rp, resp, err := h.configstoreClient.UpdateProject(ctx, p.ID, p.Project)

View File

@ -94,9 +94,16 @@ func (h *UpdateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
return return
} }
var visibility *cstypes.Visibility
if req.Visibility != nil {
v := cstypes.Visibility(*req.Visibility)
visibility = &v
}
areq := &action.UpdateProjectRequest{ areq := &action.UpdateProjectRequest{
Name: req.Name, Name: req.Name,
Visibility: cstypes.Visibility(req.Visibility), ParentRef: req.ParentRef,
Visibility: visibility,
} }
project, err := h.ah.UpdateProject(ctx, projectRef, areq) project, err := h.ah.UpdateProject(ctx, projectRef, areq)
if httpError(w, err) { if httpError(w, err) {

View File

@ -24,8 +24,9 @@ type CreateProjectRequest struct {
} }
type UpdateProjectRequest struct { type UpdateProjectRequest struct {
Name string `json:"name,omitempty"` Name *string `json:"name,omitempty"`
Visibility Visibility `json:"visibility,omitempty"` ParentRef *string `json:"parent_ref,omitempty"`
Visibility *Visibility `json:"visibility,omitempty"`
} }
type ProjectResponse struct { type ProjectResponse struct {