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

(-)a/Koha/REST/V1/DeletedBiblios.pm (+186 lines)
Line 0 Link Here
1
package Koha::REST::V1::DeletedBiblios;
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 <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::Old::Biblios;
23
use Koha::DateUtils;
24
use Koha::RecordProcessor;
25
26
use C4::Context;
27
28
use Koha::Items;
29
30
use List::MoreUtils qw( any );
31
use MARC::Record::MiJ;
32
33
use Try::Tiny qw( catch try );
34
35
=head1 API
36
37
=head2 Methods
38
39
=head3 get
40
41
Controller function that handles retrieving a single biblio object
42
43
=cut
44
45
sub get {
46
    my $c = shift->openapi->valid_input or return;
47
48
    my $attributes;
49
    $attributes = { prefetch => [ 'metadata' ] } # don't prefetch metadata if not needed
50
        unless $c->req->headers->accept =~ m/application\/json/;
51
52
    my $biblio = Koha::Old::Biblios->find( { biblionumber => $c->param('biblio_id') }, $attributes );
53
54
    unless ( $biblio ) {
55
        return $c->render(
56
            status  => 404,
57
            openapi => {
58
                error => "Object not found."
59
            }
60
        );
61
    }
62
63
    return try {
64
65
        if ( $c->req->headers->accept =~ m/application\/json/ ) {
66
            return $c->render(
67
                status => 200,
68
                json   => $biblio->to_api
69
            );
70
        }
71
        else {
72
            my $metadata = $biblio->metadata;
73
            my $record   = $metadata->record;
74
            my $schema   = $metadata->schema // C4::Context->preference("marcflavour");
75
76
            $c->respond_to(
77
                marcxml => {
78
                    status => 200,
79
                    format => 'marcxml',
80
                    text   => $record->as_xml_record($schema),
81
                },
82
                mij => {
83
                    status => 200,
84
                    format => 'mij',
85
                    data   => $record->to_mij
86
                },
87
                marc => {
88
                    status => 200,
89
                    format => 'marc',
90
                    text   => $record->as_usmarc
91
                },
92
                txt => {
93
                    status => 200,
94
                    format => 'text/plain',
95
                    text   => $record->as_formatted
96
                },
97
                any => {
98
                    status  => 406,
99
                    openapi => [
100
                        "application/json",
101
                        "application/marcxml+xml",
102
                        "application/marc-in-json",
103
                        "application/marc",
104
                        "text/plain"
105
                    ]
106
                }
107
            );
108
        }
109
    }
110
    catch {
111
        $c->unhandled_exception($_);
112
    };
113
}
114
115
=head3 list
116
117
Controller function that handles listing a deleted biblio objects
118
119
=cut
120
121
sub list {
122
    my $c = shift->openapi->valid_input or return;
123
124
    my @prefetch = qw(biblioitem);
125
    push @prefetch, 'metadata'    # don't prefetch metadata if not needed
126
      unless $c->req->headers->accept =~ m/application\/json/;
127
128
    my $rs = Koha::Old::Biblios->search( undef, { prefetch => \@prefetch });
129
    my $biblios = $c->objects->search_rs( $rs, [(sub{ $rs->api_query_fixer( $_[0], '', $_[1] ) })] );
130
131
    return try {
132
133
        if ( $c->req->headers->accept =~ m/application\/json(;.*)?$/ ) {
134
            return $c->render(
135
                status => 200,
136
                json   => $c->objects->to_api( $biblios ),
137
            );
138
        }
139
        elsif (
140
            $c->req->headers->accept =~ m/application\/marcxml\+xml(;.*)?$/ )
141
        {
142
            $c->res->headers->add( 'Content-Type', 'application/marcxml+xml' );
143
            return $c->render(
144
                status => 200,
145
                text   => $biblios->print_collection('marcxml')
146
            );
147
        }
148
        elsif (
149
            $c->req->headers->accept =~ m/application\/marc-in-json(;.*)?$/ )
150
        {
151
            $c->res->headers->add( 'Content-Type', 'application/marc-in-json' );
152
            return $c->render(
153
                status => 200,
154
                data   => $biblios->print_collection('mij')
155
            );
156
        }
157
        elsif ( $c->req->headers->accept =~ m/application\/marc(;.*)?$/ ) {
158
            $c->res->headers->add( 'Content-Type', 'application/marc' );
159
            return $c->render(
160
                status => 200,
161
                text   => $biblios->print_collection('marc')
162
            );
163
        }
164
        elsif ( $c->req->headers->accept =~ m/text\/plain(;.*)?$/ ) {
165
            return $c->render(
166
                status => 200,
167
                text   => $biblios->print_collection('txt')
168
            );
169
        }
170
        else {
171
            return $c->render(
172
                status  => 406,
173
                openapi => [
174
                    "application/json",         "application/marcxml+xml",
175
                    "application/marc-in-json", "application/marc",
176
                    "text/plain"
177
                ]
178
            );
179
        }
180
    }
181
    catch {
182
        $c->unhandled_exception($_);
183
    };
184
}
185
186
1;
(-)a/api/v1/swagger/paths/deleted_biblios.yaml (+109 lines)
Line 0 Link Here
1
---
2
"/deleted/biblios":
3
  get:
