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

(-)a/Koha/Acquisition/Basket.pm (+1 lines)
Lines 270-275 sub to_api_mapping { Link Here
270
    return {
270
    return {
271
        basketno                => 'basket_id',
271
        basketno                => 'basket_id',
272
        basketname              => 'name',
272
        basketname              => 'name',
273
        note                    => undef,
273
        booksellernote          => 'vendor_note',
274
        booksellernote          => 'vendor_note',
274
        contractnumber          => 'contract_id',
275
        contractnumber          => 'contract_id',
275
        creationdate            => 'creation_date',
276
        creationdate            => 'creation_date',
(-)a/Koha/REST/V1/Acquisitions/Baskets.pm (+62 lines)
Line 0 Link Here
1
package Koha::REST::V1::Acquisitions::Baskets;
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::Acquisition::Baskets;
23
24
use Clone qw( clone );
25
use Scalar::Util qw( blessed );
26
use Try::Tiny qw( catch try );
27
28
=head1 NAME
29
30
Koha::REST::V1::Acquisitions::Baskets
31
32
=head1 API
33
34
=head2 Methods
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(
50
            $c->req->url->to_string . '/' . $basket->basketno
51
        );
52
53
        return $c->render(
54
            status  => 201,
55
            openapi => $basket->to_api
56
        );
57
    } catch {
58
        $c->unhandled_exception($_);
59
    };
60
}
61
62
1;
(-)a/api/v1/swagger/definitions/basket.yaml (-6 / +18 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 18-24 properties: Link Here
18
      - "null"
20
      - "null"
19
    description: Vendor note
21
    description: Vendor note
20
  contract_id:
22
  contract_id:
21
    type: integer
23
    type:
24
      - integer
25
      - "null"
22
    description: Internal identifier of the linked contract
26
    description: Internal identifier of the linked contract
23
  creation_date:
27
  creation_date:
24
    type:
28
    type:
Lines 32-41 properties: Link Here
32
      - "null"
36
      - "null"
33
    format: date
37
    format: date
34
    description: The date the basket was closed
38
    description: The date the basket was closed
39
  closed:
40
    type: boolean
41
    description: Is the basket closed ?
35
  vendor_id:
42
  vendor_id:
36
    type: integer
43
    type: integer
37
    description: Internal identifier for the vendor
44
    description: Internal identifier for the vendor
38
  authorised_by:
45
  creator_id:
39
    type:
46
    type:
40
      - integer
47
      - integer
41
      - "null"
48
      - "null"
Lines 45-56 properties: Link Here
45
      - integer
52
      - integer
46
      - "null"
53
      - "null"
47
    description: links this basket to its group (aqbasketgroups.id)
54
    description: links this basket to its group (aqbasketgroups.id)
48
  delivery_library:
55
  delivery_library_id:
49
    type:
56
    type:
50
      - string
57
      - string
51
      - "null"
58
      - "null"
52
    description: basket delivery place
59
    description: basket delivery place
53
  billing_library:
60
  billing_library_id:
54
    type:
61
    type:
55
      - string
62
      - string
56
      - "null"
63
      - "null"
Lines 64-74 properties: Link Here
64
    type: boolean
71
    type: boolean
65
    description: If the orders in this basket are standing
72
    description: If the orders in this basket are standing
66
  create_items:
73
  create_items:
67
    type: string
74
    type:
75
      - string
76
      - "null"
68
    enum:
77
    enum:
69
      - ordering
78
      - ordering
70
      - receiving
79
      - receiving
71
      - cataloguing
80
      - cataloguing
81
      - null
72
    description: "When items should be created for orders in this basket (Options:
82
    description: "When items should be created for orders in this basket (Options:
73
      'ordering', 'receiving', 'cataloguing'. Null means system wide config)"
83
      'ordering', 'receiving', 'cataloguing'. Null means system wide config)"
74
additionalProperties: false
84
additionalProperties: false
85
required:
86
  - vendor_id
