gw api: fix project and remotesource to return the right response
This commit is contained in:
parent
bb21520133
commit
2d68be8a30
|
@ -27,8 +27,6 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/sorintlab/agola/internal/services/types"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
@ -131,30 +129,30 @@ func (c *Client) GetProjectGroupProjects(ctx context.Context, projectGroupRef st
|
|||
return projects, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetProject(ctx context.Context, projectRef string) (*types.Project, *http.Response, error) {
|
||||
project := new(types.Project)
|
||||
func (c *Client) GetProject(ctx context.Context, projectRef string) (*ProjectResponse, *http.Response, error) {
|
||||
project := new(ProjectResponse)
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projects/%s", url.PathEscape(projectRef)), nil, jsonContent, nil, project)
|
||||
return project, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) CreateProjectGroup(ctx context.Context, req *CreateProjectGroupRequest) (*types.Project, *http.Response, error) {
|
||||
func (c *Client) CreateProjectGroup(ctx context.Context, req *CreateProjectGroupRequest) (*ProjectResponse, *http.Response, error) {
|
||||
reqj, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
project := new(types.Project)
|
||||
project := new(ProjectResponse)
|
||||
resp, err := c.getParsedResponse(ctx, "PUT", "/projectgroups", nil, jsonContent, bytes.NewReader(reqj), project)
|
||||
return project, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) CreateProject(ctx context.Context, req *CreateProjectRequest) (*types.Project, *http.Response, error) {
|
||||
func (c *Client) CreateProject(ctx context.Context, req *CreateProjectRequest) (*ProjectResponse, *http.Response, error) {
|
||||
reqj, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
project := new(types.Project)
|
||||
project := new(ProjectResponse)
|
||||
resp, err := c.getParsedResponse(ctx, "PUT", "/projects", nil, jsonContent, bytes.NewReader(reqj), project)
|
||||
return project, resp, err
|
||||
}
|
||||
|
@ -347,13 +345,13 @@ func (c *Client) GetRemoteSources(ctx context.Context, start string, limit int,
|
|||
return rss, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) CreateRemoteSource(ctx context.Context, req *CreateRemoteSourceRequest) (*types.RemoteSource, *http.Response, error) {
|
||||
func (c *Client) CreateRemoteSource(ctx context.Context, req *CreateRemoteSourceRequest) (*RemoteSourceResponse, *http.Response, error) {
|
||||
uj, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
rs := new(types.RemoteSource)
|
||||
rs := new(RemoteSourceResponse)
|
||||
resp, err := c.getParsedResponse(ctx, "PUT", "/remotesources", nil, jsonContent, bytes.NewReader(uj), rs)
|
||||
return rs, resp, err
|
||||
}
|
||||
|
|
|
@ -81,7 +81,8 @@ func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(project); err != nil {
|
||||
res := createProjectResponse(project)
|
||||
if err := json.NewEncoder(w).Encode(res); err != nil {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
|
|
@ -58,13 +58,14 @@ func (h *CreateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
|||
return
|
||||
}
|
||||
|
||||
user, err := h.createRemoteSource(ctx, &req)
|
||||
rs, err := h.createRemoteSource(ctx, &req)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(user); err != nil {
|
||||
res := createRemoteSourceResponse(rs)
|
||||
if err := json.NewEncoder(w).Encode(res); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue