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

(-)a/Koha/Biblio.pm (+107 lines)
Lines 36-41 use Koha::Biblio::Metadatas; Link Here
36
use Koha::Biblio::ItemGroups;
36
use Koha::Biblio::ItemGroups;
37
use Koha::Biblioitems;
37
use Koha::Biblioitems;
38
use Koha::Cache::Memory::Lite;
38
use Koha::Cache::Memory::Lite;
39
use Koha::Bookings;
39
use Koha::Checkouts;
40
use Koha::Checkouts;
40
use Koha::CirculationRules;
41
use Koha::CirculationRules;
41
use Koha::Exceptions;
42
use Koha::Exceptions;
Lines 199-204 sub can_article_request { Link Here
199
    return q{};
200
    return q{};
200
}
201
}
201
202
203
=head3 check_booking
204
205
  my $bookable =
206
    $biblio->check_booking( { start_date => $datetime, end_date => $datetime, [ booking_id => $booking_id ] } );
207
208
Returns a boolean denoting whether the passed booking can be made without clashing.
209
210
Optionally, you may pass a booking id to exclude from the checks; This is helpful when you are updating an existing booking.
211
212
=cut
213
214
sub check_booking {
215
    my ( $self, $params ) = @_;
216
217
    my $start_date = dt_from_string( $params->{start_date} );
218
    my $end_date   = dt_from_string( $params->{end_date} );
219
    my $booking_id = $params->{booking_id};
220
221
    my $bookable_items = $self->items;
222
    my $total_bookable = $bookable_items->count;
223
224
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
225
    my $existing_bookings = $self->bookings(
226
        [
227
            start_date => {
228
                '-between' => [
229
                    $dtf->format_datetime($start_date),
230
                    $dtf->format_datetime($end_date)
231
                ]
232
            },
233
            end_date => {
234
                '-between' => [
235
                    $dtf->format_datetime($start_date),
236
                    $dtf->format_datetime($end_date)
237
                ]
238
            },
239
            {
240
                start_date => { '<' => $dtf->format_datetime($start_date) },
241
                end_date   => { '>' => $dtf->format_datetime($end_date) }
242
            }
243
        ]
244
    );
245
246
    my $booked_count =
247
      defined($booking_id)
248
      ? $existing_bookings->search( { booking_id => { '!=' => $booking_id } } )
249
      ->count
250
      : $existing_bookings->count;
251
    return ( ( $total_bookable - $booked_count ) > 0 ) ? 1 : 0;
252
}
253
254
=head3 place_booking
255
256
  my $booking = $biblio->place_booking(
257
    {
258
        patron     => $patron,
259
        start_date => $datetime,
260
        end_date   => $datetime
261
    }
262
  );
263
264
Add a booking for this item for the dates passed.
265
266
Returns the Koha::Booking object or throws an exception if the item cannot be booked for the given dates.
267
268
=cut
269
270
sub place_booking {
271
    my ( $self, $params ) = @_;
272
273
    # check for mandatory params
274
    my @mandatory = ( 'start_date', 'end_date', 'patron' );
275
    for my $param (@mandatory) {
276
        unless ( defined( $params->{$param} ) ) {
277
            Koha::Exceptions::MissingParameter->throw(
278
                error => "The $param parameter is mandatory" );
279
        }
280
    }
281
    my $patron = $params->{patron};
282
283
    # New booking object
284
    my $booking = Koha::Booking->new(
285
        {
286
            start_date     => $params->{start_date},
287
            end_date       => $params->{end_date},
288
            borrowernumber => $patron->borrowernumber,
289
            biblionumber   => $self->biblionumber
290
        }
291
    )->store();
292
    return $booking;
293
}
294
202
=head3 can_be_transferred
295
=head3 can_be_transferred
203
296
204
$biblio->can_be_transferred({ to => $to_library, from => $from_library })
297
$biblio->can_be_transferred({ to => $to_library, from => $from_library })
Lines 569-574 sub biblioitem { Link Here
569
    return $self->{_biblioitem};
662
    return $self->{_biblioitem};
570
}
663
}
571
664
665
=head3 bookings
666
667
  my $bookings = $item->bookings();
