View | Details | Raw Unified | Return to bug 17314
Collapse All | Expand All

(-)a/Koha/REST/V1/Suggestions.pm (-1 / +134 lines)
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_created',
381
   volumedesc => 'volume_desc',
382
   publicationyear => 'publication_year',
383
   place => 'publication_place',
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_created => 'date',
418
   volume_desc => 'volumedesc',
419
   publication_year => 'publicationyear',
420
   publication_place => '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;
(-)a/api/v1/swagger/definitions/suggestion.json (-24 / +23 lines)
Lines 1-43 Link Here
1
{
1
{
2
  "type": "object",
2
  "type": "object",
3
  "properties": {
3
  "properties": {
4
    "suggestionid": {
4
    "suggestion_id": {
5
      "type": "string",
5
      "type": "string",
6
      "description": "unique identifier assigned automatically by Koha"
6
      "description": "unique identifier assigned automatically by Koha"
7
    },
7
    },
8
    "suggestedby": {
8
    "suggested_by": {
9
      "type": ["string", "null"],
9
      "type": ["string", "null"],
10
      "description": "patron_id for the person making the suggestion, foreign key linking to the borrowers table"
10
      "description": "patron_id for the person making the suggestion, foreign key linking to the borrowers table"
11
    },
11
    },
12
    "suggesteddate": {
12
    "suggested_date": {
13
      "type": ["string", "null"],
13
      "type": ["string", "null"],
14
      "description": "the suggestion was submitted"
14
      "description": "the suggestion was submitted"
15
    },
15
    },
16
    "managedby": {
16
    "managed_by": {
17
      "type": ["string", "null"],
17
      "type": ["string", "null"],
18
      "description": "patron_id for the librarian managing the suggestion, foreign key linking to the borrowers table"
18
      "description": "patron_id for the librarian managing the suggestion, foreign key linking to the borrowers table"
19
    },
19
    },
20
    "manageddate": {
20
    "managed_date": {
21
      "type": ["string", "null"],
21
      "type": ["string", "null"],
22
      "description": "date the suggestion was updated"
22
      "description": "date the suggestion was updated"
23
    },
23
    },
24
    "acceptedby": {
24
    "accepted_by": {
25
      "type": ["string", "null"],
25
      "type": ["string", "null"],
26
      "description": "patron_id for the librarian who accepted the suggestion, foreign key linking to the borrowers table"
26
      "description": "patron_id for the librarian who accepted the suggestion, foreign key linking to the borrowers table"
27
    },
27
    },
28
    "accepteddate": {
28
    "accepted_date": {
29
      "type": ["string", "null"],
29
      "type": ["string", "null"],
30
      "description": "date the suggestion was marked as accepted"
30
      "description": "date the suggestion was marked as accepted"
31
    },
31
    },
32
    "rejectedby": {
32
    "rejected_by": {
33
      "type": ["string", "null"],
33
      "type": ["string", "null"],
34
      "description": "patron_id for the librarian who rejected the suggestion, foreign key linking to the borrowers table"
34
      "description": "patron_id for the librarian who rejected the suggestion, foreign key linking to the borrowers table"
35
    },
35
    },
36
    "rejecteddate": {
36
    "rejected_date": {
37
      "type": ["string", "null"],
37
      "type": ["string", "null"],
38
      "description": "date the suggestion was marked as rejected"
38
      "description": "date the suggestion was marked as rejected"
39
    },
39
    },
40
    "STATUS": {
40
    "status": {
41
      "type": "string",
41
      "type": "string",
42
      "description": "suggestion status (ASKED, CHECKED, ACCEPTED, or REJECTED)"
42
      "description": "suggestion status (ASKED, CHECKED, ACCEPTED, or REJECTED)"
43
    },
43
    },
Lines 53-79 Link Here
53
      "type": ["string", "null"],
53
      "type": ["string", "null"],
54
      "description": "title of the suggested item"
54
      "description": "title of the suggested item"
55
    },
55
    },
56
    "copyrightdate": {
56
    "copyright_date": {
57
      "type": ["string", "null"],
57
      "type": ["string", "null"],
58
      "description": "copyright date of the suggested item"
58
      "description": "copyright date of the suggested item"
59
    },
59
    },
60
    "publishercode": {
60
    "publisher_code": {
61
      "type": ["string", "null"],
61
      "type": ["string", "null"],
62
      "description": "publisher of the suggested item"
62
      "description": "publisher of the suggested item"
63
    },
63
    },
64
    "date": {
64
    "date_created": {
65
      "type": ["string", "null"],
65
      "type": ["string", "null"],
66
      "description": "date created"
66
      "description": "date created"
67
    },
67
    },
68
    "volumedesc": {
68
    "volume_desc": {
69
      "type": ["string", "null"],
69
      "type": ["string", "null"],
70
      "description": "volume description"
70
      "description": "volume description"
71
    },
71
    },
72
    "publicationyear": {
72
    "publication_year": {
73
      "type": ["string", "null"],
73
      "type": ["string", "null"],
74
      "description": "year of publication"
74
      "description": "year of publication"
75
    },
75
    },
76
    "place": {
76
    "publication_place": {
77
      "type": ["string", "null"],
77
      "type": ["string", "null"],
78
      "description": "publication place of the suggested item"
78
      "description": "publication place of the suggested item"
79
    },
79
    },
Lines 81-87 Link Here
81
      "type": ["string", "null"],
81
      "type": ["string", "null"],
82
      "description": "isbn of the suggested item"
82
      "description": "isbn of the suggested item"
83
    },
83
    },
