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

(-)a/Koha/REST/V1/Suggestions.pm (-1 / +134 lines)
Lines 44-50 sub list { Link Here
44
    }
44
    }
45
45
46
    return try {
46
    return try {
47
        $suggestions = Koha::Suggestions->search($filter)->unblessed;
47
        $suggestions = Koha::Suggestions->search($filter, \&_to_model, \&_to_api);
48
        return $c->render( status => 200, openapi => $suggestions );
48
        return $c->render( status => 200, openapi => $suggestions );
49
    }
49
    }
50
    catch {
50
    catch {
Lines 253-257 sub _validate_body { Link Here
253
    # Everything's fine ..
253
    # Everything's fine ..
254
    return 0;
254
    return 0;
255
}
255
}
256
=head3 _to_api
256
257
258
Helper function that maps unblessed Koha::Suggestion objects into REST api
259
attribute names.
260
261
=cut
262
263
sub _to_api {
264
    my $suggestion = shift;
265
266
    # Rename attributes
267
    foreach my $column ( keys %{ $Koha::REST::V1::Suggestions::to_api_mapping } ) {
268
        my $mapped_column = $Koha::REST::V1::Suggestions::to_api_mapping->{$column};
269
        if (    exists $suggestion->{ $column }
270
             && defined $mapped_column )
271
        {
272
            # key != undef
273
            $suggestion->{ $mapped_column } = delete $suggestion->{ $column };
274
        }
275
        elsif (    exists $suggestion->{ $column }
276
                && !defined $mapped_column )
277
        {
278
            # key == undef
279
            delete $suggestion->{ $column };
280
        }
281
    }
282
283
    return $suggestion;
284
}
285
286
=head3 _to_model
287
288
Helper function that maps REST api objects into Koha::Suggestion
289
attribute names.
290
291
=cut
292
293
sub _to_model {
294
    my $suggestion = shift;
295
296
    foreach my $attribute ( keys %{ $Koha::REST::V1::Suggestions::to_model_mapping } ) {
297
        my $mapped_attribute = $Koha::REST::V1::Suggestions::to_model_mapping->{$attribute};
298
        if (    exists $suggestion->{ $attribute }
299
             && defined $mapped_attribute )
300
        {
301
            # key => !undef
302
            $suggestion->{ $mapped_attribute } = delete $suggestion->{ $attribute };
303
        }
304
        elsif (    exists $suggestion->{ $attribute }
305
                && !defined $mapped_attribute )
306
        {
307
            # key => undef / to be deleted
308
            delete $suggestion->{ $attribute };
309
        }
310
    }
311
312
    return $suggestion;
313
}
314
315
=head2 Global variables
316
317
=head3 $to_api_mapping
318
319
=cut
320
321
our $to_api_mapping = {
322
   suggestionid => 'suggestion_id',
323
   suggestedby => 'suggested_by',
324
   suggesteddate => 'suggestion_date',
325
   managedby => 'managed_by',
326
   manageddate => 'managed_date',
327
   accepteddate => 'accepted_date',
328
   rejectedby => 'rejected_by',
329
   rejectiondate => 'rejected_date',
330
   STATUS => 'status',
331
   note => 'note',
332
   author => 'author',
333
   title => 'title',
334
   copyrightdate => 'copyright_date',
335
   publishercode => 'publisher_code',
336
   date => 'date_created',
337
   volumedesc => 'volume_desc',
338
   publicationyear => 'publication_year',
339
   place => 'publication_place',
340
   isbn => 'isbn',
341
   biblionumber => 'biblio_id',
342
   reason => 'reason',
343
   patronreason => 'patron_reason',
344
   budgetid => 'budget_id',
345
   branchcode => 'library_id',
346
   collectiontitle => 'collection_title',
347
   itemtype => 'item_type',
348
   quantity => 'quantity',
349
   currency => 'currency',
350
   price => 'item_price',
351
   total => 'total_price'
352
};
353
354
=head3 $to_model_mapping
355
356
=cut
357
358
our $to_model_mapping = {
359
   suggestion_id => 'suggestionid',
360
   suggested_by => 'suggestedby',
361
   suggestion_date => 'suggesteddate',
362
   managed_by => 'managedby',
363
   managed_date => 'manageddate',
364
   accepted_date => 'accepteddate',
365
   rejected_by => 'rejectedby',
366
   rejected_date => 'rejectiondate',
367
   status => 'STATUS',
368
   note => 'note',
369
   author => 'author',
370
   title => 'title',
371
   copyright_date => 'copyrightdate',
372
   publisher_code => 'publishercode',
373
   date_created => 'date',
374
   volume_desc => 'volumedesc',
375
   publication_year => 'publicationyear',
376
   publication_place => 'place',
377
   isbn => 'isbn',
378
   biblio_id => 'biblionumber',
379
   reason => 'reason',
380
   patron_reason => 'patronreason',
381
   budget_id => 'budgetid',
382
   library_id => 'branchcode',
383
   collection_title => 'collectiontitle',
384
   item_type => 'itemtype',
385
   quantity => 'quantity',
386
   currency => 'currency',
387
   item_price => 'price',
388
   total_price => 'total'
389
};
257
1;
390
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