Bugzilla – Attachment 91545 Details for
Bug 17314
Routes to create, list and delete a purchase suggestion
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17314 : Added _to_model and _to_api methods
Bug-17314--Added-tomodel-and-toapi-methods.patch (text/plain), 4.51 KB, created by
Arthur Suzuki
on 2019-07-16 10:26:05 UTC
(
hide
)
Description:
Bug 17314 : Added _to_model and _to_api methods
Filename:
MIME Type:
Creator:
Arthur Suzuki
Created:
2019-07-16 10:26:05 UTC
Size:
4.51 KB
patch
obsolete
>From 57c4e31fe042bd1f0196e975c65438e18f92d7b4 Mon Sep 17 00:00:00 2001 >From: Arthur Suzuki <arthur.suzuki@biblibre.com> >Date: Fri, 12 Jul 2019 18:05:45 +0200 >Subject: [PATCH] Bug 17314 : Added _to_model and _to_api methods > >--- > Koha/REST/V1/Suggestions.pm | 135 +++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 134 insertions(+), 1 deletion(-) > >diff --git a/Koha/REST/V1/Suggestions.pm b/Koha/REST/V1/Suggestions.pm >index 7b5aed4780..f23e591c2c 100644 >--- a/Koha/REST/V1/Suggestions.pm >+++ b/Koha/REST/V1/Suggestions.pm >@@ -58,7 +58,7 @@ sub list { > } > > return try { >- $suggestions = Koha::Suggestions->search($filter)->unblessed; >+ $suggestions = Koha::Suggestions->search($filter, \&_to_model, \&_to_api); > return $c->render( status => 200, openapi => $suggestions ); > } > catch { >@@ -297,5 +297,138 @@ sub _validate_body { > # Everything's fine .. > return 0; > } >+=head3 _to_api > >+Helper function that maps unblessed Koha::Suggestion objects into REST api >+attribute names. >+ >+=cut >+ >+sub _to_api { >+ my $suggestion = shift; >+ >+ # Rename attributes >+ foreach my $column ( keys %{ $Koha::REST::V1::Suggestions::to_api_mapping } ) { >+ my $mapped_column = $Koha::REST::V1::Suggestions::to_api_mapping->{$column}; >+ if ( exists $suggestion->{ $column } >+ && defined $mapped_column ) >+ { >+ # key != undef >+ $suggestion->{ $mapped_column } = delete $suggestion->{ $column }; >+ } >+ elsif ( exists $suggestion->{ $column } >+ && !defined $mapped_column ) >+ { >+ # key == undef >+ delete $suggestion->{ $column }; >+ } >+ } >+ >+ return $suggestion; >+} >+ >+=head3 _to_model >+ >+Helper function that maps REST api objects into Koha::Suggestion >+attribute names. >+ >+=cut >+ >+sub _to_model { >+ my $suggestion = shift; >+ >+ foreach my $attribute ( keys %{ $Koha::REST::V1::Suggestions::to_model_mapping } ) { >+ my $mapped_attribute = $Koha::REST::V1::Suggestions::to_model_mapping->{$attribute}; >+ if ( exists $suggestion->{ $attribute } >+ && defined $mapped_attribute ) >+ { >+ # key => !undef >+ $suggestion->{ $mapped_attribute } = delete $suggestion->{ $attribute }; >+ } >+ elsif ( exists $suggestion->{ $attribute } >+ && !defined $mapped_attribute ) >+ { >+ # key => undef / to be deleted >+ delete $suggestion->{ $attribute }; >+ } >+ } >+ >+ return $suggestion; >+} >+ >+=head2 Global variables >+ >+=head3 $to_api_mapping >+ >+=cut >+ >+our $to_api_mapping = { >+ suggestionid => 'suggestion_id', >+ suggestedby => 'suggested_by', >+ suggesteddate => 'suggestion_date', >+ managedby => 'managed_by', >+ manageddate => 'managed_date', >+ accepteddate => 'accepted_date', >+ rejectedby => 'rejected_by', >+ rejectiondate => 'rejected_date', >+ STATUS => 'status', >+ note => 'note', >+ author => 'author', >+ title => 'title', >+ copyrightdate => 'copyright_date', >+ publishercode => 'publisher_code', >+ date => 'date', >+ volumedesc => 'volume_desc', >+ publicationyear => 'publication_year', >+ place => 'location', >+ isbn => 'isbn', >+ biblionumber => 'biblio_id', >+ reason => 'reason', >+ patronreason => 'patron_reason', >+ budgetid => 'budget_id', >+ branchcode => 'library_id', >+ collectiontitle => 'collection_title', >+ itemtype => 'item_type', >+ quantity => 'quantity', >+ currency => 'currency', >+ price => 'item_price', >+ total => 'total_price' >+}; >+ >+=head3 $to_model_mapping >+ >+=cut >+ >+our $to_model_mapping = { >+ suggestion_id => 'suggestionid', >+ suggested_by => 'suggestedby', >+ suggestion_date => 'suggesteddate', >+ managed_by => 'managedby', >+ managed_date => 'manageddate', >+ accepted_date => 'accepteddate', >+ rejected_by => 'rejectedby', >+ rejected_date => 'rejectiondate', >+ status => 'STATUS', >+ note => 'note', >+ author => 'author', >+ title => 'title', >+ copyright_date => 'copyrightdate', >+ publisher_code => 'publishercode', >+ date => 'date', >+ volume_desc => 'volumedesc', >+ publication_year => 'publicationyear', >+ location => 'place', >+ isbn => 'isbn', >+ biblio_id => 'biblionumber', >+ reason => 'reason', >+ patron_reason => 'patronreason', >+ budget_id => 'budgetid', >+ library_id => 'branchcode', >+ collection_title => 'collectiontitle', >+ item_type => 'itemtype', >+ quantity => 'quantity', >+ currency => 'currency', >+ item_price => 'price', >+ total_price => 'total' >+}; > 1; >-- >2.11.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 17314
:
58098
|
58100
|
58101
|
58993
|
60133
|
90171
|
90172
|
90176
|
91545
|
91546
|
93761
|
93762
|
93763
|
93764
|
93765
|
108380
|
109972
|
109973
|
109974
|
109975
|
109976
|
109977
|
114113
|
114114
|
114115
|
114116
|
114117
|
114118
|
120111
|
120133
|
120134
|
120135
|
120136
|
125097
|
125098
|
125099
|
125100
|
125101
|
125102
|
125103
|
125104
|
127533
|
127534
|
127535
|
127536