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

(-)a/Koha/REST/V1/Patron.pm (-10 / +7 lines)
Lines 22-47 use Mojo::Base 'Mojolicious::Controller'; Link Here
22
use Koha::Patrons;
22
use Koha::Patrons;
23
23
24
sub list {
24
sub list {
25
    my ($c, $args, $cb) = @_;
25
    my $c = shift->openapi->valid_input or return;
26
27
    my $user = $c->stash('koha.user');
28
26
29
    my $patrons = Koha::Patrons->search;
27
    my $patrons = Koha::Patrons->search;
30
28
31
    $c->$cb($patrons, 200);
29
    return $c->render(status => 200, openapi => $patrons);
32
}
30
}
33
31
34
sub get {
32
sub get {
35
    my ($c, $args, $cb) = @_;
33
    my $c = shift->openapi->valid_input or return;
36
37
    my $user = $c->stash('koha.user');
38
34
39
    my $patron = Koha::Patrons->find($args->{borrowernumber});
35
    my $borrowernumber = $c->validation->param('borrowernumber');
36
    my $patron = Koha::Patrons->find($borrowernumber);
40
    unless ($patron) {
37
    unless ($patron) {
41
        return $c->$cb({error => "Patron not found"}, 404);
38
        return $c->render(status => 404, openapi => { error => "Patron not found." });
42
    }
39
    }
43
40
44
    return $c->$cb($patron, 200);
41
    return $c->render(status => 200, openapi => $patron);
45
}
42
}
46
43
47
1;
44
1;
(-)a/api/v1/swagger/paths/patrons.json (+38 lines)
Lines 1-6 Link Here
1
{
1
{
2
  "/patrons": {
2
  "/patrons": {
3
    "get": {
3
    "get": {
4
      "x-mojo-to": "Patron#list",
4
      "operationId": "listPatrons",
5
      "operationId": "listPatrons",
5
      "tags": ["patrons"],
6
      "tags": ["patrons"],
6
      "produces": [
7
      "produces": [
Lines 16-26 Link Here
16
            }
17
            }
17
          }
18
          }
18
        },
19
        },
20
        "401": {
21
          "description": "Authentication required",
22
          "schema": {
23
            "$ref": "../definitions.json#/error"
24
          }
25
        },
19
        "403": {
26
        "403": {
20
          "description": "Access forbidden",
27
          "description": "Access forbidden",
21
          "schema": {
28
          "schema": {
22
            "$ref": "../definitions.json#/error"
29
            "$ref": "../definitions.json#/error"
23
          }
30
          }
31
        },
32
        "500": {
33
          "description": "Internal server error",
34
          "schema": {
35
            "$ref": "../definitions.json#/error"
36
          }
37
        },
38
        "503": {
39
          "description": "Under maintenance",
40
          "schema": {
41
            "$ref": "../definitions.json#/error"
42
          }
24
        }
43
        }
25
      },
44
      },
26
      "x-koha-authorization": {
45
      "x-koha-authorization": {
Lines 32-37 Link Here
32
  },
51
  },
33
  "/patrons/{borrowernumber}": {
52
  "/patrons/{borrowernumber}": {
34
    "get": {
53
    "get": {
54
      "x-mojo-to": "Patron#get",
35
      "operationId": "getPatron",
55
      "operationId": "getPatron",
36
      "tags": ["patrons"],
56
      "tags": ["patrons"],
37
      "parameters": [{
57
      "parameters": [{
Lines 48-53 Link Here
48
            "$ref": "../definitions.json#/patron"
68
            "$ref": "../definitions.json#/patron"
49
          }
69
          }
50
        },
70
        },
71
        "401": {
72
          "description": "Authentication required",
73
          "schema": {
74
            "$ref": "../definitions.json#/error"
75
          }
76
        },
51
        "403": {
77
        "403": {
52
          "description": "Access forbidden",
78
          "description": "Access forbidden",
53
          "schema": {
79
          "schema": {
Lines 59-64 Link Here
59
          "schema": {
85
          "schema": {
60
            "$ref": "../definitions.json#/error"
86
            "$ref": "../definitions.json#/error"
61
          }
87
          }
88
        },
89
        "500": {
90
          "description": "Internal server error",
91
          "schema": {
92
            "$ref": "../definitions.json#/error"
93
          }
94
        },
95
        "503": {
96
          "description": "Under maintenance",
97
          "schema": {
98
            "$ref": "../definitions.json#/error"
99
          }
62
        }
100
        }
63
      },
101
      },
64
      "x-koha-authorization": {
102
      "x-koha-authorization": {
(-)a/t/db_dependent/api/v1/patrons.t (-2 / +1 lines)
Lines 133-138 $t->request_ok($tx) Link Here
133
  ->status_is(200)
133
  ->status_is(200)
134
  ->json_is('/borrowernumber' => $borrower->{ borrowernumber })
134
  ->json_is('/borrowernumber' => $borrower->{ borrowernumber })
135
  ->json_is('/surname' => $borrower->{ surname })
135
  ->json_is('/surname' => $borrower->{ surname })
136
  ->json_is('/lost' => 1 );
136
  ->json_is('/lost' => Mojo::JSON->true );
137
137
138
$schema->storage->txn_rollback;
138
$schema->storage->txn_rollback;
139
- 

Return to bug 18137