668
669
Returns the bookings attached to this biblio.
670
671
=cut
672
673
sub bookings {
674
    my ( $self, $params ) = @_;
675
    my $bookings_rs = $self->_result->bookings->search($params);
676
    return Koha::Bookings->_new_from_dbic( $bookings_rs );
677
}
678
572
=head3 suggestions
679
=head3 suggestions
573
680
574
my $suggestions = $self->suggestions
681
my $suggestions = $self->suggestions
(-)a/Koha/Booking.pm (+212 lines)
Line 0 Link Here
1
package Koha::Booking;
2
3
# Copyright PTFS Europe 2021
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Koha::Exceptions::Booking;
23
use Koha::DateUtils qw( dt_from_string );
24
25
use base qw(Koha::Object);
26
27
=head1 NAME
28
29
Koha::Booking - Koha Booking object class
30
31
=head1 API
32
33
=head2 Class methods
34
35
=head3 biblio
36
37
Returns the related Koha::Biblio object for this booking
38
39
=cut
40
41
sub biblio {
42
    my ($self) = @_;
43
44
    my $biblio_rs = $self->_result->biblio;
45
    return Koha::Biblio->_new_from_dbic($biblio_rs);
46
}
47
48
=head3 patron
49
50
Returns the related Koha::Patron object for this booking
51
52
=cut
53
54
sub patron {
55
    my ($self) = @_;
56
57
    my $patron_rs = $self->_result->patron;
58
    return Koha::Patron->_new_from_dbic($patron_rs);
59
}
60
61
=head3 item
62
63
Returns the related Koha::Item object for this Booking
64
65
=cut
66
67
sub item {
68
    my ($self) = @_;
69
70
    my $item_rs = $self->_result->item;
71
    return unless $item_rs;
72
    return Koha::Item->_new_from_dbic($item_rs);
73
}
74
75
=head3 store
76
77
Booking specific store method to catch booking clashes
78
79
=cut
80
81
sub store {
82
    my ($self) = @_;
83
84
    $self->_result->result_source->schema->txn_do(
85
        sub {
86
            if ( $self->item_id ) {
87
                Koha::Exceptions::Object::FKConstraint->throw(
88
                    broken_fk => 'item_id',
89
                    value     => $self->item_id,
90
                ) unless ( $self->item );
91
92
                $self->biblio_id( $self->item->biblionumber )
93
                  unless $self->biblio_id;
94
95
                Koha::Exceptions::Object::FKConstraint->throw()
96
                  unless ( $self->biblio_id == $self->item->biblionumber );
97
            }
98
99
            Koha::Exceptions::Object::FKConstraint->throw(
100
                broken_fk => 'biblio_id',
101
                value     => $self->biblio_id,
102
            ) unless ( $self->biblio );
103
104
            # Throw exception for item level booking clash
105
            Koha::Exceptions::Booking::Clash->throw()
106
              if $self->item_id && !$self->item->check_booking(
107
                {
108
                    start_date => $self->start_date,
109
                    end_date   => $self->end_date,
110
                    booking_id => $self->in_storage ? $self->booking_id : undef
111
                }
112
              );
113
114
            # Throw exception for biblio level booking clash
115
            Koha::Exceptions::Booking::Clash->throw()
116
              if !$self->biblio->check_booking(
117
                {
118
                    start_date => $self->start_date,
119
                    end_date   => $self->end_date,
120
                    booking_id => $self->in_storage ? $self->booking_id : undef
121
                }
122
              );
123
124
            $self = $self->SUPER::store;
125
        }
126
    );
127
128
    return $self;
129
}
130
131
=head3 intersects
132
133
  my $intersects = $booking1->intersects($booking2);
134
135
Returns a boolean denoting whether booking1 interfers/overlaps/clashes with booking2.
136
137
=cut
138
139
sub intersects {
140
    my ( $self, $comp ) = @_;
141
142
    # Start date of comparison booking is after end date of this booking.
143
    return 0
144
      if (
145
        DateTime->compare(
146
            dt_from_string( $comp->start_date ),
147
            dt_from_string( $self->end_date )
148
        ) >= 0
149
      );
150
151
    # End date of comparison booking is before start date of this booking.
152
    return 0
153
      if (
154
        DateTime->compare(
155
            dt_from_string( $comp->end_date ),
156
            dt_from_string( $self->start_date )
157
        ) <= 0
158
      );
159
160
    # Bookings must overlap
161
    return 1;
162
}
163
164
=head3 get_items_that_can_fill
165
166
    my $items = $bookings->get_items_that_can_fill();
167
168
Return the list of items that can fulfill this booking.
169
170
Items that are not:
171
172
  in transit
173
  lost
174
  withdrawn
175
  not for loan
176
  not already booked
177
178
=cut
179
180
sub get_items_that_can_fill {
181
    my ($self) = @_;
182
    return;
183
}
184
185
=head3 to_api_mapping
186
187
This method returns the mapping for representing a Koha::Booking object
188
on the API.
189
190
=cut
191
192
sub to_api_mapping {
193
    return {};
194
}
195
196
=head2 Internal methods
197
198
=head3 _type
199
200
=cut
201
202
sub _type {
203
    return 'Booking';
204
}
205
206
=head1 AUTHORS
207
208
Martin Renvoize <martin.renvoize@ptfs-europe.com>
209
210
=cut
211
212
1;
(-)a/Koha/Bookings.pm (+59 lines)
Line 0 Link Here
1
package Koha::Bookings;
2
3
# Copyright PTFS Europe 2021
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
use Koha::Booking;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::Bookings - Koha Booking object set class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'Booking';
43
}
44
45
=head3 object_class
46
47
=cut
48
49
sub object_class {
50
    return 'Koha::Booking';
51
}
52
53
=head1 AUTHOR
54
55
Martin Renvoize <martin.renvoize@ptfs-europe.com>
56
57
=cut
58
59
1;
(-)a/Koha/Exceptions/Booking.pm (+15 lines)
Line 0 Link Here
1
package Koha::Exceptions::Booking;
2
3
use Modern::Perl;
4
5
use Exception::Class (
6
    'Koha::Exceptions::Booking' => {
7
        description => "Something went wrong!"
8
    },
9
    'Koha::Exceptions::Booking::Clash' => {
10
        isa         => 'Koha::Exceptions::Booking',
11
        description => "Adding or updateing the booking would result in a clash"
12
    },
13
);
14
15
1;
(-)a/Koha/Item.pm (+105 lines)
Lines 484-489 sub holds { Link Here
484
    return Koha::Holds->_new_from_dbic( $holds_rs );
484
    return Koha::Holds->_new_from_dbic( $holds_rs );
485
}
485
}
486
486
487
=head3 bookings
488
489
  my $bookings = $item->bookings();
