Lines 58-64
sub list {
Link Here
|
58 |
} |
58 |
} |
59 |
|
59 |
|
60 |
return try { |
60 |
return try { |
61 |
$suggestions = Koha::Suggestions->search($filter)->unblessed; |
61 |
$suggestions = Koha::Suggestions->search($filter, \&_to_model, \&_to_api); |
62 |
return $c->render( status => 200, openapi => $suggestions ); |
62 |
return $c->render( status => 200, openapi => $suggestions ); |
63 |
} |
63 |
} |
64 |
catch { |
64 |
catch { |
Lines 297-301
sub _validate_body {
Link Here
|
297 |
# Everything's fine .. |
297 |
# Everything's fine .. |
298 |
return 0; |
298 |
return 0; |
299 |
} |
299 |
} |
|
|
300 |
=head3 _to_api |
300 |
|
301 |
|
|
|
302 |
Helper function that maps unblessed Koha::Suggestion objects into REST api |
303 |
attribute names. |
304 |
|
305 |
=cut |
306 |
|
307 |
sub _to_api { |
308 |
my $suggestion = shift; |
309 |
|
310 |
# Rename attributes |
311 |
foreach my $column ( keys %{ $Koha::REST::V1::Suggestions::to_api_mapping } ) { |
312 |
my $mapped_column = $Koha::REST::V1::Suggestions::to_api_mapping->{$column}; |
313 |
if ( exists $suggestion->{ $column } |
314 |
&& defined $mapped_column ) |
315 |
{ |
316 |
# key != undef |
317 |
$suggestion->{ $mapped_column } = delete $suggestion->{ $column }; |
318 |
} |
319 |
elsif ( exists $suggestion->{ $column } |
320 |
&& !defined $mapped_column ) |
321 |
{ |
322 |
# key == undef |
323 |
delete $suggestion->{ $column }; |
324 |
} |
325 |
} |
326 |
|
327 |
return $suggestion; |
328 |
} |
329 |
|
330 |
=head3 _to_model |
331 |
|
332 |
Helper function that maps REST api objects into Koha::Suggestion |
333 |
attribute names. |
334 |
|
335 |
=cut |
336 |
|
337 |
sub _to_model { |
338 |
my $suggestion = shift; |
339 |
|
340 |
foreach my $attribute ( keys %{ $Koha::REST::V1::Suggestions::to_model_mapping } ) { |
341 |
my $mapped_attribute = $Koha::REST::V1::Suggestions::to_model_mapping->{$attribute}; |
342 |
if ( exists $suggestion->{ $attribute } |
343 |
&& defined $mapped_attribute ) |
344 |
{ |
345 |
# key => !undef |
346 |
$suggestion->{ $mapped_attribute } = delete $suggestion->{ $attribute }; |
347 |
} |
348 |
elsif ( exists $suggestion->{ $attribute } |
349 |
&& !defined $mapped_attribute ) |
350 |
{ |
351 |
# key => undef / to be deleted |
352 |
delete $suggestion->{ $attribute }; |
353 |
} |
354 |
} |
355 |
|
356 |
return $suggestion; |
357 |
} |
358 |
|
359 |
=head2 Global variables |
360 |
|
361 |
=head3 $to_api_mapping |
362 |
|
363 |
=cut |
364 |
|
365 |
our $to_api_mapping = { |
366 |
suggestionid => 'suggestion_id', |
367 |
suggestedby => 'suggested_by', |
368 |
suggesteddate => 'suggestion_date', |
369 |
managedby => 'managed_by', |
370 |
manageddate => 'managed_date', |
371 |
accepteddate => 'accepted_date', |
372 |
rejectedby => 'rejected_by', |
373 |
rejectiondate => 'rejected_date', |
374 |
STATUS => 'status', |
375 |
note => 'note', |
376 |
author => 'author', |
377 |
title => 'title', |
378 |
copyrightdate => 'copyright_date', |
379 |
publishercode => 'publisher_code', |
380 |
date => 'date', |
381 |
volumedesc => 'volume_desc', |
382 |
publicationyear => 'publication_year', |
383 |
place => 'location', |
384 |
isbn => 'isbn', |
385 |
biblionumber => 'biblio_id', |
386 |
reason => 'reason', |
387 |
patronreason => 'patron_reason', |
388 |
budgetid => 'budget_id', |
389 |
branchcode => 'library_id', |
390 |
collectiontitle => 'collection_title', |
391 |
itemtype => 'item_type', |
392 |
quantity => 'quantity', |
393 |
currency => 'currency', |
394 |
price => 'item_price', |
395 |
total => 'total_price' |
396 |
}; |
397 |
|
398 |
=head3 $to_model_mapping |
399 |
|
400 |
=cut |
401 |
|
402 |
our $to_model_mapping = { |
403 |
suggestion_id => 'suggestionid', |
404 |
suggested_by => 'suggestedby', |
405 |
suggestion_date => 'suggesteddate', |
406 |
managed_by => 'managedby', |
407 |
managed_date => 'manageddate', |
408 |
accepted_date => 'accepteddate', |
409 |
rejected_by => 'rejectedby', |
410 |
rejected_date => 'rejectiondate', |
411 |
status => 'STATUS', |
412 |
note => 'note', |
413 |
author => 'author', |
414 |
title => 'title', |
415 |
copyright_date => 'copyrightdate', |
416 |
publisher_code => 'publishercode', |
417 |
date => 'date', |
418 |
volume_desc => 'volumedesc', |
419 |
publication_year => 'publicationyear', |
420 |
location => 'place', |
421 |
isbn => 'isbn', |
422 |
biblio_id => 'biblionumber', |
423 |
reason => 'reason', |
424 |
patron_reason => 'patronreason', |
425 |
budget_id => 'budgetid', |
426 |
library_id => 'branchcode', |
427 |
collection_title => 'collectiontitle', |
428 |
item_type => 'itemtype', |
429 |
quantity => 'quantity', |
430 |
currency => 'currency', |
431 |
item_price => 'price', |
432 |
total_price => 'total' |
433 |
}; |
301 |
1; |
434 |
1; |
302 |
- |
|
|