Bugzilla – Attachment 96706 Details for
Bug 24321
Make objects.search use mappings from Koha::Object(s)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24312: Clean /cities
Bug-24312-Clean-cities.patch (text/plain), 5.26 KB, created by
Tomás Cohen Arazi (tcohen)
on 2019-12-31 14:52:24 UTC
(
hide
)
Description:
Bug 24312: Clean /cities
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2019-12-31 14:52:24 UTC
Size:
5.26 KB
patch
obsolete
>From 659e55e8ceee60609f30bcbe1c3002b1d934c9dc Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 31 Dec 2019 10:35:15 -0300 >Subject: [PATCH] Bug 24312: Clean /cities > >https://bugs.koha-community.org/show_bug.cgi?id=24321 >--- > Koha/REST/V1/Cities.pm | 89 +--------------------------------- > t/db_dependent/api/v1/cities.t | 16 +++--- > 2 files changed, 10 insertions(+), 95 deletions(-) > >diff --git a/Koha/REST/V1/Cities.pm b/Koha/REST/V1/Cities.pm >index bbc54defcb..e458fe3fc6 100644 >--- a/Koha/REST/V1/Cities.pm >+++ b/Koha/REST/V1/Cities.pm >@@ -25,7 +25,7 @@ use Try::Tiny; > > =head1 API > >-=head2 Class Methods >+=head2 Methods > > =head3 list > >@@ -36,7 +36,7 @@ sub list { > > return try { > my $cities_set = Koha::Cities->new; >- my $cities = $c->objects->search( $cities_set, \&_to_model, \&_to_api ); >+ my $cities = $c->objects->search( $cities_set ); > return $c->render( status => 200, openapi => $cities ); > } > catch { >@@ -160,89 +160,4 @@ sub delete { > }; > } > >-=head3 _to_api >- >-Helper function that maps a hashref of Koha::City attributes into REST api >-attribute names. >- >-=cut >- >-sub _to_api { >- my $city = shift; >- >- # Rename attributes >- foreach my $column ( keys %{ $Koha::REST::V1::Cities::to_api_mapping } ) { >- my $mapped_column = $Koha::REST::V1::Cities::to_api_mapping->{$column}; >- if ( exists $city->{ $column } >- && defined $mapped_column ) >- { >- # key /= undef >- $city->{ $mapped_column } = delete $city->{ $column }; >- } >- elsif ( exists $city->{ $column } >- && !defined $mapped_column ) >- { >- # key == undef => to be deleted >- delete $city->{ $column }; >- } >- } >- >- return $city; >-} >- >-=head3 _to_model >- >-Helper function that maps REST api objects into Koha::Cities >-attribute names. >- >-=cut >- >-sub _to_model { >- my $city = shift; >- >- foreach my $attribute ( keys %{ $Koha::REST::V1::Cities::to_model_mapping } ) { >- my $mapped_attribute = $Koha::REST::V1::Cities::to_model_mapping->{$attribute}; >- if ( exists $city->{ $attribute } >- && defined $mapped_attribute ) >- { >- # key /= undef >- $city->{ $mapped_attribute } = delete $city->{ $attribute }; >- } >- elsif ( exists $city->{ $attribute } >- && !defined $mapped_attribute ) >- { >- # key == undef => to be deleted >- delete $city->{ $attribute }; >- } >- } >- >- return $city; >-} >- >-=head2 Global variables >- >-=head3 $to_api_mapping >- >-=cut >- >-our $to_api_mapping = { >- cityid => 'city_id', >- city_country => 'country', >- city_name => 'name', >- city_state => 'state', >- city_zipcode => 'postal_code' >-}; >- >-=head3 $to_model_mapping >- >-=cut >- >-our $to_model_mapping = { >- city_id => 'cityid', >- country => 'city_country', >- name => 'city_name', >- postal_code => 'city_zipcode', >- state => 'city_state' >-}; >- > 1; >diff --git a/t/db_dependent/api/v1/cities.t b/t/db_dependent/api/v1/cities.t >index c97e907cc4..17d90515d5 100644 >--- a/t/db_dependent/api/v1/cities.t >+++ b/t/db_dependent/api/v1/cities.t >@@ -71,7 +71,7 @@ subtest 'list() tests' => sub { > # One city created, should get returned > $t->get_ok("//$userid:$password@/api/v1/cities") > ->status_is(200) >- ->json_is( [Koha::REST::V1::Cities::_to_api( $city->TO_JSON )] ); >+ ->json_is( [$city->to_api] ); > > my $another_city = $builder->build_object( > { class => 'Koha::Cities', value => { city_country => $city->city_country } } ); >@@ -80,21 +80,21 @@ subtest 'list() tests' => sub { > # Two cities created, they should both be returned > $t->get_ok("//$userid:$password@/api/v1/cities") > ->status_is(200) >- ->json_is([Koha::REST::V1::Cities::_to_api($city->TO_JSON), >- Koha::REST::V1::Cities::_to_api($another_city->TO_JSON), >- Koha::REST::V1::Cities::_to_api($city_with_another_country->TO_JSON) >+ ->json_is([$city->to_api, >+ $another_city->to_api, >+ $city_with_another_country->to_api > ] ); > > # Filtering works, two cities sharing city_country > $t->get_ok("//$userid:$password@/api/v1/cities?country=" . $city->city_country ) > ->status_is(200) >- ->json_is([ Koha::REST::V1::Cities::_to_api($city->TO_JSON), >- Koha::REST::V1::Cities::_to_api($another_city->TO_JSON) >+ ->json_is([ $city->to_api, >+ $another_city->to_api > ]); > > $t->get_ok("//$userid:$password@/api/v1/cities?name=" . $city->city_name ) > ->status_is(200) >- ->json_is( [Koha::REST::V1::Cities::_to_api($city->TO_JSON)] ); >+ ->json_is( [$city->to_api] ); > > # Warn on unsupported query parameter > $t->get_ok("//$userid:$password@/api/v1/cities?city_blah=blah" ) >@@ -137,7 +137,7 @@ subtest 'get() tests' => sub { > > $t->get_ok( "//$userid:$password@/api/v1/cities/" . $city->cityid ) > ->status_is(200) >- ->json_is(Koha::REST::V1::Cities::_to_api($city->TO_JSON)); >+ ->json_is($city->to_api); > > $t->get_ok( "//$unauth_userid:$password@/api/v1/cities/" . $city->cityid ) > ->status_is(403); >-- >2.24.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24321
:
96703
|
96704
|
96705
|
96706
|
96707
|
96708
|
96709
|
96710
|
96711
|
96712
|
96713
|
96714
|
96715
|
96716
|
96717
|
96718
|
96719
|
96720
|
96721
|
96722
|
96744
|
96840
|
96841
|
96842
|
96843
|
96844
|
96845
|
96846
|
96847
|
96848
|
96849
|
96850
|
96851
|
96852
|
96874
|
96875
|
96876
|
96877
|
96878
|
96879
|
96880
|
96881
|
96882
|
96883
|
96884
|
96885
|
96886
|
96887
|
96939
|
96940
|
96941
|
96942
|
96943
|
96944
|
96945
|
96946
|
96947
|
96948
|
96949
|
96950
|
96951
|
96952