Bugzilla – Attachment 182203 Details for
Bug 33430
Use REST API for suggestions tables
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33430: Add strings_map method
Bug-33430-Add-stringsmap-method.patch (text/plain), 5.45 KB, created by
Lisette Scheer
on 2025-05-09 17:18:21 UTC
(
hide
)
Description:
Bug 33430: Add strings_map method
Filename:
MIME Type:
Creator:
Lisette Scheer
Created:
2025-05-09 17:18:21 UTC
Size:
5.45 KB
patch
obsolete
>From 7740223d452268557c2b6435612c782d9feb9e72 Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> >Date: Thu, 8 May 2025 11:02:29 +0100 >Subject: [PATCH] Bug 33430: Add strings_map method > >This patch adds a strings_map method to allow the API to return the required authorised values needed for table displays > >Signed-off-by: Emily Lamancusa <emily.lamancusa@montgomerycountymd.gov> >Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com> >--- > Koha/Suggestion.pm | 36 +++++++++++++ > api/v1/swagger/definitions/suggestion.yaml | 4 ++ > api/v1/swagger/paths/suggestions.yaml | 10 ++++ > t/db_dependent/Koha/Suggestion.t | 59 +++++++++++++++++++++- > 4 files changed, 108 insertions(+), 1 deletion(-) > >diff --git a/Koha/Suggestion.pm b/Koha/Suggestion.pm >index 8a098189b20..f44342c687e 100644 >--- a/Koha/Suggestion.pm >+++ b/Koha/Suggestion.pm >@@ -294,6 +294,42 @@ sub to_api_mapping { > }; > } > >+=head3 strings_map >+ >+Returns a map of column name to string representations including the string. >+ >+=cut >+ >+sub strings_map { >+ my ( $self, $params ) = @_; >+ >+ my $strings = {}; >+ >+ my $required_strings = { >+ STATUS => 'SUGGEST_STATUS', >+ itemtype => 'SUGGEST_FORMAT', >+ patronreason => 'OPAC_SUG', >+ }; >+ >+ foreach my $key ( keys %$required_strings ) { >+ my $av = Koha::AuthorisedValues->search( >+ { category => $required_strings->{$key}, authorised_value => $self->$key } ); >+ my $status_str = >+ $av->count >+ ? $params->{public} >+ ? $av->next->opac_description >+ : $av->next->lib >+ : $self->$key; >+ >+ $strings->{$key} = { >+ category => $required_strings->{$key}, >+ str => $status_str, >+ type => 'av', >+ }; >+ } >+ return $strings; >+} >+ > =head1 AUTHOR > > Kyle M Hall <kyle@bywatersolutions.com> >diff --git a/api/v1/swagger/definitions/suggestion.yaml b/api/v1/swagger/definitions/suggestion.yaml >index daa136ff23b..2a9bdfbfd5e 100644 >--- a/api/v1/swagger/definitions/suggestion.yaml >+++ b/api/v1/swagger/definitions/suggestion.yaml >@@ -191,4 +191,8 @@ properties: > - boolean > - "null" > description: archived (processed) suggestion >+ _strings: >+ type: >+ - object >+ - "null" > additionalProperties: false >diff --git a/api/v1/swagger/paths/suggestions.yaml b/api/v1/swagger/paths/suggestions.yaml >index a76c382f226..a4d3515ea51 100644 >--- a/api/v1/swagger/paths/suggestions.yaml >+++ b/api/v1/swagger/paths/suggestions.yaml >@@ -15,6 +15,16 @@ > - $ref: "../swagger.yaml#/parameters/q_param" > - $ref: "../swagger.yaml#/parameters/q_body" > - $ref: "../swagger.yaml#/parameters/request_id_header" >+ - name: x-koha-embed >+ in: header >+ required: false >+ description: Embed list sent as a request header >+ type: array >+ items: >+ type: string >+ enum: >+ - +strings >+ collectionFormat: csv > produces: > - application/json > responses: >diff --git a/t/db_dependent/Koha/Suggestion.t b/t/db_dependent/Koha/Suggestion.t >index cf959d868ea..4f2f0a465a6 100755 >--- a/t/db_dependent/Koha/Suggestion.t >+++ b/t/db_dependent/Koha/Suggestion.t >@@ -20,7 +20,7 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 2; >+use Test::More tests => 3; > > use Koha::Database; > use Koha::Suggestions; >@@ -49,3 +49,60 @@ subtest 'suggester() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'strings_map() tests' => sub { >+ plan tests => 2; >+ >+ $schema->txn_begin; >+ >+ my $av_value1 = Koha::AuthorisedValue->new( >+ { >+ category => "SUGGEST_FORMAT", >+ authorised_value => 'RECORD', >+ lib => "Test format" >+ } >+ )->store; >+ my $av_value2 = Koha::AuthorisedValue->new( >+ { >+ category => "SUGGEST_STATUS", >+ authorised_value => 'WANTED', >+ lib => "Test status" >+ } >+ )->store; >+ my $suggestion = $builder->build_object( >+ { class => 'Koha::Suggestions', value => { suggestedby => undef, STATUS => 'WANTED', itemtype => 'RECORD' } } ); >+ >+ my $strings_map = $suggestion->strings_map( { public => 0 } ); >+ is_deeply( >+ $strings_map, >+ { >+ STATUS => { str => 'Test status', type => 'av', category => 'SUGGEST_STATUS' }, >+ itemtype => { str => 'Test format', type => 'av', category => 'SUGGEST_FORMAT' }, >+ patronreason => { str => $suggestion->patronreason, type => 'av', category => 'OPAC_SUG' }, >+ }, >+ 'Strings map is correct' >+ ); >+ >+ my $av_value3 = Koha::AuthorisedValue->new( >+ { >+ category => "OPAC_SUG", >+ authorised_value => 'OPAC', >+ lib => "An OPAC reason" >+ } >+ )->store; >+ >+ $suggestion->patronreason('OPAC'); >+ $strings_map = $suggestion->strings_map( { public => 0 } ); >+ is_deeply( >+ $strings_map, >+ { >+ STATUS => { str => 'Test status', type => 'av', category => 'SUGGEST_STATUS' }, >+ itemtype => { str => 'Test format', type => 'av', category => 'SUGGEST_FORMAT' }, >+ patronreason => { str => 'An OPAC reason', type => 'av', category => 'OPAC_SUG' }, >+ }, >+ 'Strings map is correct' >+ ); >+ >+ $schema->txn_rollback; >+ >+}; >-- >2.39.5
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 33430
:
182146
|
182147
|
182148
|
182149
|
182150
|
182161
|
182196
|
182197
|
182198
|
182199
|
182200
|
182202
|
182203
|
182204
|
182205
|
182206
|
182207
|
182208
|
182209
|
182210
|
182211
|
182339
|
182340
|
182341
|
182342
|
182343
|
182428
|
182429
|
182430
|
182431
|
182432
|
182433
|
182434
|
182478
|
182480
|
182481
|
182482
|
182483
|
182484
|
182485
|
182486
|
182487
|
182493
|
182494
|
182495
|
182496
|
182497
|
182498
|
182499
|
182500
|
182577
|
182578