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

(-)a/Koha/REST/V1/Accountline.pm (+17 lines)
Lines 31-34 sub list { Link Here
31
    return $c->$cb($accountlines->unblessed, 200);
31
    return $c->$cb($accountlines->unblessed, 200);
32
}
32
}
33
33
34
35
sub edit {
36
    my ($c, $args, $cb) = @_;
37
38
    my $accountline = Koha::Account::Lines->find($args->{accountlines_id});
39
    unless ($accountline) {
40
        return $c->$cb({error => "Accountline not found"}, 404);
41
    }
42
43
    my $body = $c->req->json;
44
45
    $accountline->set( $body );
46
    $accountline->store();
47
48
    return $c->$cb($accountline->unblessed(), 200);
49
}
50
34
1;
51
1;
(-)a/api/v1/swagger/parameters.json (+3 lines)
Lines 1-4 Link Here
1
{
1
{
2
  "accountlinesIdPathParam": {
3
    "$ref": "parameters/accountline.json#/accountlinesIdPathParam"
4
  },
2
  "borrowernumberPathParam": {
5
  "borrowernumberPathParam": {
3
    "$ref": "parameters/patron.json#/borrowernumberPathParam"
6
    "$ref": "parameters/patron.json#/borrowernumberPathParam"
4
  },
7
  },
(-)a/api/v1/swagger/parameters/accountline.json (+9 lines)
Line 0 Link Here
1
{
2
  "accountlinesIdPathParam": {
3
    "name": "accountlines_id",
4
    "in": "path",
5
    "description": "Internal accountline identifier",
6
    "required": true,
7
    "type": "integer"
8
  }
9
}
(-)a/api/v1/swagger/paths.json (+3 lines)
Lines 2-7 Link Here
2
  "/accountlines": {
2
  "/accountlines": {
3
    "$ref": "paths/accountlines.json#/~1accountlines"
3
    "$ref": "paths/accountlines.json#/~1accountlines"
4
  },
4
  },
5
  "/accountlines/{accountlines_id}": {
6
    "$ref": "paths/accountlines.json#/~1accountlines~1{accountlines_id}"
7
  },
5
  "/holds": {
8
  "/holds": {
6
    "$ref": "paths/holds.json#/~1holds"
9
    "$ref": "paths/holds.json#/~1holds"
7
  },
10
  },
(-)a/api/v1/swagger/paths/accountlines.json (+62 lines)
Lines 31-35 Link Here
31
        }
31
        }
32
      }
32
      }
33
    }
33
    }
34
  },
35
  "/accountlines/{accountlines_id}": {
36
    "put": {
37
      "operationId": "editAccountlines",
38
      "tags": ["accountlines"],
39
      "produces": [
40
        "application/json"
41
      ],
42
      "parameters": [
43
        { "$ref": "../parameters.json#/accountlinesIdPathParam" },
44
        {
45
          "name": "body",
46
          "in": "body",
47
          "description": "A JSON object containing fields to modify",
48
          "required": true,
49
          "schema": {
50
            "type": "object",
51
            "properties": {
52
              "amount": {
53
                "description": "Amount"
54
              },
55
              "amountoutstanding": {
56
                "description": "Amount outstanding"
57
              },
58
              "note": {
59
                "description": "Accountline note"
60
              },
61
              "meansofpayment": {
62
                "description": "Means of payment"
63
              }
64
            }
65
          }
66
        }
67
      ],
68
      "consumes": ["application/json"],
69
      "produces": ["application/json"],
70
      "responses": {
71
        "200": {
72
          "description": "Updated accountline",
73
          "schema": { "$ref": "../definitions.json#/accountline" }
74
        },
75
        "400": {
76
          "description": "Missing or wrong parameters",
77
          "schema": { "$ref": "../definitions.json#/error" }
78
        },
79
        "403": {
80
          "description": "Access forbidden",
81
          "schema": {
82
            "$ref": "../definitions.json#/error"
83
          }
84
        },
85
        "404": {
86
          "description": "Accountline not found",
87
          "schema": { "$ref": "../definitions.json#/error" }
88
        }
89
      },
90
      "x-koha-authorization": {
91
        "permissions": {
92
          "updatecharges": "1"
93
        }
94
      }
95
    }
34
  }
96
  }
35
}
97
}
(-)a/t/db_dependent/api/v1/accountlines.t (-2 / +45 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 12;
20
use Test::More tests => 22;
21
use Test::Mojo;
21
use Test::Mojo;
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
23
Lines 25-30 use C4::Auth; Link Here
25
use C4::Context;
25
use C4::Context;
26
26
27
use Koha::Database;
27
use Koha::Database;
28
use Koha::Account::Line;
28
29
29
my $builder = t::lib::TestBuilder->new();
30
my $builder = t::lib::TestBuilder->new();
30
31
Lines 41-46 my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; Link Here
41
$t->get_ok('/api/v1/accountlines')
42
$t->get_ok('/api/v1/accountlines')
42
  ->status_is(401);
43
  ->status_is(401);
43
44
45
$t->put_ok("/api/v1/accountlines/11224409" => json => {'amount' => -5})
46
    ->status_is(401);
47
44
my $loggedinuser = $builder->build({
48
my $loggedinuser = $builder->build({
45
    source => 'Borrower',
49
    source => 'Borrower',
46
    value => {
50
    value => {
Lines 115-118 $json = $t->tx->res->json; Link Here
115
ok(ref $json eq 'ARRAY', 'response is a JSON array');
119
ok(ref $json eq 'ARRAY', 'response is a JSON array');
116
ok(scalar @$json == 4, 'response array contains 3 elements');
120
ok(scalar @$json == 4, 'response array contains 3 elements');
117
121
122
# Editing accountlines tests
123
my $put_data = {
124
    'amount' => -19,
125
    'amountoutstanding' => -19
126
};
127
128
$tx = $t->ua->build_tx(
129
    PUT => "/api/v1/accountlines/11224409"
130
        => {Accept => '*/*'}
131
        => json => $put_data);
132
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
133
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
134
$t->request_ok($tx)
135
    ->status_is(404);
136
137
my $accountline_to_edit = Koha::Account::Lines->search({'borrowernumber' => $borrowernumber2})->unblessed()->[0];
138
139
$tx = $t->ua->build_tx(PUT => "/api/v1/accountlines/$accountline_to_edit->{accountlines_id}" => json => $put_data);
140
$tx->req->cookies({name => 'CGISESSID', value => $borrowersession->id});
141
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
142
$t->request_ok($tx)
143
  ->status_is(403);
144
145
$tx = $t->ua->build_tx(
146
    PUT => "/api/v1/accountlines/$accountline_to_edit->{accountlines_id}"
147
        => {Accept => '*/*'}
148
        => json => $put_data);
149
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
150
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
151
$t->request_ok($tx)
152
    ->status_is(200);
153
154
my $accountline_edited = Koha::Account::Lines->search({'borrowernumber' => $borrowernumber2})->unblessed()->[0];
155
156
is($accountline_edited->{amount}, '-19.000000');
157
is($accountline_edited->{amountoutstanding}, '-19.000000');
158
159
160
# Payment tests
161
118
$dbh->rollback;
162
$dbh->rollback;
119
- 

Return to bug 15165