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

(-)a/Koha/REST/V1/Accountline.pm (+22 lines)
Lines 36-39 sub list { Link Here
36
    return $c->$cb($accountlines->unblessed, 200);
36
    return $c->$cb($accountlines->unblessed, 200);
37
}
37
}
38
38
39
40
sub edit {
41
    my ($c, $args, $cb) = @_;
42
43
    my $user = $c->stash('koha.user');
44
    unless ($user && haspermission($user->userid, {updatecharges => 1})) {
45
        return $c->$cb({error => "You don't have the required permission"}, 403);
46
    }
47
48
    my $accountline = Koha::Accountlines->find($args->{accountlines_id});
49
    unless ($accountline) {
50
        return $c->$cb({error => "Accountline not found"}, 404);
51
    }
52
53
    my $body = $c->req->json;
54
55
    $accountline->set( $body );
56
    $accountline->store();
57
58
    return $c->$cb($accountline->unblessed(), 200);
59
}
60
39
1;
61
1;
(-)a/api/v1/definitions/editAccountlineBody.json (+17 lines)
Line 0 Link Here
1
{
2
    "type": "object",
3
        "properties": {
4
            "amount": {
5
                "description": "Amount"
6
            },
7
            "amountoutstanding": {
8
                "description": "Amount outstanding"
9
            },
10
            "note": {
11
                "description": "Accountline note"
12
            },
13
            "meansofpayment": {
14
                "description": "Means of payment"
15
            }
16
      }
17
}
(-)a/api/v1/definitions/index.json (+1 lines)
Lines 1-5 Link Here
1
{
1
{
2
    "accountline": { "$ref": "accountline.json" },
2
    "accountline": { "$ref": "accountline.json" },
3
    "editAccountlineBody": { "$ref": "editAccountlineBody.json" },
3
    "patron": { "$ref": "patron.json" },
4
    "patron": { "$ref": "patron.json" },
4
    "holds": { "$ref": "holds.json" },
5
    "holds": { "$ref": "holds.json" },
5
    "hold": { "$ref": "hold.json" },
6
    "hold": { "$ref": "hold.json" },
(-)a/api/v1/swagger.json (+48 lines)
Lines 257-262 Link Here
257
          }
257
          }
258
        }
258
        }
259
      }
259
      }
260
    },
261
    "/accountlines/{accountlines_id}": {
262
      "put": {
263
        "operationId": "editAccountlines",
264
        "tags": ["accountlines"],
265
        "produces": [
266
          "application/json"
267
        ],
268
        "parameters": [
269
          { "$ref": "#/parameters/accountlinesIdPathParam" },
270
          {
271
            "name": "body",
272
            "in": "body",
273
            "description": "A JSON object containing fields to modify",
274
            "required": true,
275
            "schema": { "$ref": "#/definitions/editAccountlineBody" }
276
          }
277
        ],
278
        "consumes": ["application/json"],
279
        "produces": ["application/json"],
280
        "responses": {
281
          "200": {
282
            "description": "Updated accountline",
283
            "schema": { "$ref": "#/definitions/accountline" }
284
          },
285
          "400": {
286
            "description": "Missing or wrong parameters",
287
            "schema": { "$ref": "#/definitions/error" }
288
          },
289
          "403": {
290
            "description": "Access forbidden",
291
            "schema": {
292
              "$ref": "#/definitions/error"
293
            }
294
          },
295
          "404": {
296
            "description": "Accountline not found",
297
            "schema": { "$ref": "#/definitions/error" }
298
          }
299
        }
300
      }
260
    }
301
    }
261
  },
302
  },
262
  "definitions": {
303
  "definitions": {
Lines 276-281 Link Here
276
      "description": "Internal hold identifier",
317
      "description": "Internal hold identifier",
277
      "required": true,
318
      "required": true,
278
      "type": "integer"
319
      "type": "integer"
320
    },
321
    "accountlinesIdPathParam": {
322
      "name": "accountlines_id",
323
      "in": "path",
324
      "description": "Internal accountline identifier",
325
      "required": true,
326
      "type": "integer"
279
    }
327
    }
280
  }
328
  }
281
}
329
}
(-)a/t/db_dependent/api/v1/accountlines.t (-2 / +39 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 10;
20
use Test::More tests => 18;
21
use Test::Mojo;
21
use Test::Mojo;
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
23
Lines 41-46 my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; Link Here
41
$t->get_ok('/api/v1/accountlines')
41
$t->get_ok('/api/v1/accountlines')
42
  ->status_is(403);
42
  ->status_is(403);
43
43
44
$t->put_ok("/api/v1/accountlines/11224409" => json => {'amount' => -5})
45
    ->status_is(403);
46
44
my $loggedinuser = $builder->build({
47
my $loggedinuser = $builder->build({
45
    source => 'Borrower',
48
    source => 'Borrower',
46
    value => {
49
    value => {
Lines 101-104 $json = $t->tx->res->json; Link Here
101
ok(ref $json eq 'ARRAY', 'response is a JSON array');
104
ok(ref $json eq 'ARRAY', 'response is a JSON array');
102
ok(scalar @$json == 4, 'response array contains 3 elements');
105
ok(scalar @$json == 4, 'response array contains 3 elements');
103
106
107
# Editing accountlines tests
108
my $put_data = {
109
    'amount' => -19,
110
    'amountoutstanding' => -19
111
};
112
113
114
$tx = $t->ua->build_tx(
115
    PUT => "/api/v1/accountlines/11224409"
116
        => {Accept => '*/*'}
117
        => json => $put_data);
118
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
119
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
120
$t->request_ok($tx)
121
    ->status_is(404);
122
123
my $accountline_to_edit = Koha::Accountlines->search({'borrowernumber' => $borrowernumber2})->unblessed()->[0];
124
125
$tx = $t->ua->build_tx(
126
    PUT => "/api/v1/accountlines/$accountline_to_edit->{accountlines_id}"
127
        => {Accept => '*/*'}
128
        => json => $put_data);
129
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
130
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
131
$t->request_ok($tx)
132
    ->status_is(200);
133
134
my $accountline_edited = Koha::Accountlines->search({'borrowernumber' => $borrowernumber2})->unblessed()->[0];
135
136
is($accountline_edited->{amount}, '-19.000000');
137
is($accountline_edited->{amountoutstanding}, '-19.000000');
138
139
140
# Payment tests
141
104
$dbh->rollback;
142
$dbh->rollback;
105
- 

Return to bug 15165