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

(-)a/Koha/REST/V1/DeletedBiblios.pm (+172 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 => { error => "Object not found." }
58
        );
59
    }
60
61
    return try {
62
63
        if ( $c->req->headers->accept =~ m/application\/json/ ) {
64
            return $c->render(
65
                status => 200,
66
                json   => $biblio->to_api
67
            );
68
        } else {
69
            my $metadata = $biblio->metadata;
70
            my $record   = $metadata->record;
71
            my $schema   = $metadata->schema // C4::Context->preference("marcflavour");
72
73
            $c->respond_to(
74
                marcxml => {
75
                    status => 200,
76
                    format => 'marcxml',
77
                    text   => $record->as_xml_record($schema),
78
                },
79
                mij => {
80
                    status => 200,
81
                    format => 'mij',
82
                    data   => $record->to_mij
83
                },
84
                marc => {
85
                    status => 200,
86
                    format => 'marc',
87
                    text   => $record->as_usmarc
88
                },
89
                txt => {
90
                    status => 200,
91
                    format => 'text/plain',
92
                    text   => $record->as_formatted
93
                },
94
                any => {
95
                    status  => 406,
96
                    openapi => [
97
                        "application/json",
98
                        "application/marcxml+xml",
99
                        "application/marc-in-json",
100
                        "application/marc",
101
                        "text/plain"
102
                    ]
103
                }
104
            );
105
        }
106
    } catch {
107
        $c->unhandled_exception($_);
108
    };
109
}
110
111
=head3 list
112
113
Controller function that handles listing a deleted biblio objects
114
115
=cut
116
117
sub list {
118
    my $c = shift->openapi->valid_input or return;
119
120
    my @prefetch = qw(biblioitem);
121
    push @prefetch, 'metadata'    # don't prefetch metadata if not needed
122
        unless $c->req->headers->accept =~ m/application\/json/;
123
124
    my $rs      = Koha::Old::Biblios->search( undef, { prefetch => \@prefetch } );
125
    my $biblios = $c->objects->search_rs( $rs, [ ( sub { $rs->api_query_fixer( $_[0], '', $_[1] ) } ) ] );
126
127
    return try {
128
129
        if ( $c->req->headers->accept =~ m/application\/json(;.*)?$/ ) {
130
            return $c->render(
131
                status => 200,
132
                json   => $c->objects->to_api($biblios),
133
            );
134
        } elsif ( $c->req->headers->accept =~ m/application\/marcxml\+xml(;.*)?$/ ) {
135
            $c->res->headers->add( 'Content-Type', 'application/marcxml+xml' );
136
            return $c->render(
137
                status => 200,
138
                text   => $biblios->print_collection('marcxml')
139
            );
140
        } elsif ( $c->req->headers->accept =~ m/application\/marc-in-json(;.*)?$/ ) {
141
            $c->res->headers->add( 'Content-Type', 'application/marc-in-json' );
142
            return $c->render(
143
                status => 200,
144
                data   => $biblios->print_collection('mij')
145
            );
146
        } elsif ( $c->req->headers->accept =~ m/application\/marc(;.*)?$/ ) {
147
            $c->res->headers->add( 'Content-Type', 'application/marc' );
148
            return $c->render(
149
                status => 200,
150
                text   => $biblios->print_collection('marc')
151
            );
152
        } elsif ( $c->req->headers->accept =~ m/text\/plain(;.*)?$/ ) {
153
            return $c->render(
154
                status => 200,
155
                text   => $biblios->print_collection('txt')
156
            );
157
        } else {
158
            return $c->render(
159
                status  => 406,
160
                openapi => [
161
                    "application/json",         "application/marcxml+xml",
162
                    "application/marc-in-json", "application/marc",
163
                    "text/plain"
164
                ]
165
            );
166
        }
167
    } catch {
168
        $c->unhandled_exception($_);
169
    };
170
}
171
172
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 279-284 paths: Link Here
279
    $ref: ./paths/config_smtp_servers.yaml#/~1config~1smtp_servers
279
    $ref: ./paths/config_smtp_servers.yaml#/~1config~1smtp_servers
280
  "/config/smtp_servers/{smtp_server_id}":
280
  "/config/smtp_servers/{smtp_server_id}":
281
    $ref: "./paths/config_smtp_servers.yaml#/~1config~1smtp_servers~1{smtp_server_id}"
281
    $ref: "./paths/config_smtp_servers.yaml#/~1config~1smtp_servers~1{smtp_server_id}"
282
  "/deleted/biblios":
283
    $ref: "./paths/deleted_biblios.yaml#/~1deleted~1biblios"
284
  "/deleted/biblios/{biblio_id}":
285
    $ref: "./paths/deleted_biblios.yaml#/~1deleted~1biblios~1{biblio_id}"
282
  /erm/config:
286
  /erm/config:
283
    $ref: ./paths/erm_config.yaml#/~1erm~1config
287
    $ref: ./paths/erm_config.yaml#/~1erm~1config
284
  /erm/agreements:
288
  /erm/agreements:
285
- 

Return to bug 33960