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
    "patron": { "$ref": "patron.json" },
2
    "patron": { "$ref": "patron.json" },
3
    "accountline": { "$ref": "accountline.json" },
3
    "accountline": { "$ref": "accountline.json" },
4
    "editAccountlineBody": { "$ref": "editAccountlineBody.json" },
4
    "error": { "$ref": "error.json" }
5
    "error": { "$ref": "error.json" }
5
}
6
}
(-)a/api/v1/swagger.json (+48 lines)
Lines 99-104 Link Here
99
          }
99
          }
100
        }
100
        }
101
      }
101
      }
102
    },
103
    "/accountlines/{accountlines_id}": {
104
      "put": {
105
        "operationId": "editAccountlines",
106
        "tags": ["accountlines"],
107
        "produces": [
108
          "application/json"
109
        ],
110
        "parameters": [
111
          { "$ref": "#/parameters/accountlinesIdPathParam" },
112
          {
113
            "name": "body",
114
            "in": "body",
115
            "description": "A JSON object containing fields to modify",
116
            "required": true,
117
            "schema": { "$ref": "#/definitions/editAccountlineBody" }
118
          }
119
        ],
120
        "consumes": ["application/json"],
121
        "produces": ["application/json"],
122
        "responses": {
123
          "200": {
124
            "description": "Updated accountline",
125
            "schema": { "$ref": "#/definitions/accountline" }
126
          },
127
          "400": {
128
            "description": "Missing or wrong parameters",
129
            "schema": { "$ref": "#/definitions/error" }
130
          },
131
          "403": {
132
            "description": "Access forbidden",
133
            "schema": {
134
              "$ref": "#/definitions/error"
135
            }
136
          },
137
          "404": {
138
            "description": "Accountline not found",
139
            "schema": { "$ref": "#/definitions/error" }
140
          }
141
        }
142
      }
102
    }
143
    }
103
  },
144
  },
104
  "definitions": {
145
  "definitions": {
Lines 111-116 Link Here
111
      "description": "Internal patron identifier",
152
      "description": "Internal patron identifier",
112
      "required": true,
153
      "required": true,
113
      "type": "integer"
154
      "type": "integer"
155
    },
156
    "accountlinesIdPathParam": {
157
      "name": "accountlines_id",
158
      "in": "path",
159
      "description": "Internal accountline identifier",
160
      "required": true,
161
      "type": "integer"
114
    }
162
    }
115
  }
163
  }
116
}
164
}
(-)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