490
491
Returns the bookings attached to this item.
492
493
=cut
494
495
sub bookings {
496
    my ( $self, $params ) = @_;
497
    my $bookings_rs = $self->_result->bookings->search($params);
498
    return Koha::Bookings->_new_from_dbic( $bookings_rs );
499
}
500
501
=head3 check_booking
502
503
  my $bookable =
504
    $item->check_booking( { start_date => $datetime, end_date => $datetime, [ booking_id => $booking_id ] } );
505
506
Returns a boolean denoting whether the passed booking can be made without clashing.
507
508
Optionally, you may pass a booking id to exclude from the checks; This is helpful when you are updating an existing booking.
509
510
=cut
511
512
sub check_booking {
513
    my ($self, $params) = @_;
514
515
    my $start_date = dt_from_string( $params->{start_date} );
516
    my $end_date   = dt_from_string( $params->{end_date} );
517
    my $booking_id = $params->{booking_id};
518
519
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
520
    my $existing_bookings = $self->bookings(
521
        [
522
            start_date => {
523
                '-between' => [
524
                    $dtf->format_datetime($start_date),
525
                    $dtf->format_datetime($end_date)
526
                ]
527
            },
528
            end_date => {
529
                '-between' => [
530
                    $dtf->format_datetime($start_date),
531
                    $dtf->format_datetime($end_date)
532
                ]
533
            },
534
            {
535
                start_date => { '<' => $dtf->format_datetime($start_date) },
536
                end_date   => { '>' => $dtf->format_datetime($end_date) }
537
            }
538
        ]
539
    );
540
541
    my $bookings_count =
542
      defined($booking_id)
543
      ? $existing_bookings->search( { booking_id => { '!=' => $booking_id } } )
544
      ->count
545
      : $existing_bookings->count;
546
547
    return $bookings_count ? 0 : 1;
548
}
549
550
=head3 place_booking
551
552
  my $booking = $item->place_booking(
553
    {
554
        patron     => $patron,
555
        start_date => $datetime,
556
        end_date   => $datetime
557
    }
558
  );
559
560
Add a booking for this item for the dates passed.
561
562
Returns the Koha::Booking object or throws an exception if the item cannot be booked for the given dates.
563
564
=cut
565
566
sub place_booking {
567
    my ( $self, $params ) = @_;
568
569
    # check for mandatory params
570
    my @mandatory = ( 'start_date', 'end_date', 'patron' );
571
    for my $param (@mandatory) {
572
        unless ( defined( $params->{$param} ) ) {
573
            Koha::Exceptions::MissingParameter->throw(
574
                error => "The $param parameter is mandatory" );
575
        }
576
    }
577
    my $patron = $params->{patron};
578
579
    # New booking object
580
    my $booking = Koha::Booking->new(
581
        {
582
            start_date     => $params->{start_date},
583
            end_date       => $params->{end_date},
584
            borrowernumber => $patron->borrowernumber,
585
            biblionumber   => $self->biblionumber,
586
            itemnumber     => $self->itemnumber,
587
        }
588
    )->store();
589
    return $booking;
590
}
591
487
=head3 request_transfer
592
=head3 request_transfer
488
593
489
  my $transfer = $item->request_transfer(
594
  my $transfer = $item->request_transfer(
(-)a/Koha/REST/V1/Biblios.pm (+34 lines)
Lines 246-251 sub get_public { Link Here
246
    };
246
    };
247
}
247
}
248
248
249
=head3 get_bookings
250
251
Controller function that handles retrieving biblio's bookings
252
253
=cut
254
255
sub get_bookings {
256
    my $c = shift->openapi->valid_input or return;
257
258
    my $biblio = Koha::Biblios->find( { biblionumber => $c->validation->param('biblio_id') }, { prefetch => ['bookings'] } );
259
260
    unless ( $biblio ) {
261
        return $c->render(
262
            status  => 404,
263
            openapi => {
264
                error => "Object not found."
265
            }
266
        );
267
    }
268
269
    return try {
270
271
        my $bookings_rs = $biblio->bookings;
272
        my $bookings    = $c->objects->search( $bookings_rs );
273
        return $c->render(
274
            status  => 200,
275
            openapi => $bookings
276
        );
277
    }
278
    catch {
279
        $c->unhandled_exception($_);
280
    };
281
}
282
249
=head3 get_items
283
=head3 get_items
250
284
251
Controller function that handles retrieving biblio's items
285
Controller function that handles retrieving biblio's items
(-)a/Koha/REST/V1/Bookings.pm (+165 lines)
Line 0 Link Here
1
package Koha::REST::V1::Bookings;
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::Bookings;
23
24
use Try::Tiny qw( catch try );
25
26
=head1 API
27
28
=head2 Methods
29
30
=head3 list
31
32
Controller function that handles retrieving a list of bookings
33
34
=cut
35
36
sub list {
37
    my $c = shift->openapi->valid_input or return;
38
39
    return try {
40
        my $bookings_set = Koha::Bookings->new;
41
        my $bookings     = $c->objects->search($bookings_set);
42
        return $c->render( status => 200, openapi => $bookings );
43
    }
44
    catch {
45
        $c->unhandled_exception($_);
46
    };
47
48
}
49
50
=head3 get
51
52
Controller function that handles retrieving a single booking
53
54
=cut
55
56
sub get {
57
    my $c = shift->openapi->valid_input or return;
58
59
    return try {
60
        my $booking =
61
          Koha::Bookings->find( $c->validation->param('booking_id') );
62
        unless ($booking) {
63
            return $c->render(
64
                status  => 404,
65
                openapi => { error => "Booking not found" }
66
            );
67
        }
68
69
        return $c->render( status => 200, openapi => $booking->to_api );
70
    }
71
    catch {
72
        $c->unhandled_exception($_);
73
    }
74
}
75
76
=head3 add
77
78
Controller function that handles adding a new booking
79
80
=cut
81
82
sub add {
83
    my $c = shift->openapi->valid_input or return;
84
85
    return try {
86
        my $booking =
87
          Koha::Booking->new_from_api( $c->validation->param('body') );
88
        $booking->store;
89
        $c->res->headers->location(
90
            $c->req->url->to_string . '/' . $booking->booking_id );
91
        return $c->render(
92
            status  => 201,
93
            openapi => $booking->to_api
94
        );
95
    }
96
    catch {
97
        if ( blessed $_ and $_->isa('Koha::Exceptions::Booking::Clash') ) {
98
            return $c->render(
99
                status  => 400,
100
                openapi => { error => "Booking would conflict" }
101
            );
102
        }
103
104
        return $c->unhandled_exception($_);
105
    };
106
}
107
108
=head3 update
109
110
Controller function that handles updating an existing booking
111
112
=cut
113
114
sub update {
115
    my $c = shift->openapi->valid_input or return;
116
117
    my $booking = Koha::Bookings->find( $c->validation->param('booking_id') );
118
119
    if ( not defined $booking ) {
120
        return $c->render(
121
            status  => 404,
122
            openapi => { error => "Object not found" }
123
        );
124
    }
125
126
    return try {
127
        $booking->set_from_api( $c->validation->param('body') );
128
        $booking->store();
129
        return $c->render( status => 200, openapi => $booking->to_api );
130
    }
131
    catch {
132
        $c->unhandled_exception($_);
133
    };
134
}
135
136
=head3 delete
137
138
Controller function that handles removing an existing booking
139
140
=cut
141
142
sub delete {
143
    my $c = shift->openapi->valid_input or return;
144
145
    my $booking = Koha::Bookings->find( $c->validation->param('booking_id') );
146
    if ( not defined $booking ) {
147
        return $c->render(
148
            status  => 404,
149
            openapi => { error => "Object not found" }
150
        );
151
    }
152
153
    return try {
154
        $booking->delete;
155
        return $c->render(
156
            status  => 204,
157
            openapi => q{}
158
        );
159
    }
160
    catch {
161
        $c->unhandled_exception($_);
162
    };
163
}
164
165
1;
(-)a/Koha/REST/V1/Items.pm (+34 lines)
Lines 174-179 sub delete { Link Here
174
    };
