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

(-)a/Koha/Old/Item.pm (+60 lines)
Lines 55-60 sub restore { Link Here
55
    return $new_item;
55
    return $new_item;
56
}
56
}
57
57
58
=head3 to_api_mapping
59
60
This method returns the mapping for representing a Koha::Old::Item object
61
on the API.
62
63
=cut
64
65
sub to_api_mapping {
66
    return {
67
        itemnumber                        => 'item_id',
68
        biblionumber                      => 'biblio_id',
69
        biblioitemnumber                  => undef,
70
        barcode                           => 'external_id',
71
        dateaccessioned                   => 'acquisition_date',
72
        booksellerid                      => 'acquisition_source',
73
        homebranch                        => 'home_library_id',
74
        price                             => 'purchase_price',
75
        replacementprice                  => 'replacement_price',
76
        replacementpricedate              => 'replacement_price_date',
77
        datelastborrowed                  => 'last_checkout_date',
78
        datelastseen                      => 'last_seen_date',
79
        stack                             => undef,
80
        notforloan                        => 'not_for_loan_status',
81
        damaged                           => 'damaged_status',
82
        damaged_on                        => 'damaged_date',
83
        itemlost                          => 'lost_status',
84
        itemlost_on                       => 'lost_date',
85
        withdrawn                         => 'withdrawn',
86
        withdrawn_on                      => 'withdrawn_date',
87
        itemcallnumber                    => 'callnumber',
88
        coded_location_qualifier          => 'coded_location_qualifier',
89
        issues                            => 'checkouts_count',
90
        renewals                          => 'renewals_count',
91
        reserves                          => 'holds_count',
92
        restricted                        => 'restricted_status',
93
        itemnotes                         => 'public_notes',
94
        itemnotes_nonpublic               => 'internal_notes',
95
        holdingbranch                     => 'holding_library_id',
96
        permanent_location                => 'permanent_location',
97
        onloan                            => 'checked_out_date',
98
        cn_source                         => 'call_number_source',
99
        cn_sort                           => 'call_number_sort',
100
        ccode                             => 'collection_code',
101
        materials                         => 'materials_notes',
102
        itype                             => 'item_type_id',
103
        more_subfields_xml                => 'extended_subfields',
104
        enumchron                         => 'serial_issue_number',
105
        copynumber                        => 'copy_number',
106
        stocknumber                       => 'inventory_number',
107
        new_status                        => 'new_status',
108
        deleted_on                        => 'deleted_on',
109
        bookable                          => undef,
110
        location                          => undef,
111
        uri                               => undef,
112
        timestamp                         => undef,
113
        localuse                          => undef,
114
        exclude_from_local_holds_priority => undef,
115
    };
116
}
117
58
=head2 Internal methods
118
=head2 Internal methods
59
119
60
=head3 _type
120
=head3 _type
(-)a/Koha/REST/V1/DeletedItems.pm (+97 lines)
Line 0 Link Here
1
package Koha::REST::V1::DeletedItems;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::Old::Items;
23
24
use Try::Tiny qw( catch try );
25
26
=head1 API
27
28
=head2 Methods
29
30
=head3 get
31
32
Controller function that handles retrieving a single deleted item object
33
34
=cut
35
36
sub get {
37
    my $c = shift->openapi->valid_input or return;
38
39
    my $item = Koha::Old::Items->find( $c->param('item_id') );
40
41
    return $c->render_resource_not_found("Item")
42
        unless $item;
43
44
    return try {
45
        return $c->render(
46
            status  => 200,
47
            openapi => $c->objects->to_api($item),
48
        );
49
    } catch {
50
        $c->unhandled_exception($_);
51
    };
52
}
53
54
=head3 list
55
56
Controller function that handles listing deleted item objects
57
58
=cut
59
60
sub list {
61
    my $c = shift->openapi->valid_input or return;
62
63
    return try {
64
        my $items = $c->objects->search( Koha::Old::Items->new );
65
        return $c->render( status => 200, openapi => $items );
66
    } catch {
67
        $c->unhandled_exception($_);
68
    };
69
}
70
71
=head3 restore
72
73
Controller function that handles restoring a single deleted item object
74
75
=cut
76
77
sub restore {
78
    my $c = shift->openapi->valid_input or return;
79
80
    my $deleted_item = Koha::Old::Items->find( $c->param('item_id') );
81
82
    return $c->render_resource_not_found("Item")
83
        unless $deleted_item;
84
85
    return try {
86
        my $item = $deleted_item->restore;
87
88
        return $c->render(
89
            status  => 200,
90
            openapi => $c->objects->to_api($item),
91
        );
92
    } catch {
93
        $c->unhandled_exception($_);
94
    };
95
}
96
97
1;
(-)a/api/v1/swagger/definitions/item.yaml (+6 lines)
Lines 157-162 properties: Link Here
157
    type: string
157
    type: string
158
    format: date-time
158
    format: date-time
159
    description: Date and time this item was last altered
159
    description: Date and time this item was last altered
