Browse Source

Bug 23859: Make POST add the Location header on cities endpoint

According to the coding guidelines, this endpoint should be adding the
Location header on POST actions.

To test:
1. Apply the tests patch
2. Run:
    $ kshell
    k$ prove t/db_dependent/api/v1/cities.t
=> FAIL: Tests fail!
3. Apply this patch
4. Repeat (1)
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
remotes/origin/19.11.x
Tomas Cohen Arazi 3 years ago
committed by Martin Renvoize
parent
commit
4de24b70e5
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 6
      Koha/REST/V1/Cities.pm
  2. 2
      api/v1/swagger/paths/cities.json

6
Koha/REST/V1/Cities.pm

@ -78,7 +78,11 @@ sub add {
return try {
my $city = Koha::City->new( _to_model( $c->validation->param('body') ) );
$city->store;
return $c->render( status => 200, openapi => $city->to_api );
$c->res->headers->location( $c->req->url->to_string . '/' . $city->cityid );
return $c->render(
status => 201,
openapi => $city->to_api
);
}
catch {
if ( $_->isa('DBIx::Class::Exception') ) {

2
api/v1/swagger/paths/cities.json

@ -84,7 +84,7 @@
"application/json"
],
"responses": {
"200": {
"201": {
"description": "City added",
"schema": {
"$ref": "../definitions.json#/city"

Loading…
Cancel
Save