174
    };
175
}
175
}
176
176
177
=head3 get_bookings
178
179
Controller function that handles retrieving item's bookings
180
181
=cut
182
183
sub get_bookings {
184
    my $c = shift->openapi->valid_input or return;
185
186
    my $item = Koha::Items->find( { itemnumber => $c->validation->param('item_id') }, { prefetch => ['bookings'] } );
187
188
    unless ( $item ) {
189
        return $c->render(
190
            status  => 404,
191
            openapi => {
192
                error => "Object not found."
193
            }
194
        );
195
    }
196
197
    return try {
198
199
        my $bookings_rs = $item->bookings;
200
        my $bookings    = $c->objects->search( $bookings_rs );
201
        return $c->render(
202
            status  => 200,
203
            openapi => $bookings
204
        );
205
    }
206
    catch {
207
        $c->unhandled_exception($_);
208
    };
209
}
210
177
=head3 pickup_locations
211
=head3 pickup_locations
178
212
179
Method that returns the possible pickup_locations for a given item
213
Method that returns the possible pickup_locations for a given item
(-)a/api/v1/swagger/definitions/booking.yaml (+45 lines)
Line 0 Link Here
1
---
2
additionalProperties: false
3
properties:
4
  biblio_id:
5
    description: Internal identifier for the parent bibliographic record
6
    type: integer
7
  biblio:
8
    description: Embedable biblio representation
9
    type: object
10
  booking_id:
11
    description: Internal booking identifier
12
    type: integer
13
  end_date:
14
    description: Start date and time of this booking
15
    format: date-time
16
    type: string
17
  item_id:
18
    description: Internal item identifier
19
    type:
20
      - integer
21
      - "null"
22
  item:
23
    description: Embedable item representation
24
    type:
25
      - object
26
      - "null"
27
  patron_id:
28
    description: Internal patron identifier
29
    type: integer
30
  patron:
31
    description: Embedable patron representation
32
    type:
33
      - object
34
      - "null"
35
  start_date:
36
    description: Start date and time of this booking
37
    format: date-time
38
    type: string
39
required:
40
  - biblio_id
41
  - item_id
42
  - patron_id
43
  - start_date
44
  - end_date
45
type: object
(-)a/api/v1/swagger/parameters/booking.yaml (+6 lines)
Line 0 Link Here
1
booking_id_pp:
2
  name: booking_id
3
  in: path
4
  description: Booking internal identifier
5
  required: true
6
  type: integer
(-)a/api/v1/swagger/paths/biblios.yaml (+68 lines)
Lines 275-280 Link Here
275
    x-koha-authorization:
275
    x-koha-authorization:
276
      permissions:
276
      permissions:
277
        editcatalogue: edit_catalogue
277
        editcatalogue: edit_catalogue
278
"/biblios/{biblio_id}/bookings":
279
  get:
280
    x-mojo-to: Biblios#get_bookings
281
    operationId: getBiblioBookings
282
    tags:
283
      - bookings
284
    summary: Get bookings for a biblio
285
    parameters:
286
      - $ref: "../swagger.yaml#/parameters/biblio_id_pp"
