gateway: add parentRef field to project update api
and make all the request fields optional
This commit is contained in:
parent
7e6a143e40
commit
8b9464486d
|
@ -180,8 +180,10 @@ func (h *ActionHandler) CreateProject(ctx context.Context, req *CreateProjectReq
|
|||
}
|
||||
|
||||
type UpdateProjectRequest struct {
|
||||
Name string
|
||||
Visibility cstypes.Visibility
|
||||
Name *string
|
||||
ParentRef *string
|
||||
|
||||
Visibility *cstypes.Visibility
|
||||
}
|
||||
|
||||
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"))
|
||||
}
|
||||
|
||||
p.Name = req.Name
|
||||
p.Visibility = req.Visibility
|
||||
if req.Name != nil {
|
||||
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")
|
||||
rp, resp, err := h.configstoreClient.UpdateProject(ctx, p.ID, p.Project)
|
||||
|
|
|
@ -94,9 +94,16 @@ func (h *UpdateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
var visibility *cstypes.Visibility
|
||||
if req.Visibility != nil {
|
||||
v := cstypes.Visibility(*req.Visibility)
|
||||
visibility = &v
|
||||
}
|
||||
|
||||
areq := &action.UpdateProjectRequest{
|
||||
Name: req.Name,
|
||||
Visibility: cstypes.Visibility(req.Visibility),
|
||||
ParentRef: req.ParentRef,
|
||||
Visibility: visibility,
|
||||
}
|
||||
project, err := h.ah.UpdateProject(ctx, projectRef, areq)
|
||||
if httpError(w, err) {
|
||||
|
|
|
@ -24,8 +24,9 @@ type CreateProjectRequest struct {
|
|||
}
|
||||
|
||||
type UpdateProjectRequest 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 ProjectResponse struct {
|
||||
|
|
Loading…
Reference in New Issue