CreateDashboard: Fix response code

Since this REST endpoint creates a new dashboard resource the response
code should be '201 Created' instead of '200 OK'. Strictly speaking this
is an API-breaking change, but it's unlikely that clients check the
exact response code and also the dashboard functionality is not widely
used. This means the risk of breaking callers is very small.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I7715156e0026e65d7962bd6699b5f3b5387b1d4a
This commit is contained in:
Edwin Kempin
2019-08-05 15:59:58 +02:00
parent b446055fc0
commit 339cb31c2f
2 changed files with 66 additions and 8 deletions

View File

@@ -2787,17 +2787,18 @@ dashboard-id.
}
----
[[set-dashboard]]
=== Set Dashboard
[[create-dashboard]]
=== Create Dashboard
--
'PUT /projects/link:#project-name[\{project-name\}]/dashboards/link:#dashboard-id[\{dashboard-id\}]'
--
Updates/Creates a project dashboard.
Creates a project dashboard, if a project dashboard with the given
dashboard ID doesn't exist yet.
Currently only supported for the `default` dashboard.
The creation/update information for the dashboard must be provided in
The creation information for the dashboard must be provided in
the request body as a link:#dashboard-input[DashboardInput] entity.
.Request
@@ -2811,7 +2812,63 @@ the request body as a link:#dashboard-input[DashboardInput] entity.
}
----
As response the new/updated dashboard is returned as a
As response the new dashboard is returned as a link:#dashboard-info[
DashboardInfo] entity.
.Response
----
HTTP/1.1 201 Created
Content-Disposition: attachment
Content-Type: application/json; charset=UTF-8
)]}'
{
"id": "main:closed",
"ref": "main",
"path": "closed",
"description": "Merged and abandoned changes in last 7 weeks",
"url": "/dashboard/?title\u003dClosed+changes\u0026Merged\u003dstatus:merged+age:7w\u0026Abandoned\u003dstatus:abandoned+age:7w",
"is_default": true,
"title": "Closed changes",
"sections": [
{
"name": "Merged",
"query": "status:merged age:7w"
},
{
"name": "Abandoned",
"query": "status:abandoned age:7w"
}
]
}
----
[[update-dashboard]]
=== Update Dashboard
--
'PUT /projects/link:#project-name[\{project-name\}]/dashboards/link:#dashboard-id[\{dashboard-id\}]'
--
Updates a project dashboard, if a project dashboard with the given
dashboard ID already exists.
Currently only supported for the `default` dashboard.
The update information for the dashboard must be provided in
the request body as a link:#dashboard-input[DashboardInput] entity.
.Request
----
PUT /projects/work%2Fmy-project/dashboards/default HTTP/1.0
Content-Type: application/json; charset=UTF-8
{
"id": "main:closed",
"commit_message": "Update the default dashboard"
}
----
As response the updated dashboard is returned as a
link:#dashboard-info[DashboardInfo] entity.
.Response

View File

@@ -52,8 +52,9 @@ public class CreateDashboard
}
SetDefaultDashboard set = setDefault.get();
set.inherited = inherited;
// TODO(ekempin): This should return Response.created(...) since it creates a new dashboard.
return set.apply(
DashboardResource.projectDefault(parent.getProjectState(), parent.getUser()), input);
return Response.created(
set.apply(
DashboardResource.projectDefault(parent.getProjectState(), parent.getUser()), input)
.value());
}
}