287
      - $ref: "../swagger.yaml#/parameters/match"
288
      - $ref: "../swagger.yaml#/parameters/order_by"
289
      - $ref: "../swagger.yaml#/parameters/page"
290
      - $ref: "../swagger.yaml#/parameters/per_page"
291
      - $ref: "../swagger.yaml#/parameters/q_param"
292
      - $ref: "../swagger.yaml#/parameters/q_body"
293
      - $ref: "../swagger.yaml#/parameters/q_header"
294
      - name: x-koha-embed
295
        in: header
296
        required: false
297
        description: Embed list sent as a request header
298
        type: array
299
        items:
300
          type: string
301
          enum:
302
            - item
303
            - patron
304
        collectionFormat: csv
305
    consumes:
306
      - application/json
307
    produces:
308
      - application/json
309
    responses:
310
      "200":
311
        description: A list of the bookings attached to the record
312
        schema:
313
          type: array
314
          items:
315
            $ref: ../swagger.yaml#/definitions/booking
316
      "401":
317
        description: Authentication required
318
        schema:
319
          $ref: ../swagger.yaml#/definitions/error
320
      "403":
321
        description: Access forbidden
322
        schema:
323
          $ref: ../swagger.yaml#/definitions/error
324
      "404":
325
        description: Biblio not found
326
        schema:
327
          $ref: ../swagger.yaml#/definitions/error
328
      "406":
329
        description: Not acceptable
330
        schema:
331
          type: array
332
          description: Accepted content-types
333
          items:
334
            type: string
335
      "500":
336
        description: Internal server error
337
        schema:
338
          $ref: ../swagger.yaml#/definitions/error
339
      "503":
340
        description: Under maintenance
341
        schema:
342
          $ref: ../swagger.yaml#/definitions/error
343
    x-koha-authorization:
344
      permissions:
345
        circulation: "1"
278
"/biblios/{biblio_id}/checkouts":
346
"/biblios/{biblio_id}/checkouts":
279
  get:
347
  get:
280
    x-mojo-to: Biblios#get_checkouts
348
    x-mojo-to: Biblios#get_checkouts
(-)a/api/v1/swagger/paths/bookings.yaml (+235 lines)
Line 0 Link Here
1
---
2
/bookings:
3
  get:
4
    x-mojo-to: Bookings#list
5
    operationId: listBookings
6
    parameters:
7
      - description: Case insensative search on booking biblio_id
8
        in: query
9
        name: biblio_id
10
        required: false
11
        type: string
12
      - description: Case insensative search on booking item_id
13
        in: query
14
        name: item_id
15
        required: false
16
        type: string
17
      - description: Case insensative search on booking patron_id
18
        in: query
19
        name: patron_id
20
        required: false
21
        type: string
22
      - description: Case Insensative search on booking start_date
23
        in: query
24
        name: start_date
25
        required: false
26
        type: string
27
      - description: Case Insensative search on booking end_date
28
        in: query
29
        name: end_date
30
        required: false
31
        type: string
32
      - $ref: "../swagger.yaml#/parameters/match"
33
      - $ref: "../swagger.yaml#/parameters/order_by"
34
      - $ref: "../swagger.yaml#/parameters/page"
35
      - $ref: "../swagger.yaml#/parameters/per_page"
36
      - $ref: "../swagger.yaml#/parameters/q_param"
37
      - $ref: "../swagger.yaml#/parameters/q_body"
38
      - $ref: "../swagger.yaml#/parameters/q_header"
39
      - name: x-koha-embed
40
        in: header
41
        required: false
42
        description: Embed list sent as a request header
43
        type: array
44
        items:
45
          type: string
46
          enum:
47
            - biblio
48
            - item
49
            - patron
50
        collectionFormat: csv
51
    produces:
52
      - application/json
53
    responses:
54
      200:
55
        description: A list of bookings
56
        schema:
57
          items:
58
            $ref: ../swagger.yaml#/definitions/booking
59
          type: array
60
      403:
61
        description: Access forbidden
62
        schema:
63
          $ref: ../swagger.yaml#/definitions/error
64
      500:
65
        description: Internal error
66
        schema:
67
          $ref: ../swagger.yaml#/definitions/error
68
      503:
69
        description: Under maintenance
70
        schema:
71
          $ref: ../swagger.yaml#/definitions/error
72
    summary: List bookings
73
    tags:
74
      - bookings
75
    x-koha-authorization:
76
      permissions:
77
        catalogue: 1
78
  post:
79
    operationId: addBooking
80
    parameters:
81
      - description: A JSON object containing informations about the new booking
82
        in: body
83
        name: body
84
        required: true
85
        schema:
86
          $ref: ../swagger.yaml#/definitions/booking
87
    produces:
88
      - application/json
89
    responses:
90
      201:
91
        description: Booking added
92
        schema:
93
          $ref: ../swagger.yaml#/definitions/booking
94
      400:
95
        description: Client error
96
        schema:
97
          $ref: ../swagger.yaml#/definitions/error
98
      401:
99
        description: Authentication required
100
        schema:
101
          $ref: ../swagger.yaml#/definitions/error
102
      403:
103
        description: Access forbidden
104
        schema:
105
          $ref: ../swagger.yaml#/definitions/error
106
      500:
107
        description: Internal error
108
        schema:
109
          $ref: ../swagger.yaml#/definitions/error
110
      503:
111
        description: Under maintenance
112
        schema:
113
          $ref: ../swagger.yaml#/definitions/error
114
    summary: Add booking
115
    tags:
116
      - bookings
