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

(-)a/Koha/REST/V1/Items.pm (+60 lines)
Lines 22-27 use Mojo::Base 'Mojolicious::Controller'; Link Here
22
use C4::Circulation qw( barcodedecode );
22
use C4::Circulation qw( barcodedecode );
23
23
24
use Koha::Items;
24
use Koha::Items;
25
use Koha::DateUtils qw( dt_from_string output_pref );
26
27
use C4::Letters qw(GetPreparedLetter);
25
28
26
use List::MoreUtils qw( any );
29
use List::MoreUtils qw( any );
27
use Try::Tiny qw( catch try );
30
use Try::Tiny qw( catch try );
Lines 272-275 sub remove_from_bundle { Link Here
272
    );
275
    );
273
}
276
}
274
277
278
=head3 print_slip
279
280
Controller function that handles constructing and returning the contents for a print slip for this item
281
282
=cut
283
284
sub print_slip {
285
    my $c = shift->openapi->valid_input or return;
286
287
    my $item_id = $c->validation->param('item_id');
288
    my $item = Koha::Items->find( $item_id );
289
290
    unless ($item) {
291
        return $c->render(
292
            status  => 404,
293
            openapi => { error => "Item not found" }
294
        );
295
    }
296
297
    my $print_slip_id = $c->validation->param('slip_id');
298
299
    #FIXME: This should come from the session
300
    my $user       = $c->stash('koha.user');
301
    my $branchcode = $user->branchcode;
302
    my $lang       = $user->lang;
303
304
    my $slip = C4::Letters::GetPreparedLetter(
305
        module                 => 'circulation',
306
        letter_code            => $print_slip_id,
307
        branchcode             => $branchcode,
308
        message_transport_type => 'print',
309
        #lang                  => $lang,
310
        tables                 => {
311
            items => $item_id
312
        }
313
    );
314
315
    unless ($slip) {
316
        return $c->render(
317
            status  => 404,
318
            openapi => { error => "Slip not found" }
319
        );
320
    }
321
322
    return $c->render(
323
        status  => 200,
324
        openapi => {
325
            timestamp => output_pref(
326
                { dt => dt_from_string(), dateformat => 'rfc3339' }
327
            ),
328
            slip_id => $print_slip_id,
329
            content => $slip->{content},
330
            title   => $slip->{title}
331
        }
332
    );
333
}
334
275
1;
335
1;
(-)a/api/v1/swagger/definitions/slip.yaml (+18 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  slip_id:
5
    type: string
6
    readOnly: true
7
    description: unique identifier code for the slip template
8
  content:
9
    type: string
10
    description: Raw string content of the generated slip
11
  title:
12
    type: string
13
    description: Raw string title of generated slip
14
  timestamp:
15
    type: string
16
    format: date-time
17
    description: timestamp of date the slip content was generated
18
additionalProperties: false
(-)a/api/v1/swagger/paths/items.yaml (+91 lines)
Lines 316-318 Link Here
316
    x-koha-authorization:
316
    x-koha-authorization:
317
      permissions:
317
      permissions:
318
        reserveforothers: place_holds
318
        reserveforothers: place_holds
319
/items/{item_id}/print_slips/{slip_id}:
320
  get:
321
    x-mojo-to: Items#print_slip
322
    operationId: printSlipItems
323
    tags:
324
      - items
325
    summary: Print slip for item as defined in notices and slips
326
    parameters:
327
      - $ref: ../swagger.yaml#/parameters#/item_id_pp
328
      - name: slip_id
329
        in: path
330
        description: The required slip letter code identifier
331
        required: true
332
        type: string
333
    produces:
334
      - application/json
335
    responses:
336
      "200":
337
        description: A slip object
338
        schema:
339
          $ref: ../swagger.yaml#/definitions#/slip
340
      "401":
341
        description: Authentication required
342
        schema:
343
          $ref: ../swagger.yaml#/definitions#/error
344
      "403":
345
        description: Access forbidden
346
        schema:
347
          $ref: ../swagger.yaml#/definitions#/error
348
      "500":
349
        description: Internal server error
350
        schema:
351
          $ref: ../swagger.yaml#/definitions#/error
352
      "503":
353
        description: Under maintenance
354
        schema:
355
          $ref: ../swagger.yaml#/definitions#/error
356
    x-koha-authorization:
357
      permissions:
358
        catalogue: "1"
359
/public/items/{item_id}/bundled_items:
360
  get:
361
    x-mojo-to: Items#bundled_items
362
    operationId: bundledItemsPublic
363
    tags:
364
      - items
365
    summary: List bundled items
366
    parameters:
367
      - $ref: ../swagger.yaml#/parameters#/item_id_pp
368
      - name: external_id
369
        in: query
370
        description: Search on the item's barcode
371
        required: false
372
        type: string
373
      - $ref: ../swagger.yaml#/parameters#/match
374
      - $ref: ../swagger.yaml#/parameters#/order_by
375
      - $ref: ../swagger.yaml#/parameters#/page
376
      - $ref: ../swagger.yaml#/parameters#/per_page
377
      - $ref: ../swagger.yaml#/parameters#/q_param
378
      - $ref: ../swagger.yaml#/parameters#/q_body
379
      - $ref: ../swagger.yaml#/parameters#/q_header
380
    consumes:
381
      - application/json
382
    produces:
383
      - application/json
384
    responses:
385
      "200":
386
        description: A list of item
387
        schema:
388
          type: array
389
          items:
390
            $ref: ../swagger.yaml#/definitions#/item
391
      "401":
392
        description: Authentication required
393
        schema:
394
          $ref: ../swagger.yaml#/definitions#/error
395
      "403":
396
        description: Access forbidden
397
        schema:
398
          $ref: ../swagger.yaml#/definitions#/error
399
      "500":
400
        description: Internal server error
401
        schema:
402
          $ref: ../swagger.yaml#/definitions#/error
403
      "503":
404
        description: Under maintenance
405
        schema:
406
          $ref: ../swagger.yaml#/definitions#/error
407
    x-koha-embed:
408
      - biblio
409
      - checkout
(-)a/api/v1/swagger/swagger.yaml (-1 / +4 lines)
Lines 66-71 definitions: Link Here
66
    $ref: ./definitions/renewals.yaml
66
    $ref: ./definitions/renewals.yaml
67
  return_claim:
67
  return_claim:
68
    $ref: ./definitions/return_claim.yaml
68
    $ref: ./definitions/return_claim.yaml
69
  slip:
70
    $ref: ./definitions/slip.yaml
69
  smtp_server:
71
  smtp_server:
70
    $ref: ./definitions/smtp_server.yaml
72
    $ref: ./definitions/smtp_server.yaml
71
  suggestion:
73
  suggestion:
Lines 177-182 paths: Link Here
177
    $ref: ./paths/items.yaml#/~1items~1{item_id}~1bundled_items~1{bundled_item_id}
179
    $ref: ./paths/items.yaml#/~1items~1{item_id}~1bundled_items~1{bundled_item_id}
178
  "/items/{item_id}/pickup_locations":
180
  "/items/{item_id}/pickup_locations":
179
    $ref: "./paths/items.yaml#/~1items~1{item_id}~1pickup_locations"
181
    $ref: "./paths/items.yaml#/~1items~1{item_id}~1pickup_locations"
182
  "/items/{item_id}/print_slips/{slip_id}":
183
    $ref: "./paths/items.yaml#/~1items~1{item_id}~1print_slips~1{slip_id}"
180
  /libraries:
184
  /libraries:
181
    $ref: ./paths/libraries.yaml#/~1libraries
185
    $ref: ./paths/libraries.yaml#/~1libraries
182
  "/libraries/{library_id}":
186
  "/libraries/{library_id}":
183
- 

Return to bug 29566