160
  deleted_on:
161
    type:
162
      - string
163
      - "null"
164
    format: date-time
165
    description: Date and time this item was deleted
160
  location:
166
  location:
161
    type:
167
    type:
162
      - string
168
      - string
(-)a/api/v1/swagger/paths/deleted_items.yaml (-1 / +145 lines)
Line 0 Link Here
0
- 
1
---
2
"/deleted/items":
3
  get:
4
    x-mojo-to: DeletedItems#list
5
    operationId: listDeletedItems
6
    tags:
7
      - items
8
    summary: List deleted items
9
    parameters:
10
      - $ref: "../swagger.yaml#/parameters/page"
11
      - $ref: "../swagger.yaml#/parameters/per_page"
12
      - $ref: "../swagger.yaml#/parameters/match"
13
      - $ref: "../swagger.yaml#/parameters/order_by"
14
      - $ref: "../swagger.yaml#/parameters/q_param"
15
      - $ref: "../swagger.yaml#/parameters/q_body"
16
      - $ref: "../swagger.yaml#/parameters/request_id_header"
17
    produces:
18
      - application/json
19
    responses:
20
      "200":
21
        description: A list of deleted items
22
        schema:
23
          type: array
24
          items:
25
            $ref: "../swagger.yaml#/definitions/item"
26
      "400":
27
        description: |
28
          Bad request. Possible `error_code` attribute values:
29
30
            * `invalid_query`
31
        schema:
32
          $ref: "../swagger.yaml#/definitions/error"
33
      "401":
34
        description: Authentication required
35
        schema:
36
          $ref: "../swagger.yaml#/definitions/error"
37
      "403":
38
        description: Access forbidden
39
        schema:
40
          $ref: "../swagger.yaml#/definitions/error"
41
      "500":
42
        description: |
43
          Internal server error. Possible `error_code` attribute values:
44
45
          * `internal_server_error`
46
        schema:
47
          $ref: "../swagger.yaml#/definitions/error"
48
      "503":
49
        description: Under maintenance
50
        schema:
51
          $ref: "../swagger.yaml#/definitions/error"
52
    x-koha-authorization:
53
      permissions:
54
        catalogue: "1"
55
"/deleted/items/{item_id}":
56
  get:
57
    x-mojo-to: DeletedItems#get
58
    operationId: getDeletedItem
59
    tags:
60
      - items
61
    summary: Get deleted item
62
    parameters:
63
      - $ref: "../swagger.yaml#/parameters/item_id_pp"
64
    produces:
65
      - application/json
66
    responses:
67
      "200":
68
        description: A deleted item
69
        schema:
70
          $ref: "../swagger.yaml#/definitions/item"
71
      "400":
72
        description: Bad request
73
        schema:
74
          $ref: "../swagger.yaml#/definitions/error"
75
      "401":
76
        description: Authentication required
77
        schema:
78
          $ref: "../swagger.yaml#/definitions/error"
79
      "403":
80
        description: Access forbidden
81
        schema:
82
          $ref: "../swagger.yaml#/definitions/error"
83
      "404":
84
        description: Item not found
85
        schema:
86
          $ref: "../swagger.yaml#/definitions/error"
87
      "500":
88
        description: |
89
          Internal server error. Possible `error_code` attribute values:
90
91
          * `internal_server_error`
92
        schema:
93
          $ref: "../swagger.yaml#/definitions/error"
94
      "503":
95
        description: Under maintenance
96
        schema:
97
          $ref: "../swagger.yaml#/definitions/error"
98
    x-koha-authorization:
99
      permissions:
100
        catalogue: "1"
101
  put:
102
    x-mojo-to: DeletedItems#restore
103
    operationId: restoreDeletedItem
104
    tags:
105
      - items
106
    summary: Restore deleted item
107
    parameters:
108
      - $ref: "../swagger.yaml#/parameters/item_id_pp"
109
    produces:
110
      - application/json
111
    responses:
112
      "200":
113
        description: Item restored successfully
114
        schema:
115
          $ref: "../swagger.yaml#/definitions/item"
116
      "400":
117
        description: Bad request
118
        schema:
119
          $ref: "../swagger.yaml#/definitions/error"
120
      "401":
121
        description: Authentication required
122
        schema:
123
          $ref: "../swagger.yaml#/definitions/error"
124
      "403":
125
        description: Access forbidden
126
        schema:
127
          $ref: "../swagger.yaml#/definitions/error"
128
      "404":
129
        description: Deleted item not found
130
        schema:
131
          $ref: "../swagger.yaml#/definitions/error"
132
      "500":
133
        description: |
134
          Internal server error. Possible `error_code` attribute values:
135
136
          * `internal_server_error`
137
        schema:
138
          $ref: "../swagger.yaml#/definitions/error"
139
      "503":
140
        description: Under maintenance
141
        schema:
142
          $ref: "../swagger.yaml#/definitions/error"
143
    x-koha-authorization:
144
      permissions:
145
        editcatalogue: edit_catalogue

Return to bug 17387