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

(-)a/Koha/Acquisition/Basket.pm (+1 lines)
Lines 309-314 sub to_api_mapping { Link Here
309
    return {
309
    return {
310
        basketno                => 'basket_id',
310
        basketno                => 'basket_id',
311
        basketname              => 'name',
311
        basketname              => 'name',
312
        note                    => 'internal_note',
312
        booksellernote          => 'vendor_note',
313
        booksellernote          => 'vendor_note',
313
        contractnumber          => 'contract_id',
314
        contractnumber          => 'contract_id',
314
        creationdate            => 'creation_date',
315
        creationdate            => 'creation_date',
(-)a/Koha/REST/V1/Acquisitions/Baskets.pm (-1 / +29 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use Mojo::Base 'Mojolicious::Controller';
20
use Mojo::Base 'Mojolicious::Controller';
21
21
22
use Try::Tiny qw( catch try );
22
use Koha::Acquisition::Baskets;
23
24
use Clone        qw( clone );
25
use Scalar::Util qw( blessed );
26
use Try::Tiny    qw( catch try );
23
27
24
=head1 NAME
28
=head1 NAME
25
29
Lines 29-34 Koha::REST::V1::Acquisitions::Baskets Link Here
29
33
30
=head2 Class methods
34
=head2 Class methods
31
35
36
=head3 add
37
38
Controller function that handles adding a new Koha::Acquisition::Basket object
39
40
=cut
41
42
sub add {
43
    my $c = shift->openapi->valid_input or return;
44
45
    return try {
46
        my $basket = Koha::Acquisition::Basket->new_from_api( $c->validation->param('body') );
47
        $basket->store->discard_changes;
48
49
        $c->res->headers->location( $c->req->url->to_string . '/' . $basket->basketno );
50
51
        return $c->render(
52
            status  => 201,
53
            openapi => $basket->to_api
54
        );
55
    } catch {
56
        $c->unhandled_exception($_);
57
    };
58
}
59
32
=head3 list
60
=head3 list
33
61
34
Controller function that handles baskets
62
Controller function that handles baskets
(-)a/api/v1/swagger/definitions/basket.yaml (-6 / +5 lines)
Lines 5-11 properties: Link Here
5
    type: integer
5
    type: integer
6
    description: Internal identifier for the basket
6
    description: Internal identifier for the basket
7
  name:
7
  name:
8
    type: string
8
    type:
9
      - string
10
      - "null"
9
    description: Basket name
11
    description: Basket name
10
  internal_note:
12
  internal_note:
11
    type:
13
    type:
Lines 68-78 properties: Link Here
68
  closed:
70
  closed:
69
    type: boolean
71
    type: boolean
70
    description: Is the basket closed
72
    description: Is the basket closed
71
  note:
72
    type:
73
      - string
74
      - "null"
75
    description: basket notes
76
  create_items:
73
  create_items:
77
    type:
74
    type:
78
      - string
75
      - string
Lines 90-92 properties: Link Here
90
      - "null"
87
      - "null"
91
    description: The number of days the basket is late (x-koha-embed)
88
    description: The number of days the basket is late (x-koha-embed)
92
additionalProperties: false
89
additionalProperties: false
90
required:
91
  - vendor_id
(-)a/api/v1/swagger/paths/acquisitions_baskets.yaml (+58 lines)
Lines 60-65 Link Here
60
    x-koha-authorization:
60
    x-koha-authorization:
61
      permissions:
61
      permissions:
62
        acquisition: order_manage
62
        acquisition: order_manage
63
  post:
64
    x-mojo-to: Acquisitions::Baskets#add
65
    operationId: addBasket
66
    tags:
67
      - baskets
68
    summary: Add basket
69
    consumes:
70
      - application/json
71
    produces:
72
      - application/json
73
    parameters:
74
      - name: body
75
        in: body
76
        description: A basket
77
        required: true
78
        schema:
79
          $ref: "../swagger.yaml#/definitions/basket"
80
    responses:
81
      "201":
82
        description: A successfully created basket
83
        schema:
84
          items:
85
            $ref: "../swagger.yaml#/definitions/basket"
86
      "400":
87
        description: Bad request
88
        schema:
89
          $ref: "../swagger.yaml#/definitions/error"
90
      "401":
91
        description: Authentication required
92
        schema:
93
          $ref: "../swagger.yaml#/definitions/error"
94
      "403":
95
        description: Access forbidden
96
        schema:
97
          $ref: "../swagger.yaml#/definitions/error"
98
      "404":
99
        description: Resource not found
100
        schema:
101
          $ref: "../swagger.yaml#/definitions/error"
102
      "409":
103
        description: Conflict in creating resource
104
        schema:
105
          $ref: "../swagger.yaml#/definitions/error"
106
      "500":
107
        description: |
108
          Internal server error. Possible `error_code` attribute values:
109
110
          * `internal_server_error`
111
        schema:
112
          $ref: "../swagger.yaml#/definitions/error"
113
      "503":
114
        description: Under maintenance
115
        schema:
116
          $ref: "../swagger.yaml#/definitions/error"
117
    x-koha-authorization:
118
      permissions:
119
        acquisition:
120
          - order_manage
63
/acquisitions/baskets/managers:
121
/acquisitions/baskets/managers:
64
  get:
122
  get:
65
    x-mojo-to: Acquisitions::Baskets#list_managers
123
    x-mojo-to: Acquisitions::Baskets#list_managers
(-)a/t/db_dependent/api/v1/acquisitions_baskets/post.t (-1 / +63 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 14;
6
use Test::Mojo;
7
8
use t::lib::Mocks;
9
use t::lib::TestBuilder;
10
11
use Koha::Database;
12
13
my $schema  = Koha::Database->new->schema;
14
my $builder = t::lib::TestBuilder->new;
15
16
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
17
18
my $t = Test::Mojo->new('Koha::REST::V1');
19
20
$schema->storage->txn_begin;
21
22
my $bookseller = $builder->build_object(
23
    {
24
        class => 'Koha::Acquisition::Booksellers',
25
    }
26
);
27
my $patron = $builder->build_object(
28
    {
29
        class => 'Koha::Patrons',
30
        value => { flags => 0 }
31
    }
32
);
33
my $password = 'thePassword123';
34
$patron->set_password( { password => $password, skip_validation => 1 } );
35
my $userid = $patron->userid;
36
37
my $url = "//$userid:$password@/api/v1/acquisitions/baskets";
38
39
$t->post_ok( $url, json => {} )->status_is(403);
40
41
$schema->resultset('UserPermission')->create(
42
    {
43
        borrowernumber => $patron->borrowernumber,
44
        module_bit     => 11,
45
        code           => 'order_manage',
46
    }
47
);
48
49
$t->post_ok( $url, json => {} )->status_is(400);
50
51
$t->post_ok( $url, json => { vendor_id => $bookseller->id } )->status_is(201)->json_has('/basket_id')
52
    ->json_is( '/vendor_id', $bookseller->id );
53
54
my $basket = {
55
    vendor_id   => $bookseller->id,
56
    name        => 'Basket #1',
57
    vendor_note => 'Vendor note',
58
};
59
$t->post_ok( $url, json => $basket )->status_is(201)->json_has('/basket_id')
60
    ->json_is( '/vendor_id',   $basket->{vendor_id} )->json_is( '/name', $basket->{name} )
61
    ->json_is( '/vendor_note', $basket->{vendor_note} );
62
63
$schema->storage->txn_rollback;

Return to bug 29668