117
    x-koha-authorization:
118
      permissions:
119
        parameters: manage_bookings
120
    x-mojo-to: Bookings#add
121
'/bookings/{booking_id}':
122
  delete:
123
    operationId: deleteBooking
124
    parameters:
125
      - $ref: "../swagger.yaml#/parameters/booking_id_pp"
126
    produces:
127
      - application/json
128
    responses:
129
      204:
130
        description: Booking deleted
131
      401:
132
        description: Authentication required
133
        schema:
134
          $ref: ../swagger.yaml#/definitions/error
135
      403:
136
        description: Access forbidden
137
        schema:
138
          $ref: ../swagger.yaml#/definitions/error
139
      404:
140
        description: Booking not found
141
        schema:
142
          $ref: ../swagger.yaml#/definitions/error
143
      500:
144
        description: Internal error
145
        schema:
146
          $ref: ../swagger.yaml#/definitions/error
147
      503:
148
        description: Under maintenance
149
        schema:
150
          $ref: ../swagger.yaml#/definitions/error
151
    summary: Delete booking
152
    tags:
153
      - bookings
154
    x-koha-authorization:
155
      permissions:
156
        parameters: manage_bookings
157
    x-mojo-to: Bookings#delete
158
  get:
159
    operationId: getBooking
160
    parameters:
161
      - $ref: "../swagger.yaml#/parameters/booking_id_pp"
162
    produces:
163
      - application/json
164
    responses:
165
      200:
166
        description: A booking
167
        schema:
168
          $ref: ../swagger.yaml#/definitions/booking
169
      404:
170
        description: Booking not found
171
        schema:
172
          $ref: ../swagger.yaml#/definitions/error
173
      500:
174
        description: Internal error
175
        schema:
176
          $ref: ../swagger.yaml#/definitions/error
177
      503:
178
        description: Under maintenance
179
        schema:
180
          $ref: ../swagger.yaml#/definitions/error
181
    summary: Get booking
182
    tags:
183
      - bookings
184
    x-koha-authorization:
185
      permissions:
186
        catalogue: 1
187
    x-mojo-to: Bookings#get
188
  put:
189
    operationId: updateBooking
190
    parameters:
191
      - $ref: "../swagger.yaml#/parameters/booking_id_pp"
192
      - description: A booking object
193
        in: body
194
        name: body
195
        required: true
196
        schema:
197
          $ref: ../swagger.yaml#/definitions/booking
198
    produces:
199
      - application/json
200
    responses:
201
      200:
202
        description: A booking
203
        schema:
204
          $ref: ../swagger.yaml#/definitions/booking
205
      400:
206
        description: Client error
207
        schema:
208
          $ref: ../swagger.yaml#/definitions/error
209
      401:
210
        description: Authentication required
211
        schema:
212
          $ref: ../swagger.yaml#/definitions/error
213
      403:
214
        description: Access forbidden
215
        schema:
216
          $ref: ../swagger.yaml#/definitions/error
217
      404:
218
        description: Booking not found
219
        schema:
220
          $ref: ../swagger.yaml#/definitions/error
221
      500:
222
        description: Internal error
223
        schema:
224
          $ref: ../swagger.yaml#/definitions/error
225
      503:
226
        description: Under maintenance
227
        schema:
228
          $ref: ../swagger.yaml#/definitions/error
229
    summary: Update booking
230
    tags:
231
      - bookings
232
    x-koha-authorization:
233
      permissions:
234
        parameters: manage_bookings
235
    x-mojo-to: Bookings#update
(-)a/api/v1/swagger/paths/items.yaml (+54 lines)
Lines 333-338 Link Here
333
    x-koha-authorization:
333
    x-koha-authorization:
334
      permissions:
334
      permissions:
335
        catalogue: 1
335
        catalogue: 1
336
/items/{item_id}/bookings:
337
  get:
338
    x-mojo-to: Items#bookings
339
    operationId: getItemBookings
340
    summary: Get existing bookings for an item
341
    tags:
342
      - items
343
    parameters:
344
      - $ref: "../swagger.yaml#/parameters/item_id_pp"
345
      - $ref: "../swagger.yaml#/parameters/match"
346
      - $ref: "../swagger.yaml#/parameters/order_by"
347
      - $ref: "../swagger.yaml#/parameters/page"
348
      - $ref: "../swagger.yaml#/parameters/per_page"
349
      - $ref: "../swagger.yaml#/parameters/q_param"
350
      - $ref: "../swagger.yaml#/parameters/q_body"
351
      - $ref: "../swagger.yaml#/parameters/q_header"
352
    consumes:
353
      - application/json
354
    produces:
355
      - application/json
356
    responses:
357
      "200":
358
        description: Item bookings
359
        schema:
360
          type: array
361
          items:
362
            $ref: ../swagger.yaml#/definitions/booking
363
      "400":
364
        description: Missing or wrong parameters
365
        schema:
366
          $ref: ../swagger.yaml#/definitions/error
367
      "401":
368
        description: Authentication required
369
        schema:
370
          $ref: ../swagger.yaml#/definitions/error
371
      "403":
372
        description: Access forbidden
373
        schema:
374
          $ref: ../swagger.yaml#/definitions/error
375
      "404":
376
        description: Item not found
377
        schema:
378
          $ref: ../swagger.yaml#/definitions/error
379
      "500":
380
        description: Internal server error
381
        schema:
382
          $ref: ../swagger.yaml#/definitions/error
383
      "503":
384
        description: Under maintenance
385
        schema:
386
          $ref: ../swagger.yaml#/definitions/error