(-)a/api/v1/swagger/paths.yaml (+2 lines)
Lines 1-6 Link Here
1
---
1
---
2
/oauth/token:
2
/oauth/token:
3
  $ref: paths/oauth.yaml#/~1oauth~1token
3
  $ref: paths/oauth.yaml#/~1oauth~1token
4
"/acquisitions/baskets":
5
  $ref: paths/acquisitions_baskets.yaml#/~1acquisitions~1baskets
4
/acquisitions/orders:
6
/acquisitions/orders:
5
  $ref: paths/acquisitions_orders.yaml#/~1acquisitions~1orders
7
  $ref: paths/acquisitions_orders.yaml#/~1acquisitions~1orders
6
"/acquisitions/orders/{order_id}":
8
"/acquisitions/orders/{order_id}":
(-)a/api/v1/swagger/paths/acquisitions_baskets.yaml (+45 lines)
Line 0 Link Here
1
---
2
"/acquisitions/baskets":
3
  post:
4
    x-mojo-to: Acquisitions::Baskets#add
5
    operationId: addBasket
6
    tags:
7
      - baskets
8
    summary: Add basket
9
    consumes:
10
      - application/json
11
    produces:
12
      - application/json
13
    parameters:
14
      -
15
        name: body
16
        in: body
17
        description: A basket
18
        required: true
19
        schema:
20
          $ref: ../definitions.yaml#/basket
21
    responses:
22
      "201":
23
        description: Basket created
24
        schema:
25
          $ref: ../definitions.yaml#/basket
26
      "401":
27
        description: Authentication required
28
        schema:
29
          $ref: ../definitions.yaml#/error
30
      "403":
31
        description: Access forbidden
32
        schema:
33
          $ref: ../definitions.yaml#/error
34
      "500":
35
        description: Internal server error
36
        schema:
37
          $ref: ../definitions.yaml#/error
38
      "503":
39
        description: Under maintenance
40
        schema:
41
          $ref: ../definitions.yaml#/error
42
    x-koha-authorization:
43
      permissions:
44
        acquisition:
45
          - order_manage
(-)a/t/db_dependent/api/v1/acquisitions_baskets/post.t (-1 / +68 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
my $schema  = Koha::Database->new->schema;
12
my $builder = t::lib::TestBuilder->new;
13
14
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
15
16
my $t = Test::Mojo->new('Koha::REST::V1');
17
18
$schema->storage->txn_begin;
19
20
my $bookseller = $builder->build_object(
21
    {
22
        class => 'Koha::Acquisition::Booksellers',
23
    }
24
);
25
my $patron = $builder->build_object(
26
    {
27
        class => 'Koha::Patrons',
28
        value => { flags => 0 }
29
    }
30
);
31
my $password = 'thePassword123';
32
$patron->set_password( { password => $password, skip_validation => 1 } );
33
my $userid = $patron->userid;
34
35
my $url = "//$userid:$password@/api/v1/acquisitions/baskets";
36
37
$t->post_ok($url, json => {})
38
  ->status_is(403);
39
40
$schema->resultset('UserPermission')->create(
41
    {
42
        borrowernumber => $patron->borrowernumber,
43
        module_bit => 11,
44
        code => 'order_manage',
45
    }
46
);
47
48
$t->post_ok($url, json => {})
49
  ->status_is(400);
50
51
$t->post_ok($url, json => { vendor_id => $bookseller->id })
52
  ->status_is(201)
53
  ->json_has('/basket_id')
54
  ->json_is('/vendor_id', $bookseller->id);
55
56
my $basket = {
57
    vendor_id => $bookseller->id,
58
    name => 'Basket #1',
59
    vendor_note => 'Vendor note',
60
};
61
$t->post_ok($url, json => $basket)
62
  ->status_is(201)
63
  ->json_has('/basket_id')
64
  ->json_is('/vendor_id', $basket->{vendor_id})
65
  ->json_is('/name', $basket->{name})
66
  ->json_is('/vendor_note', $basket->{vendor_note});
67
68
$schema->storage->txn_rollback;

Return to bug 29668