Bugzilla – Attachment 147998 Details for
Bug 33161
Implement +strings for GET /items and GET /items/:item_id
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33161: (follow-up) Consistent use of db fields throughout
Bug-33161-follow-up-Consistent-use-of-db-fields-th.patch (text/plain), 4.90 KB, created by
Martin Renvoize
on 2023-03-09 13:09:16 UTC
(
hide
)
Description:
Bug 33161: (follow-up) Consistent use of db fields throughout
Filename:
MIME Type:
Creator:
Martin Renvoize
Created:
2023-03-09 13:09:16 UTC
Size:
4.90 KB
patch
obsolete
>From 72a404d8a4f609dc9cc0c803cc7b4dbda0966f0c Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 9 Mar 2023 12:43:05 +0000 >Subject: [PATCH] Bug 33161: (follow-up) Consistent use of db fields throughout > >We should stick to DB field names as long as possible to allow re-use >and only convert to api field names via to_api_mapping at the last >moment inside the parent to_api function. >--- > Koha/Item.pm | 17 +---------------- > Koha/Object.pm | 44 +++++++++++++++++++++++++++++++++++--------- > 2 files changed, 36 insertions(+), 25 deletions(-) > >diff --git a/Koha/Item.pm b/Koha/Item.pm >index 3139babed1..d31130203e 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -2089,17 +2089,6 @@ sub api_strings_mapping { > > foreach my $col ( keys %{$columns_info} ) { > >- # Skip columns not in public read list >- next >- unless !$params->{public} >- || any { $col eq $_ } $public_read_list; >- >- # Skip columns that are not exposed on the API by to_api_mapping >- # i.e. mapping exists but points to undef >- next >- if $col eq 'more_subfields_xml' # not dealt with as a regular field >- || ( exists $to_api_mapping->{$col} && !defined $to_api_mapping->{$col} ); >- > # By now, we are done with known columns, now check the framework for mappings > my $field = $self->_result->result_source->name . '.' . $col; > >@@ -2113,11 +2102,7 @@ sub api_strings_mapping { > > my $str = C4::Biblio::GetAuthorisedValueDesc( $itemtagfield, $subfield->{tagsubfield}, $self->$col, '', $tagslib, undef, $params->{public} ); > my $type = exists $code_to_type->{$code} ? $code_to_type->{$code} : 'av'; >- >- # The _strings entry should match the API attribute name >- my $mapped_attr = exists $to_api_mapping->{$col} ? $to_api_mapping->{$col} : $col; >- >- $strings->{$mapped_attr} = { >+ $strings->{$col} = { > str => $str, > type => $type, > ( $type eq 'av' ? ( category => $code ) : () ), >diff --git a/Koha/Object.pm b/Koha/Object.pm >index b4b5717c34..1bb1448556 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -570,13 +570,14 @@ sub to_api { > # Remove forbidden attributes if required (including their coded values) > if ( $params->{public} ) { > for my $field ( keys %{$json_object} ) { >- delete $json_object->{$field} unless any { $_ eq $field } @{ $self->public_read_list }; >+ delete $json_object->{$field} >+ unless any { $_ eq $field } @{ $self->public_read_list }; > } > >- if ( $strings ) { >- foreach my $field (keys %{$avs}) { >+ if ($strings) { >+ foreach my $field ( keys %{$avs} ) { > delete $avs->{$field} >- unless any { $_ eq $field } @{ $self->public_read_list }; >+ unless any { $_ eq $field } @{ $self->public_read_list }; > } > } > } >@@ -588,15 +589,18 @@ sub to_api { > foreach my $column ( keys %{ $self->to_api_mapping } ) { > my $mapped_column = $self->to_api_mapping->{$column}; > if ( exists $json_object->{$column} >- && defined $mapped_column ) { >+ && defined $mapped_column ) >+ { > > # key != undef > $json_object->{$mapped_column} = delete $json_object->{$column}; > $avs->{$mapped_column} = delete $avs->{$column} > if exists $avs->{$column}; > >- } elsif ( exists $json_object->{$column} >- && !defined $mapped_column ) { >+ } >+ elsif ( exists $json_object->{$column} >+ && !defined $mapped_column ) >+ { > > # key == undef > delete $json_object->{$column}; >@@ -610,8 +614,9 @@ sub to_api { > > if ($embeds) { > foreach my $embed ( keys %{$embeds} ) { >- if ( $embed =~ m/^(?<relation>.*)_count$/ >- and $embeds->{$embed}->{is_count} ) { >+ if ( $embed =~ m/^(?<relation>.*)_count$/ >+ and $embeds->{$embed}->{is_count} ) >+ { > > my $relation = $+{relation}; > $json_object->{$embed} = $self->$relation->count; >@@ -671,6 +676,27 @@ sub to_api_mapping { > return {}; > } > >+=head3 api_strings_mapping >+ >+ my $params = { is_public => 1 }; >+ my $string_map = $object->api_strings_mapping($params); >+ >+Generic method that returns the string map for coded attributes. >+ >+Return should be a hashref keyed on database field name with the values >+being hashrefs containing 'str', 'type' and optionally 'category'. >+ >+This is then use in to_api to render the _strings embed when requested. >+ >+Note: this only returns an empty I<hashref>. Each class should have its >+own mapping returned. >+ >+=cut >+ >+sub api_strings_mapping { >+ return {}; >+} >+ > =head3 public_read_list > > >-- >2.39.2
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 33161
:
147888
|
147973
|
147977
|
147995
|
147998
|
147999
|
148010
|
148011
|
148012
|
148013
|
148014
|
148039
|
148040
|
148041
|
148042
|
148043
|
148059
|
148060
|
148061
|
148062
|
148063
|
148068
|
148075