387
    x-koha-authorization:
388
      permissions:
389
        circulation: 1
336
"/items/{item_id}/pickup_locations":
390
"/items/{item_id}/pickup_locations":
337
  get:
391
  get:
338
    x-mojo-to: Items#pickup_locations
392
    x-mojo-to: Items#pickup_locations
(-)a/api/v1/swagger/swagger.yaml (-16 / +31 lines)
Lines 13-23 definitions: Link Here
13
  authorised_value_category:
13
  authorised_value_category:
14
    $ref: ./definitions/authorised_value_category.yaml
14
    $ref: ./definitions/authorised_value_category.yaml
15
  identity_provider:
15
  identity_provider:
16
    "$ref": ./definitions/identity_provider.yaml
16
    $ref: ./definitions/identity_provider.yaml
17
  identity_provider_domain:
17
  identity_provider_domain:
18
    "$ref": ./definitions/identity_provider_domain.yaml
18
    $ref: ./definitions/identity_provider_domain.yaml
19
  basket:
19
  basket:
20
    $ref: ./definitions/basket.yaml
20
    $ref: ./definitions/basket.yaml
21
  booking:
22
    $ref: ./definitions/booking.yaml
21
  bundle_link:
23
  bundle_link:
22
    $ref: ./definitions/bundle_link.yaml
24
    $ref: ./definitions/bundle_link.yaml
23
  cashup:
25
  cashup:
Lines 110-122 definitions: Link Here
110
    $ref: ./definitions/vendor.yaml
112
    $ref: ./definitions/vendor.yaml
111
paths:
113
paths:
112
  /acquisitions/baskets/managers:
114
  /acquisitions/baskets/managers:
113
    $ref: paths/acquisitions_baskets.yaml#/~1acquisitions~1baskets~1managers
115
    $ref: ./paths/acquisitions_baskets.yaml#/~1acquisitions~1baskets~1managers
114
  /acquisitions/funds:
116
  /acquisitions/funds:
115
    $ref: ./paths/acquisitions_funds.yaml#/~1acquisitions~1funds
117
    $ref: ./paths/acquisitions_funds.yaml#/~1acquisitions~1funds
116
  /acquisitions/funds/owners:
118
  /acquisitions/funds/owners:
117
    $ref: paths/acquisitions_funds.yaml#/~1acquisitions~1funds~1owners
119
    $ref: ./paths/acquisitions_funds.yaml#/~1acquisitions~1funds~1owners
118
  /acquisitions/funds/users:
120
  /acquisitions/funds/users:
119
    $ref: paths/acquisitions_funds.yaml#/~1acquisitions~1funds~1users
121
    $ref: ./paths/acquisitions_funds.yaml#/~1acquisitions~1funds~1users
120
  /acquisitions/orders:
122
  /acquisitions/orders:
121
    $ref: ./paths/acquisitions_orders.yaml#/~1acquisitions~1orders
123
    $ref: ./paths/acquisitions_orders.yaml#/~1acquisitions~1orders
122
  "/acquisitions/orders/{order_id}":
124
  "/acquisitions/orders/{order_id}":
Lines 129-134 paths: Link Here
129
    $ref: ./paths/advancededitormacros.yaml#/~1advanced_editor~1macros
131
    $ref: ./paths/advancededitormacros.yaml#/~1advanced_editor~1macros
130
  /advanced_editor/macros/shared:
132
  /advanced_editor/macros/shared:
131
    $ref: ./paths/advancededitormacros.yaml#/~1advanced_editor~1macros~1shared
133
    $ref: ./paths/advancededitormacros.yaml#/~1advanced_editor~1macros~1shared
134
  /bookings:
135
    $ref: ./paths/bookings.yaml#/~1bookings
136
  "/bookings/{booking_id}":
137
    $ref: ./paths/bookings.yaml#/~1bookings~1{booking_id}
132
  /search_filters:
138
  /search_filters:
133
    $ref: ./paths/search_filters.yaml#/~1search_filters
139
    $ref: ./paths/search_filters.yaml#/~1search_filters
134
  "/search_filters/{search_filter_id}":
140
  "/search_filters/{search_filter_id}":
Lines 140-172 paths: Link Here
140
  "/article_requests/{article_request_id}":
146
  "/article_requests/{article_request_id}":
141
    $ref: "./paths/article_requests.yaml#/~1article_requests~1{article_request_id}"
147
    $ref: "./paths/article_requests.yaml#/~1article_requests~1{article_request_id}"
142
  /auth/otp/token_delivery:
148
  /auth/otp/token_delivery:
143
    $ref: paths/auth.yaml#/~1auth~1otp~1token_delivery
149
    $ref: "./paths/auth.yaml#/~1auth~1otp~1token_delivery"
144
  "/auth/password/validation":
150
  "/auth/password/validation":
145
    $ref: "./paths/auth.yaml#/~1auth~1password~1validation"
151
    $ref: "./paths/auth.yaml#/~1auth~1password~1validation"
146
  /auth/two-factor/registration:
152
  /auth/two-factor/registration:
147
    $ref: paths/auth.yaml#/~1auth~1two-factor~1registration
153
    $ref: ./paths/auth.yaml#/~1auth~1two-factor~1registration
148
  /auth/two-factor/registration/verification:
154
  /auth/two-factor/registration/verification:
149
    $ref: paths/auth.yaml#/~1auth~1two-factor~1registration~1verification
155
    $ref: ./paths/auth.yaml#/~1auth~1two-factor~1registration~1verification
150
  /auth/identity_providers:
