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

(-)a/Koha/REST/V1/Biblios.pm (+72 lines)
Lines 23-28 use Koha::Biblios; Link Here
23
use Koha::RecordProcessor;
23
use Koha::RecordProcessor;
24
use C4::Biblio qw(DelBiblio);
24
use C4::Biblio qw(DelBiblio);
25
25
26
use List::MoreUtils qw(any);
26
use MARC::Record::MiJ;
27
use MARC::Record::MiJ;
27
28
28
use Try::Tiny;
29
use Try::Tiny;
Lines 268-271 sub get_items { Link Here
268
    };
269
    };
269
}
270
}
270
271
272
=head3 pickup_locations
273
274
Method that returns the possible pickup_locations for a given biblio
275
used for building the dropdown selector
276
277
=cut
278
279
sub pickup_locations {
280
    my $c = shift->openapi->valid_input or return;
281
282
    my $biblio_id = $c->validation->param('biblio_id');
283
    my $biblio = Koha::Biblios->find( $biblio_id );
284
285
    unless ($biblio) {
286
        return $c->render(
287
            status  => 404,
288
            openapi => { error => "Biblio not found" }
289
        );
290
    }
291
292
    my $patron_id = delete $c->validation->output->{patron_id};
293
    my $patron    = Koha::Patrons->find( $patron_id );
294
295
    unless ($patron) {
296
        return $c->render(
297
            status  => 400,
298
            openapi => { error => "Patron not found" }
299
        );
300
    }
301
302
    return try {
303
304
        my $ps_set = $biblio->pickup_locations( { patron => $patron } );
305
306
        my $pickup_locations = $c->objects->search( $ps_set );
307
        my @response = ();
308
309
        if ( C4::Context->preference('AllowHoldPolicyOverride') ) {
310
311
            my $libraries_rs = Koha::Libraries->search( { pickup_location => 1 } );
312
            my $libraries    = $c->objects->search($libraries_rs);
313
314
            @response = map {
315
                my $library = $_;
316
                $library->{needs_override} = (
317
                    any { $_->{library_id} eq $library->{library_id} }
318
                    @{$pickup_locations}
319
                  )
320
                  ? Mojo::JSON->false
321
                  : Mojo::JSON->true;
322
                $library;
323
            } @{$libraries};
324
325
            return $c->render(
326
                status  => 200,
327
                openapi => \@response
328
            );
329
        }
330
331
        @response = map { $_->{needs_override} = Mojo::JSON->false; $_; } @{$pickup_locations};
332
333
        return $c->render(
334
            status  => 200,
335
            openapi => \@response
336
        );
337
    }
338
    catch {
339
        $c->unhandled_exception($_);
340
    };
341
}
342
271
1;
343
1;
(-)a/api/v1/swagger/paths.json (+3 lines)
Lines 23-28 Link Here
23
  "/biblios/{biblio_id}/items": {
23
  "/biblios/{biblio_id}/items": {
24
    "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}~1items"
24
    "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}~1items"
25
  },
25
  },
26
  "/biblios/{biblio_id}/pickup_locations": {
27
    "$ref": "paths/biblios.json#/~1biblios~1{biblio_id}~1pickup_locations"
28
  },
26
  "/cash_registers/{cash_register_id}/cashups": {
29
  "/cash_registers/{cash_register_id}/cashups": {
27
    "$ref": "paths/cash_registers.json#/~1cash_registers~1{cash_register_id}~1cashups"
30
    "$ref": "paths/cash_registers.json#/~1cash_registers~1{cash_register_id}~1cashups"
28
  },
31
  },
(-)a/api/v1/swagger/paths/biblios.json (-1 / +101 lines)
Lines 232-237 Link Here
232
      }
232
      }
233
    }
233
    }
234
  },
234
  },
235
  "/biblios/{biblio_id}/pickup_locations": {
236
    "get": {
237
      "x-mojo-to": "Biblios#pickup_locations",
238
      "operationId": "getBiblioPickupLocations",
239
      "tags": [
240
        "biblios",
241
        "pickup_locations"
242
      ],
243
      "parameters": [
244
        {
245
          "$ref": "../parameters.json#/biblio_id_pp"
246
        },
247
        {
248
          "name": "patron_id",
249
          "in": "query",
250
          "description": "Internal patron identifier",
251
          "required": true,
252
          "type": "integer"
253
        },
254
        {
255
          "$ref": "../parameters.json#/match"
256
        },
257
        {
258
          "$ref": "../parameters.json#/order_by"
259
        },
260
        {
261
          "$ref": "../parameters.json#/page"
262
        },
263
        {
264
          "$ref": "../parameters.json#/per_page"
265
        },
266
        {
267
          "$ref": "../parameters.json#/q_param"
268
        },
269
        {
270
          "$ref": "../parameters.json#/q_body"
271
        },
272
        {
273
          "$ref": "../parameters.json#/q_header"
274
        }
275
      ],
276
      "consumes": [
277
        "application/json"
278
      ],
279
      "produces": [
280
        "application/json"
281
      ],
282
      "responses": {
283
        "200": {
284
          "description": "Biblio pickup locations",
285
          "schema": {
286
            "type": "array",
287
            "items": {
288
              "$ref": "../definitions.json#/library"
289
            }
290
          }
291
        },
292
        "400": {
293
          "description": "Missing or wrong parameters",
294
          "schema": {
295
            "$ref": "../definitions.json#/error"
296
          }
297
        },
298
        "401": {
299
          "description": "Authentication required",
300
          "schema": {
301
            "$ref": "../definitions.json#/error"
302
          }
303
        },
304
        "403": {
305
          "description": "Access forbidden",
306
          "schema": {
307
            "$ref": "../definitions.json#/error"
308
          }
309
        },
310
        "404": {
311
          "description": "Biblio not found",
312
          "schema": {
313
            "$ref": "../definitions.json#/error"
314
          }
315
        },
316
        "500": {
317
          "description": "Internal server error",
318
          "schema": {
319
            "$ref": "../definitions.json#/error"
320
          }
321
        },
322
        "503": {
323
          "description": "Under maintenance",
324
          "schema": {
325
            "$ref": "../definitions.json#/error"
326
          }
327
        }
328
      },
329
      "x-koha-authorization": {
330
        "permissions": {
331
          "reserveforothers": "place_holds"
332
        }
333
      }
334
    }
335
  },
235
  "/public/biblios/{biblio_id}": {
336
  "/public/biblios/{biblio_id}": {
236
    "get": {
337
    "get": {
237
      "x-mojo-to": "Biblios#get_public",
338
      "x-mojo-to": "Biblios#get_public",
238
- 

Return to bug 27932