Bugzilla – Attachment 158084 Details for
Bug 34008
REST API: Add a list (GET) endpoint for itemtypes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34008: Harmonize attribute names
Bug-34008-Harmonize-attribute-names.patch (text/plain), 8.91 KB, created by
Tomás Cohen Arazi (tcohen)
on 2023-10-30 16:18:23 UTC
(
hide
)
Description:
Bug 34008: Harmonize attribute names
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2023-10-30 16:18:23 UTC
Size:
8.91 KB
patch
obsolete
>From a5c93a0512a3f1c75ef72ac77edf2e5c75e78bb0 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 30 Oct 2023 13:14:16 -0300 >Subject: [PATCH] Bug 34008: Harmonize attribute names > >This patch harmonizes the attribute names with what is used for `items` >and `checkouts` in terms of terminology. > >It also adapts the tests so they are less random failure-prone (they had >a fixed value for the item type, which might make things explode if the >chosen value already exists on the DB. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/ItemType.pm | 15 +++++++- > Koha/Schema/Result/Itemtype.pm | 6 ++- > api/v1/swagger/definitions/item_type.yaml | 32 ++++++++-------- > t/db_dependent/api/v1/item_types.t | 46 +++++++++-------------- > 4 files changed, 51 insertions(+), 48 deletions(-) > >diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm >index 3aed3ec81f2..fb88518c257 100644 >--- a/Koha/ItemType.pm >+++ b/Koha/ItemType.pm >@@ -221,7 +221,20 @@ on the API. > =cut > > sub to_api_mapping { >- return { 'itemtype' => 'item_type_id' }; >+ return { >+ checkinmsg => 'checkin_message', >+ checkinmsgtype => 'checkin_message_type', >+ defaultreplacecost => 'default_replacement_cost', >+ hideinopac => 'hide_in_opac', >+ imageurl => 'image_url', >+ itemtype => 'item_type_id', >+ notforloan => 'not_for_loan_status', >+ processfee => 'process_fee', >+ rentalcharge_daily => 'daily_rental_charge', >+ rentalcharge_daily_calendar => 'daily_rental_charge_calendar', >+ rentalcharge_hourly => 'hourly_rental_charge', >+ rentalcharge_hourly_calendar => 'hourly_rental_charge_calendar', >+ }; > } > > =head2 Internal methods >diff --git a/Koha/Schema/Result/Itemtype.pm b/Koha/Schema/Result/Itemtype.pm >index 99fb6de5a58..d005da023f4 100644 >--- a/Koha/Schema/Result/Itemtype.pm >+++ b/Koha/Schema/Result/Itemtype.pm >@@ -337,9 +337,11 @@ __PACKAGE__->has_many( > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SoRKIMEqXE2+RkGq6zBejA > > __PACKAGE__->add_columns( >- '+rentalcharge_hourly_calendar' => { is_boolean => 1 }, >- '+rentalcharge_daily_calendar' => { is_boolean => 1 }, > '+automatic_checkin' => { is_boolean => 1 }, >+ '+hideinopac' => { is_boolean => 1 }, >+ '+notforloan' => { is_boolean => 1 }, >+ '+rentalcharge_daily_calendar' => { is_boolean => 1 }, >+ '+rentalcharge_hourly_calendar' => { is_boolean => 1 }, > ); > > # Use the ItemtypeLocalization view to create the join on localization >diff --git a/api/v1/swagger/definitions/item_type.yaml b/api/v1/swagger/definitions/item_type.yaml >index 789fe5fcd91..f451c2892ba 100644 >--- a/api/v1/swagger/definitions/item_type.yaml >+++ b/api/v1/swagger/definitions/item_type.yaml >@@ -18,38 +18,36 @@ properties: > type: > - number > - "null" >- rentalcharge_daily: >+ daily_rental_charge: > description: The amount charged for each day between checkout date and due date > type: > - number > - "null" >- rentalcharge_daily_calendar: >+ daily_rental_charge_calendar: > description: Controls if the daily rental fee is calculated directly or using finesCalendar > type: boolean >- rentalcharge_hourly: >+ hourly_rental_charge: > description: The amount charged for each hour between checkout date and due date > type: > - number > - "null" >- rentalcharge_hourly_calendar: >+ hourly_rental_charge_calendar: > description: Controls if the hourly rental fee is calculated directly or using finesCalendar > type: boolean >- defaultreplacecost: >+ default_replacement_cost: > description: Default replacement cost > type: > - number > - "null" >- processfee: >+ process_fee: > description: Default text be recorded in the column note when the processing fee is applied > type: > - number > - "null" >- notforloan: >- description: Controls if the item is available for loan >- type: >- - boolean >- - "null" >- imageurl: >+ not_for_loan_status: >+ description: If items of this type are not for loan >+ type: boolean >+ image_url: > description: URL for the item type icon > type: > - string >@@ -59,13 +57,13 @@ properties: > type: > - string > - "null" >- checkinmsg: >+ checkin_message: > description: Message that is displayed when an item with the given item type is checked in > type: > - string > - "null" >- checkinmsgtype: >- description: Type (CSS class) for the checkinmsg, can be 'alert' or 'message' >+ checkin_message_type: >+ description: Type (CSS class) for the checkin_message, can be 'alert' or 'message' > type: > - string > - "null" >@@ -74,7 +72,7 @@ properties: > type: > - string > - "null" >- hideinopac: >+ hide_in_opac: > description: Hide the item type from the search options in OPAC > type: boolean > searchcategory: >@@ -86,7 +84,7 @@ properties: > description: Controls if automatic checkin is enabled for items of this type > type: boolean > translated_descriptions: >- description: Translations of description plain text >+ description: Translations of description plain text (x-koha-embed) > type: array > items: > $ref: "item_type_translated_description.yaml" >diff --git a/t/db_dependent/api/v1/item_types.t b/t/db_dependent/api/v1/item_types.t >index c83c84d12b3..3196bbbb3bc 100755 >--- a/t/db_dependent/api/v1/item_types.t >+++ b/t/db_dependent/api/v1/item_types.t >@@ -23,6 +23,8 @@ use Test::Mojo; > use t::lib::TestBuilder; > use t::lib::Mocks; > >+use Mojo::JSON qw(encode_json); >+ > use Koha::ItemTypes; > use Koha::Database; > >@@ -34,7 +36,7 @@ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); > > subtest 'list() tests' => sub { > >- plan tests => 12; >+ plan tests => 13; > > $schema->storage->txn_begin; > >@@ -42,7 +44,6 @@ subtest 'list() tests' => sub { > { > class => 'Koha::ItemTypes', > value => { >- itemtype => 'TEST_IT', > parent_type => undef, > description => 'Test item type', > rentalcharge => 100.0, >@@ -70,7 +71,7 @@ subtest 'list() tests' => sub { > class => 'Koha::Localizations', > value => { > entity => 'itemtypes', >- code => 'TEST_IT', >+ code => $item_type->id, > lang => 'en', > translation => 'English word "test"', > } >@@ -81,7 +82,7 @@ subtest 'list() tests' => sub { > class => 'Koha::Localizations', > value => { > entity => 'itemtypes', >- code => 'TEST_IT', >+ code => $item_type->id, > lang => 'sv_SE', > translation => 'Swedish word "test"', > } >@@ -109,30 +110,19 @@ subtest 'list() tests' => sub { > my $unauth_userid = $patron->userid; > > ## Authorized user tests >- $t->get_ok("//$userid:$password@/api/v1/item_types")->status_is(200)->json_has('/0'); >- >- for my $json ( @{ $t->tx->res->json } ) { >- if ( $json->{item_type_id} eq 'TEST_IT' ) { >- is( $json->{description}, 'Test item type' ); >- ok( !exists $json->{translated_descriptions} ); >- } >- } >- >- $t->get_ok( "//$userid:$password@/api/v1/item_types" => { 'x-koha-embed' => 'translated_descriptions' } ) >- ->status_is(200)->json_has('/0'); >- >- for my $json ( @{ $t->tx->res->json } ) { >- if ( $json->{item_type_id} eq 'TEST_IT' ) { >- is( $json->{description}, 'Test item type' ); >- is_deeply( >- $json->{translated_descriptions}, >- [ >- { lang => 'en', translation => 'English word "test"' }, >- { lang => 'sv_SE', translation => 'Swedish word "test"' }, >- ] >- ); >- } >- } >+ my $query = encode_json( { item_type_id => $item_type->id } ); >+ $t->get_ok("//$userid:$password@/api/v1/item_types?q=$query")->status_is(200)->json_has('/0') >+ ->json_is( '/0/description', $item_type->description )->json_hasnt('/0/translated_descriptions'); >+ >+ $t->get_ok( "//$userid:$password@/api/v1/item_types?q=$query" => { 'x-koha-embed' => 'translated_descriptions' } ) >+ ->status_is(200)->json_has('/0')->json_is( '/0/description', $item_type->description ) >+ ->json_has('/0/translated_descriptions')->json_is( >+ '/0/translated_descriptions', >+ [ >+ { lang => 'en', translation => 'English word "test"' }, >+ { lang => 'sv_SE', translation => 'Swedish word "test"' }, >+ ] >+ ); > > # Unauthorized access > $t->get_ok("//$unauth_userid:$password@/api/v1/item_types")->status_is(403); >-- >2.42.0
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 34008
:
155734
|
155737
|
155738
|
155739
|
155741
|
157915
|
157976
|
157977
|
158082
|
158083
| 158084