156
  /auth/identity_providers:
151
    $ref: paths/auth.yaml#/~1auth~1identity_providers
157
    $ref: ./paths/auth.yaml#/~1auth~1identity_providers
152
  "/auth/identity_providers/{identity_provider_id}":
158
  "/auth/identity_providers/{identity_provider_id}":
153
    $ref: paths/auth.yaml#/~1auth~1identity_providers~1{identity_provider_id}
159
    $ref: ./paths/auth.yaml#/~1auth~1identity_providers~1{identity_provider_id}
154
  "/auth/identity_providers/{identity_provider_id}/domains":
160
  "/auth/identity_providers/{identity_provider_id}/domains":
155
    $ref: paths/auth.yaml#/~1auth~1identity_providers~1{identity_provider_id}~1domains
161
    $ref: ./paths/auth.yaml#/~1auth~1identity_providers~1{identity_provider_id}~1domains
156
  "/auth/identity_providers/{identity_provider_id}/domains/{identity_provider_domain_id}":
162
  "/auth/identity_providers/{identity_provider_id}/domains/{identity_provider_domain_id}":
157
    $ref: paths/auth.yaml#/~1auth~1identity_providers~1{identity_provider_id}~1domains~1{identity_provider_domain_id}
163
    $ref: ./paths/auth.yaml#/~1auth~1identity_providers~1{identity_provider_id}~1domains~1{identity_provider_domain_id}
158
  /authorised_value_categories:
164
  /authorised_value_categories:
159
    $ref: paths/authorised_value_categories.yaml#/~1authorised_value_categories
165
    $ref: ./paths/authorised_value_categories.yaml#/~1authorised_value_categories
160
  "/authorised_value_categories/{authorised_value_category_name}/authorised_values":
166
  "/authorised_value_categories/{authorised_value_category_name}/authorised_values":
161
    $ref: "./paths/authorised_values.yaml#/~1authorised_value_categories~1{authorised_value_category_name}~1authorised_values"
167
    $ref: "./paths/authorised_values.yaml#/~1authorised_value_categories~1{authorised_value_category_name}~1authorised_values"
162
  "/authorities":
168
  "/authorities":
163
    $ref: paths/authorities.yaml#/~1authorities
169
    $ref: paths/authorities.yaml#/~1authorities
164
  "/authorities/{authority_id}":
170
  "/authorities/{authority_id}":
165
    $ref: paths/authorities.yaml#/~1authorities~1{authority_id}
171
    $ref: "./paths/authorities.yaml#/~1authorities~1{authority_id}"
166
  "/biblios":
172
  "/biblios":
167
    $ref: "./paths/biblios.yaml#/~1biblios"
173
    $ref: "./paths/biblios.yaml#/~1biblios"
168
  "/biblios/{biblio_id}":
174
  "/biblios/{biblio_id}":
169
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}"
175
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}"
176
  "/biblios/{biblio_id}/bookings":
177
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}~1bookings"
170
  "/biblios/{biblio_id}/checkouts":
178
  "/biblios/{biblio_id}/checkouts":
171
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}~1checkouts"
179
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}~1checkouts"
172
  "/biblios/{biblio_id}/items":
180
  "/biblios/{biblio_id}/items":
Lines 267-272 paths: Link Here
267
    $ref: ./paths/items.yaml#/~1items
275
    $ref: ./paths/items.yaml#/~1items
268
  "/items/{item_id}":
276
  "/items/{item_id}":
269
    $ref: "./paths/items.yaml#/~1items~1{item_id}"
277
    $ref: "./paths/items.yaml#/~1items~1{item_id}"
278
  "/items/{item_id}/bookings":
279
    $ref: "./paths/items.yaml#/~1items~1{item_id}~1bookings"
270
  "/items/{item_id}/bundled_items":
280
  "/items/{item_id}/bundled_items":
271
    $ref: ./paths/items.yaml#/~1items~1{item_id}~1bundled_items
281
    $ref: ./paths/items.yaml#/~1items~1{item_id}~1bundled_items
272
  "/items/{item_id}/bundled_items/{bundled_item_id}":
282
  "/items/{item_id}/bundled_items/{bundled_item_id}":
Lines 346-352 paths: Link Here
346
  "/suggestions/{suggestion_id}":
356
  "/suggestions/{suggestion_id}":
347
    $ref: "./paths/suggestions.yaml#/~1suggestions~1{suggestion_id}"
357
    $ref: "./paths/suggestions.yaml#/~1suggestions~1{suggestion_id}"
348
  /suggestions/managers:
358
  /suggestions/managers:
349
    $ref: paths/suggestions.yaml#/~1suggestions~1managers
359
    $ref: "./paths/suggestions.yaml#/~1suggestions~1managers"
350
  "/tickets":
360
  "/tickets":
351
    $ref: "./paths/tickets.yaml#/~1tickets"
361
    $ref: "./paths/tickets.yaml#/~1tickets"
352
  "/tickets/{ticket_id}":
362
  "/tickets/{ticket_id}":
Lines 396-401 parameters: Link Here
396
    in: header
406
    in: header
397
    required: false
407
    required: false
398
    type: string
408
    type: string
409
  booking_id_pp:
410
    description: Booking identifier
411
    in: path
412
    name: booking_id
413
    required: true
414
    type: integer
399
  framework_id_header:
415
  framework_id_header:
400
    description: Framework id. Use when content type is not application/json
416
    description: Framework id. Use when content type is not application/json
401
    name: x-framework-id
417
    name: x-framework-id
402
- 

Return to bug 29002