4
    x-mojo-to: DeletedBiblios#list
5
    operationId: listDeletedBiblios
6
    tags:
7
      - biblios
8
    summary: List deleted biblios
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
      - application/marcxml+xml
20
      - application/marc-in-json
21
      - application/marc
22
      - text/plain
23
    responses:
24
      "200":
25
        description: A list of deleted biblios
26
      "401":
27
        description: Authentication required
28
        schema:
29
          $ref: "../swagger.yaml#/definitions/error"
30
      "403":
31
        description: Access forbidden
32
        schema:
33
          $ref: "../swagger.yaml#/definitions/error"
34
      "404":
35
        description: Biblio not found
36
        schema:
37
          $ref: "../swagger.yaml#/definitions/error"
38
      "406":
39
        description: Not acceptable
40
        schema:
41
          type: array
42
          description: Accepted content-types
43
          items:
44
            type: string
45
      "500":
46
        description: |
47
          Internal server error. Possible `error_code` attribute values:
48
49
          * `internal_server_error`
50
        schema:
51
          $ref: "../swagger.yaml#/definitions/error"
52
      "503":
53
        description: Under maintenance
54
        schema:
55
          $ref: "../swagger.yaml#/definitions/error"
56
    x-koha-authorization:
57
      permissions:
58
        catalogue: "1"
59
"/deleted/biblios/{biblio_id}":
60
  get:
61
    x-mojo-to: DeletedBiblios#get
62
    operationId: getDeletedBiblio
63
    tags:
64
      - biblios
65
    summary: Get deleted biblio
66
    parameters:
67
      - $ref: "../swagger.yaml#/parameters/biblio_id_pp"
68
    produces:
69
      - application/json
70
      - application/marcxml+xml
71
      - application/marc-in-json
72
      - application/marc
73
      - text/plain
74
    responses:
75
      "200":
76
        description: A deleted biblio
77
      "401":
78
        description: Authentication required
79
        schema:
80
          $ref: "../swagger.yaml#/definitions/error"
81
      "403":
82
        description: Access forbidden
83
        schema:
84
          $ref: "../swagger.yaml#/definitions/error"
85
      "404":
86
        description: Biblio not found
87
        schema:
88
          $ref: "../swagger.yaml#/definitions/error"
89
      "406":
90
        description: Not acceptable
91
        schema:
92
          type: array
93
          description: Accepted content-types
94
          items:
95
            type: string
96
      "500":
97
        description: |
98
          Internal server error. Possible `error_code` attribute values:
99
100
          * `internal_server_error`
101
        schema:
102
          $ref: "../swagger.yaml#/definitions/error"
103
      "503":
104
        description: Under maintenance
105
        schema:
106
          $ref: "../swagger.yaml#/definitions/error"
107
    x-koha-authorization:
108
      permissions:
109
        catalogue: "1"
(-)a/api/v1/swagger/swagger.yaml (-1 / +4 lines)
Lines 271-276 paths: Link Here
271
    $ref: ./paths/config_smtp_servers.yaml#/~1config~1smtp_servers
271
    $ref: ./paths/config_smtp_servers.yaml#/~1config~1smtp_servers
272
  "/config/smtp_servers/{smtp_server_id}":
272
  "/config/smtp_servers/{smtp_server_id}":
273
    $ref: "./paths/config_smtp_servers.yaml#/~1config~1smtp_servers~1{smtp_server_id}"
273
    $ref: "./paths/config_smtp_servers.yaml#/~1config~1smtp_servers~1{smtp_server_id}"
274
  "/deleted/biblios":
275
    $ref: "./paths/deleted_biblios.yaml#/~1deleted~1biblios"
276
  "/deleted/biblios/{biblio_id}":
277
    $ref: "./paths/deleted_biblios.yaml#/~1deleted~1biblios~1{biblio_id}"
274
  /erm/config:
278
  /erm/config:
275
    $ref: ./paths/erm_config.yaml#/~1erm~1config
279
    $ref: ./paths/erm_config.yaml#/~1erm~1config
276
  /erm/agreements:
280
  /erm/agreements:
277
- 

Return to bug 33960