84
    "biblionumber": {
84
    "biblio_id": {
85
      "type": ["string", "null"],
85
      "type": ["string", "null"],
86
      "description": "foreign key linking the suggestion to the biblio table after the suggestion has been ordered"
86
      "description": "foreign key linking the suggestion to the biblio table after the suggestion has been ordered"
87
    },
87
    },
Lines 89-111 Link Here
89
      "type": ["string", "null"],
89
      "type": ["string", "null"],
90
      "description": "reason for accepting or rejecting the suggestion"
90
      "description": "reason for accepting or rejecting the suggestion"
91
    },
91
    },
92
    "patronreason": {
92
    "patron_reason": {
93
      "type": ["string", "null"],
93
      "type": ["string", "null"],
94
      "description": "reason for making the suggestion"
94
      "description": "reason for making the suggestion"
95
    },
95
    },
96
    "budgetid": {
96
    "budget_id": {
97
      "type": ["string", "null"],
97
      "type": ["string", "null"],
98
      "description": "foreign key linking the suggested budget to the aqbudgets table"
98
      "description": "foreign key linking the suggested budget to the aqbudgets table"
99
    },
99
    },
100
    "branchcode": {
100
    "library_id": {
101
      "type": ["string", "null"],
101
      "type": ["string", "null"],
102
      "description": "foreign key linking the suggested branch to the branches table"
102
      "description": "foreign key linking the suggested branch to the branches table"
103
    },
103
    },
104
    "collectiontitle": {
104
    "collection_title": {
105
      "type": ["string", "null"],
105
      "type": ["string", "null"],
106
      "description": "collection name for the suggested item"
106
      "description": "collection name for the suggested item"
107
    },
107
    },
108
    "itemtype": {
108
    "item_type": {
109
      "type": ["string", "null"],
109
      "type": ["string", "null"],
110
      "description": "suggested item type"
110
      "description": "suggested item type"
111
    },
111
    },
Lines 117-123 Link Here
117
      "type": ["string", "null"],
117
      "type": ["string", "null"],
118
      "description": "suggested currency for the suggested price"
118
      "description": "suggested currency for the suggested price"
119
    },
119
    },
120
    "price": {
120
    "item_price": {
121
      "type": ["string", "null"],
121
      "type": ["string", "null"],
122
      "description": "suggested price"
122
      "description": "suggested price"
123
    },
123
    },
124
- 

Return to bug 17314