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

(-)a/Koha/REST/V1/ReturnClaims.pm (-13 / +9 lines)
Lines 57-73 sub claim_returned { Link Here
57
            status  => 404
57
            status  => 404
58
        ) unless $checkout;
58
        ) unless $checkout;
59
59
60
        my $claim = Koha::Checkouts::ReturnClaims->find(
60
        my $claim = $checkout->claim_returned(
61
            {
62
                issue_id => $checkout->id
63
            }
64
        );
65
        return $c->render(
66
            openapi => { error => "Bad request - claim exists" },
67
            status  => 400
68
        ) if $claim;
69
70
        $claim = $checkout->claim_returned(
71
            {
61
            {
72
                charge_lost_fee => $charge_lost_fee,
62
                charge_lost_fee => $charge_lost_fee,
73
                created_by      => $created_by,
63
                created_by      => $created_by,
Lines 82-93 sub claim_returned { Link Here
82
        );
72
        );
83
    }
73
    }
84
    catch {
74
    catch {
85
        if ( $_->isa('Koha::Exceptions::Checkouts::ReturnClaims') ) {
75
        if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
86
            return $c->render(
76
            return $c->render(
87
                status  => 500,
77
                status  => 409,
88
                openapi => { error => "$_" }
78
                openapi => { error => "$_" }
89
            );
79
            );
90
        }
80
        }
81
        elsif ( $_->isa('Koha::Exceptions::Checkouts::ReturnClaims::NoCreatedBy') ) {
82
            return $c->render(
83
                status  => 400,
84
                openapi => { error => "Mandatory attribute created_by missing" }
85
            );
86
        }
91
        else {
87
        else {
92
            return $c->render(
88
            return $c->render(
93
                status  => 500,
89
                status  => 500,
(-)a/api/v1/swagger/paths/return_claims.json (-4 / +10 lines)
Lines 67-76 Link Here
67
          }
67
          }
68
        },
68
        },
69
        "404": {
69
        "404": {
70
          "description": "Checkout not found",
70
            "description": "Checkout not found",
71
          "schema": {
71
            "schema": {
72
            "$ref": "../definitions.json#/error"
72
                "$ref": "../definitions.json#/error"
73
          }
73
            }
74
        },
75
        "409": {
76
            "description": "Conflict creating the resource",
77
            "schema": {
78
                "$ref": "../definitions.json#/error"
79
            }
74
        },
80
        },
75
        "500": {
81
        "500": {
76
          "description": "Internal server error",
82
          "description": "Internal server error",
(-)a/t/db_dependent/api/v1/return_claims.t (-10 / +15 lines)
Lines 17-25 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 25;
20
use Test::More tests => 27;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Mojo;
22
use Test::Mojo;
23
use Test::Warn;
23
use t::lib::Mocks;
24
use t::lib::Mocks;
24
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
25
26
Lines 97-114 $t->post_ok( Link Here
97
        created_by      => $librarian->id,
98
        created_by      => $librarian->id,
98
        notes           => "This is a test note."
99
        notes           => "This is a test note."
99
    }
100
    }
100
)->status_is(201);
101
)->status_is(201)
102
 ->header_like( Location => qr|^\/api\/v1\/return_claims/\d*|, 'SWAGGER3.4.1');
103
101
my $claim_id = $t->tx->res->json->{claim_id};
104
my $claim_id = $t->tx->res->json->{claim_id};
102
105
103
## Duplicate id
106
## Duplicate id
104
$t->post_ok(
107
warning_like {
105
    "//$userid:$password@/api/v1/return_claims" => json => {
108
        $t->post_ok(
106
        item_id         => $itemnumber1,
109
            "//$userid:$password@/api/v1/return_claims" => json => {
107
        charge_lost_fee => Mojo::JSON->false,
110
                item_id         => $itemnumber1,
108
        created_by      => $librarian->id,
111
                charge_lost_fee => Mojo::JSON->false,
109
        notes           => "This is a test note."
112
                created_by      => $librarian->id,
113
                notes           => "This is a test note."
114
            }
115
        )->status_is(409)
110
    }
116
    }
111
)->status_is(400);
117
    qr/^DBD::mysql::st execute failed: Duplicate entry/;
112
118
113
# Test editing a claim note
119
# Test editing a claim note
114
## Valid claim id
120
## Valid claim id
115
- 

Return to bug 14697