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

(-)a/Koha/REST/V1/Items.pm (+60 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Mojo::Base 'Mojolicious::Controller';
20
use Mojo::Base 'Mojolicious::Controller';
21
21
22
use Koha::Items;
22
use Koha::Items;
23
use Koha::DateUtils qw( dt_from_string output_pref );
24
25
use C4::Letters qw(GetPreparedLetter);
23
26
24
use List::MoreUtils qw( any );
27
use List::MoreUtils qw( any );
25
use Try::Tiny qw( catch try );
28
use Try::Tiny qw( catch try );
Lines 273-276 sub remove_from_bundle { Link Here
273
    );
276
    );
274
}
277
}
275
278
279
=head3 print_slip
280
281
Controller function that handles constructing and returning the contents for a print slip for this item
282
283
=cut
284
285
sub print_slip {
286
    my $c = shift->openapi->valid_input or return;
287
288
    my $item_id = $c->validation->param('item_id');
289
    my $item = Koha::Items->find( $item_id );
290
291
    unless ($item) {
292
        return $c->render(
293
            status  => 404,
294
            openapi => { error => "Item not found" }
295
        );
296
    }
297
298
    my $print_slip_id = $c->validation->param('slip_id');
299
300
    #FIXME: This should come from the session
301
    my $user       = $c->stash('koha.user');
302
    my $branchcode = $user->branchcode;
303
    my $lang       = $user->lang;
304
305
    my $slip = C4::Letters::GetPreparedLetter(
306
        module                 => 'circulation',
307
        letter_code            => $print_slip_id,
308
        branchcode             => $branchcode,
309
        message_transport_type => 'print',
310
        #lang                  => $lang,
311
        tables                 => {
312
            items => $item_id
313
        }
314
    );
315
316
    unless ($slip) {
317
        return $c->render(
318
            status  => 404,
319
            openapi => { error => "Slip not found" }
320
        );
321
    }
322
323
    return $c->render(
324
        status  => 200,
325
        openapi => {
326
            timestamp => output_pref(
327
                { dt => dt_from_string(), dateformat => 'rfc3339' }
328
            ),
329
            slip_id => $print_slip_id,
330
            content => $slip->{content},
331
            title   => $slip->{title}
332
        }
333
    );
334
}
335
276
1;
336
1;
(-)a/api/v1/swagger/definitions.json (+3 lines)
Lines 89-94 Link Here
89
  "return_claim": {
89
  "return_claim": {
90
    "$ref": "definitions/return_claim.json"
90
    "$ref": "definitions/return_claim.json"
91
  },
91
  },
92
  "slip": {
93
    "$ref": "definitions/slip.yaml"
94
  },
92
  "smtp_server": {
95
  "smtp_server": {
93
    "$ref": "definitions/smtp_server.json"
96
    "$ref": "definitions/smtp_server.json"
94
  },
97
  },
(-)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.json (+3 lines)
Lines 89-94 Link Here
89
  "/items/{item_id}": {
89
  "/items/{item_id}": {
90
    "$ref": "paths/items.yaml#/~1items~1{item_id}"
90
    "$ref": "paths/items.yaml#/~1items~1{item_id}"
91
  },
91
  },
92
  "/items/{item_id}/print_slips/{slip_id}": {
93
      "$ref": "paths/items.yaml#/~1items~1{item_id}~1print_slips~1{slip_id}"
94
  },
92
  "/items/{item_id}/bundled_items": {
95
  "/items/{item_id}/bundled_items": {
93
    "$ref": "paths/items.yaml#/~1items~1{item_id}~1bundled_items"
96
    "$ref": "paths/items.yaml#/~1items~1{item_id}~1bundled_items"
94
  },
97
  },
(-)a/api/v1/swagger/paths/items.yaml (-1 / +40 lines)
Lines 303-308 Link Here
303
    x-koha-authorization:
303
    x-koha-authorization:
304
      permissions:
304
      permissions:
305
        reserveforothers: place_holds
305
        reserveforothers: place_holds
306
/items/{item_id}/print_slips/{slip_id}:
307
  get:
308
    x-mojo-to: Items#print_slip
309
    operationId: printSlipItems
310
    tags:
311
      - items
312
    summary: Print slip for item as defined in notices and slips
313
    parameters:
314
      - $ref: ../parameters.json#/item_id_pp
315
      - name: slip_id
316
        in: path
317
        description: The required slip letter code identifier
318
        required: true
319
        type: string
320
    produces:
321
      - application/json
322
    responses:
323
      "200":
324
        description: A slip object
325
        schema:
326
          $ref: ../definitions.json#/slip
327
      "401":
328
        description: Authentication required
329
        schema:
330
          $ref: ../definitions.json#/error
331
      "403":
332
        description: Access forbidden
333
        schema:
334
          $ref: ../definitions.json#/error
335
      "500":
336
        description: Internal server error
337
        schema:
338
          $ref: ../definitions.json#/error
339
      "503":
340
        description: Under maintenance
341
        schema:
342
          $ref: ../definitions.json#/error
343
    x-koha-authorization:
344
      permissions:
345
        catalogue: "1"
306
/public/items/{item_id}/bundled_items:
346
/public/items/{item_id}/bundled_items:
307
  get:
347
  get:
308
    x-mojo-to: Items#bundled_items
348
    x-mojo-to: Items#bundled_items
309
- 

Return to bug 29566