Bugzilla – Attachment 91546 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 and changed attirbutes naming
Bug-17314--Added-tomodel-and-toapi-methods-and-cha.patch (text/plain), 8.99 KB, created by
Arthur Suzuki
on 2019-07-16 10:37:33 UTC
(
hide
)
Description:
Bug 17314 : Added _to_model and _to_api methods and changed attirbutes naming
Filename:
MIME Type:
Creator:
Arthur Suzuki
Created:
2019-07-16 10:37:33 UTC
Size:
8.99 KB
patch
obsolete
>From ad38b2f149e8caf263840ca04d2b0cee7e518f77 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 and changed > attirbutes naming > >--- > Koha/REST/V1/Suggestions.pm | 135 ++++++++++++++++++++++++++++- > api/v1/swagger/definitions/suggestion.json | 46 +++++----- > 2 files changed, 157 insertions(+), 24 deletions(-) > >diff --git a/Koha/REST/V1/Suggestions.pm b/Koha/REST/V1/Suggestions.pm >index 7b5aed4780..dfbf85027a 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_created', >+ volumedesc => 'volume_desc', >+ publicationyear => 'publication_year', >+ place => 'publication_place', >+ 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_created => 'date', >+ volume_desc => 'volumedesc', >+ publication_year => 'publicationyear', >+ publication_place => '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; >diff --git a/api/v1/swagger/definitions/suggestion.json b/api/v1/swagger/definitions/suggestion.json >index 2e4af794a8..57dcaac1cc 100644 >--- a/api/v1/swagger/definitions/suggestion.json >+++ b/api/v1/swagger/definitions/suggestion.json >@@ -1,43 +1,43 @@ > { > "type": "object", > "properties": { >- "suggestionid": { >+ "suggestion_id": { > "type": "string", > "description": "unique identifier assigned automatically by Koha" > }, >- "suggestedby": { >+ "suggested_by": { > "type": ["string", "null"], > "description": "patron_id for the person making the suggestion, foreign key linking to the borrowers table" > }, >- "suggesteddate": { >+ "suggested_date": { > "type": ["string", "null"], > "description": "the suggestion was submitted" > }, >- "managedby": { >+ "managed_by": { > "type": ["string", "null"], > "description": "patron_id for the librarian managing the suggestion, foreign key linking to the borrowers table" > }, >- "manageddate": { >+ "managed_date": { > "type": ["string", "null"], > "description": "date the suggestion was updated" > }, >- "acceptedby": { >+ "accepted_by": { > "type": ["string", "null"], > "description": "patron_id for the librarian who accepted the suggestion, foreign key linking to the borrowers table" > }, >- "accepteddate": { >+ "accepted_date": { > "type": ["string", "null"], > "description": "date the suggestion was marked as accepted" > }, >- "rejectedby": { >+ "rejected_by": { > "type": ["string", "null"], > "description": "patron_id for the librarian who rejected the suggestion, foreign key linking to the borrowers table" > }, >- "rejecteddate": { >+ "rejected_date": { > "type": ["string", "null"], > "description": "date the suggestion was marked as rejected" > }, >- "STATUS": { >+ "status": { > "type": "string", > "description": "suggestion status (ASKED, CHECKED, ACCEPTED, or REJECTED)" > }, >@@ -53,27 +53,27 @@ > "type": ["string", "null"], > "description": "title of the suggested item" > }, >- "copyrightdate": { >+ "copyright_date": { > "type": ["string", "null"], > "description": "copyright date of the suggested item" > }, >- "publishercode": { >+ "publisher_code": { > "type": ["string", "null"], > "description": "publisher of the suggested item" > }, >- "date": { >+ "date_created": { > "type": ["string", "null"], > "description": "date created" > }, >- "volumedesc": { >+ "volume_desc": { > "type": ["string", "null"], > "description": "volume description" > }, >- "publicationyear": { >+ "publication_year": { > "type": ["string", "null"], > "description": "year of publication" > }, >- "place": { >+ "publication_place": { > "type": ["string", "null"], > "description": "publication place of the suggested item" > }, >@@ -81,7 +81,7 @@ > "type": ["string", "null"], > "description": "isbn of the suggested item" > }, >- "biblionumber": { >+ "biblio_id": { > "type": ["string", "null"], > "description": "foreign key linking the suggestion to the biblio table after the suggestion has been ordered" > }, >@@ -89,23 +89,23 @@ > "type": ["string", "null"], > "description": "reason for accepting or rejecting the suggestion" > }, >- "patronreason": { >+ "patron_reason": { > "type": ["string", "null"], > "description": "reason for making the suggestion" > }, >- "budgetid": { >+ "budget_id": { > "type": ["string", "null"], > "description": "foreign key linking the suggested budget to the aqbudgets table" > }, >- "branchcode": { >+ "library_id": { > "type": ["string", "null"], > "description": "foreign key linking the suggested branch to the branches table" > }, >- "collectiontitle": { >+ "collection_title": { > "type": ["string", "null"], > "description": "collection name for the suggested item" > }, >- "itemtype": { >+ "item_type": { > "type": ["string", "null"], > "description": "suggested item type" > }, >@@ -117,7 +117,7 @@ > "type": ["string", "null"], > "description": "suggested currency for the suggested price" > }, >- "price": { >+ "item_price": { > "type": ["string", "null"], > "description": "suggested price" > }, >-- >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