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

(-)a/Koha/REST/V1/Illbatches.pm (-54 / +20 lines)
Lines 56-89 Get one batch Link Here
56
=cut
56
=cut
57
57
58
sub get {
58
sub get {
59
    my $c = shift->openapi->valid_input;
59
    my $c = shift->openapi->valid_input or return;
60
60
61
    my $batchid = $c->param('ill_batch_id');
61
    return try {
62
        my $ill_batch = $c->objects->find( Koha::Illbatches->search, $c->param('ill_batch_id') );
62
63
63
    my $batch = Koha::Illbatches->find($batchid);
64
        unless ($ill_batch) {
65
            return $c->render(
66
                status  => 404,
67
                openapi => { error => "ILL batch not found" }
68
            );
69
        }
64
70
65
    if ( not defined $batch ) {
66
        return $c->render(
71
        return $c->render(
67
            status  => 404,
72
            status  => 200,
68
            openapi => { error => "ILL batch not found" }
73
            openapi => $ill_batch
69
        );
74
        );
70
    }
75
    } catch {
71
76
        $c->unhandled_exception($_);
72
    return $c->render(
77
    };
73
        status  => 200,
74
        openapi => {
75
            batch_id       => $batch->id,
76
            backend        => $batch->backend,
77
            library_id     => $batch->branchcode,
78
            name           => $batch->name,
79
            statuscode     => $batch->statuscode,
80
            patron_id      => $batch->borrowernumber,
81
            patron         => $batch->patron->unblessed,
82
            branch         => $batch->branch->unblessed,
83
            status         => $batch->status->unblessed,
84
            requests_count => $batch->requests_count
85
        }
86
    );
87
}
78
}
88
79
89
=head3 add
80
=head3 add
Lines 97-104 sub add { Link Here
97
88
98
    my $body = $c->req->json;
89
    my $body = $c->req->json;
99
90
100
    # We receive cardnumber, so we need to look up the corresponding
101
    # borrowernumber
102
    my $patron = Koha::Patrons->find( { cardnumber => $body->{cardnumber} } );
91
    my $patron = Koha::Patrons->find( { cardnumber => $body->{cardnumber} } );
103
92
104
    if ( not defined $patron ) {
93
    if ( not defined $patron ) {
Lines 113-138 sub add { Link Here
113
    $body->{branchcode}     = delete $body->{library_id};
102
    $body->{branchcode}     = delete $body->{library_id};
114
103
115
    return try {
104
    return try {
116
        my $batch = Koha::Illbatch->new($body);
105
        my $batch = Koha::Illbatch->new_from_api($body);
117
        $batch->create_and_log;
106
        $batch->create_and_log;
107
118
        $c->res->headers->location( $c->req->url->to_string . '/' . $batch->id );
108
        $c->res->headers->location( $c->req->url->to_string . '/' . $batch->id );
119
109
120
        my $ret = {
110
        my $ill_batch = $c->objects->find( Koha::Illbatches->search, $batch->id );
121
            batch_id       => $batch->id,
122
            backend        => $batch->backend,
123
            library_id     => $batch->branchcode,
124
            name           => $batch->name,
125
            statuscode     => $batch->statuscode,
126
            patron_id      => $batch->borrowernumber,
127
            patron         => $batch->patron->unblessed,
128
            branch         => $batch->branch->unblessed,
129
            status         => $batch->status->unblessed,
130
            requests_count => 0
131
        };
132
111
133
        return $c->render(
112
        return $c->render(
134
            status  => 201,
113
            status  => 201,
135
            openapi => $ret
114
            openapi => $ill_batch
136
        );
115
        );
137
    } catch {
116
    } catch {
138
        if ( blessed $_ ) {
117
        if ( blessed $_ ) {
Lines 158-164 sub update { Link Here
158
137
159
    my $batch = Koha::Illbatches->find( $c->param('ill_batch_id') );
138
    my $batch = Koha::Illbatches->find( $c->param('ill_batch_id') );
160
139
161
    if ( not defined $batch ) {
140
    unless ($batch) {
162
        return $c->render(
141
        return $c->render(
163
            status  => 404,
142
            status  => 404,
164
            openapi => { error => "ILL batch not found" }
143
            openapi => { error => "ILL batch not found" }
Lines 173-194 sub update { Link Here
173
    return try {
152
    return try {
174
        $batch->update_and_log($params);
153
        $batch->update_and_log($params);
175
154
176
        my $ret = {
177
            batch_id       => $batch->id,
178
            backend        => $batch->backend,
179
            library_id     => $batch->branchcode,
180
            name           => $batch->name,
181
            statuscode     => $batch->statuscode,
182
            patron_id      => $batch->borrowernumber,
183
            patron         => $batch->patron->unblessed,
184
            branch         => $batch->branch->unblessed,
185
            status         => $batch->status->unblessed,
186
            requests_count => $batch->requests_count
187
        };
188
189
        return $c->render(
155
        return $c->render(
190
            status  => 200,
156
            status  => 200,
191
            openapi => $ret
157
            openapi => $batch->to_api
192
        );
158
        );
193
    } catch {
159
    } catch {
194
        $c->unhandled_exception($_);
160
        $c->unhandled_exception($_);
(-)a/api/v1/swagger/paths/ill_batches.yaml (+33 lines)
Lines 73-78 Link Here
73
        required: true
73
        required: true
74
        schema:
74
        schema:
75
          $ref: "../swagger.yaml#/definitions/ill_batch"
75
          $ref: "../swagger.yaml#/definitions/ill_batch"
76
      - name: x-koha-embed
77
        in: header
78
        required: false
79
        description: Embed list sent as a request header
80
        type: array
81
        items:
82
          type: string
83
          enum:
84
            - +strings
85
            - requests+count
86
            - patron
87
            - branch
88
        collectionFormat: csv
76
    produces:
89
    produces:
77
      - application/json
90
      - application/json
78
    responses:
91
    responses:
Lines 127-132 Link Here
127
        description: ILL batch id/name/contents
140
        description: ILL batch id/name/contents
128
        required: true
141
        required: true
129
        type: string
142
        type: string
143
      - $ref: "../swagger.yaml#/parameters/page"
144
      - $ref: "../swagger.yaml#/parameters/per_page"
145
      - $ref: "../swagger.yaml#/parameters/match"
146
      - $ref: "../swagger.yaml#/parameters/order_by"
147
      - $ref: "../swagger.yaml#/parameters/q_param"
148
      - $ref: "../swagger.yaml#/parameters/q_body"
149
      - $ref: "../swagger.yaml#/parameters/request_id_header"
150
      - name: x-koha-embed
151
        in: header
152
        required: false
153
        description: Embed list sent as a request header
154
        type: array
155
        items:
156
          type: string
157
          enum:
158
            - +strings
159
            - requests+count
160
            - patron
161
            - branch
162
        collectionFormat: csv
130
    produces:
163
    produces:
131
      - application/json
164
      - application/json
132
    responses:
165
    responses:
(-)a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js (-3 / +9 lines)
Lines 309-315 Link Here
309
        var payload = {
309
        var payload = {
310
            batch_id: batchId,
310
            batch_id: batchId,
311
            ill_backend_id: batch.data.backend,
311
            ill_backend_id: batch.data.backend,
312
            patron_id: batch.data.patron.borrowernumber,
312
            patron_id: batch.data.patron.patron_id,
313
            library_id: batch.data.library_id,
313
            library_id: batch.data.library_id,
314
            extended_attributes: extended_attributes
314
            extended_attributes: extended_attributes
315
        };
315
        };
Lines 499-505 Link Here
499
499
500
    // Get the batch
500
    // Get the batch
501
    function fetchBatch() {
501
    function fetchBatch() {
502
        window.doBatchApiRequest("/" + batchId)
502
        window.doBatchApiRequest("/" + batchId, {
503
                headers: {
504
                    'x-koha-embed': 'patron'
505
                }
506
            })
503
            .then(function (response) {
507
            .then(function (response) {
504
                return response.json();
508
                return response.json();
505
            })
509
            })
Lines 528-534 Link Here
528
        return doBatchApiRequest('', {
532
        return doBatchApiRequest('', {
529
            method: 'POST',
533
            method: 'POST',
530
            headers: {
534
            headers: {
531
                'Content-type': 'application/json'
535
                'Content-type': 'application/json',
536
                'x-koha-embed': 'patron'
532
            },
537
            },
533
            body: JSON.stringify({
538
            body: JSON.stringify({
534
                name: nameInput.value,
539
                name: nameInput.value,
Lines 572-577 Link Here
572
    function updateBatch() {
577
    function updateBatch() {
573
        var selectedBranchcode = branchcodeSelect.selectedOptions[0].value;
578
        var selectedBranchcode = branchcodeSelect.selectedOptions[0].value;
574
        var selectedStatuscode = statusesSelect.selectedOptions[0].value;
579
        var selectedStatuscode = statusesSelect.selectedOptions[0].value;
580
575
        return doBatchApiRequest('/' + batch.data.batch_id, {
581
        return doBatchApiRequest('/' + batch.data.batch_id, {
576
            method: 'PUT',
582
            method: 'PUT',
577
            headers: {
583
            headers: {
(-)a/t/db_dependent/api/v1/ill_batches.t (-4 / +6 lines)
Lines 161-167 subtest 'get() tests' => sub { Link Here
161
    $patron->set_password( { password => $password, skip_validation => 1 } );
161
    $patron->set_password( { password => $password, skip_validation => 1 } );
162
    my $unauth_userid = $patron->userid;
162
    my $unauth_userid = $patron->userid;
163
163
164
    $t->get_ok( "//$userid:$password@/api/v1/ill/batches/" . $batch->id )->status_is(200)
164
    $t->get_ok( "//$userid:$password@/api/v1/ill/batches/"
165
            . $batch->id => { 'x-koha-embed' => '+strings,requests+count,patron,branch' } )->status_is(200)
165
        ->json_has( '/batch_id',   'Batch ID' )->json_has( '/name', 'Batch name' )
166
        ->json_has( '/batch_id',   'Batch ID' )->json_has( '/name', 'Batch name' )
166
        ->json_has( '/backend',    'Backend name' )->json_has( '/patron_id', 'Borrowernumber' )
167
        ->json_has( '/backend',    'Backend name' )->json_has( '/patron_id', 'Borrowernumber' )
167
        ->json_has( '/library_id', 'Branchcode' )->json_has( '/patron', 'patron embedded' )
168
        ->json_has( '/library_id', 'Branchcode' )->json_has( '/patron', 'patron embedded' )
Lines 238-248 subtest 'add() tests' => sub { Link Here
238
239
239
    # Authorized attempt to write
240
    # Authorized attempt to write
240
    my $batch_id =
241
    my $batch_id =
241
        $t->post_ok( "//$userid:$password@/api/v1/ill/batches" => json => $batch_metadata )->status_is(201)
242
        $t->post_ok( "//$userid:$password@/api/v1/ill/batches" =>
243
                { 'x-koha-embed' => '+strings,requests+count,patron,branch' } => json => $batch_metadata )
244
            ->status_is(201)
242
        ->json_is( '/name'       => $batch_metadata->{name} )->json_is( '/backend' => $batch_metadata->{backend} )
245
        ->json_is( '/name'       => $batch_metadata->{name} )->json_is( '/backend' => $batch_metadata->{backend} )
243
        ->json_is( '/patron_id'  => $librarian->borrowernumber )
246
        ->json_is( '/patron_id'  => $librarian->borrowernumber )
244
        ->json_is( '/library_id' => $batch_metadata->{library_id} )->json_is( '/statuscode' => $batch_status->code )
247
        ->json_is( '/library_id' => $batch_metadata->{library_id} )->json_is( '/statuscode' => $batch_status->code )
245
        ->json_has('/patron')->json_has('/status')->json_has('/requests_count')->json_has('/branch');
248
        ->json_has('/patron')->json_has('/_strings/status')->json_has('/requests_count')->json_has('/branch');
246
249
247
    # Authorized attempt to create with null id
250
    # Authorized attempt to create with null id
248
    $batch_metadata->{id} = undef;
251
    $batch_metadata->{id} = undef;
249
- 

Return to bug 30719