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

(-)a/Koha/REST/V1/Items.pm (+72 lines)
Lines 21-26 use Mojo::Base 'Mojolicious::Controller'; Link Here
21
21
22
use Koha::Items;
22
use Koha::Items;
23
23
24
use List::MoreUtils qw(any);
24
use Try::Tiny;
25
use Try::Tiny;
25
26
26
=head1 NAME
27
=head1 NAME
Lines 80-83 sub get { Link Here
80
    };
81
    };
81
}
82
}
82
83
84
=head3 pickup_locations
85
86
Method that returns the possible pickup_locations for a given item
87
used for building the dropdown selector
88
89
=cut
90
91
sub pickup_locations {
92
    my $c = shift->openapi->valid_input or return;
93
94
    my $item_id = $c->validation->param('item_id');
95
    my $item = Koha::Items->find( $item_id );
96
97
    unless ($item) {
98
        return $c->render(
99
            status  => 404,
100
            openapi => { error => "Item not found" }
101
        );
102
    }
103
104
    my $patron_id = delete $c->validation->output->{patron_id};
105
    my $patron    = Koha::Patrons->find( $patron_id );
106
107
    unless ($patron) {
108
        return $c->render(
109
            status  => 400,
110
            openapi => { error => "Patron not found" }
111
        );
112
    }
113
114
    return try {
115
116
        my $ps_set = $item->pickup_locations( { patron => $patron } );
117
118
        my $pickup_locations = $c->objects->search( $ps_set );
119
        my @response = ();
120
121
        if ( C4::Context->preference('AllowHoldPolicyOverride') ) {
122
123
            my $libraries_rs = Koha::Libraries->search( { pickup_location => 1 } );
124
            my $libraries    = $c->objects->search($libraries_rs);
125
126
            @response = map {
127
                my $library = $_;
128
                $library->{needs_override} = (
129
                    any { $_->{library_id} eq $library->{library_id} }
130
                    @{$pickup_locations}
131
                  )
132
                  ? Mojo::JSON->false
133
                  : Mojo::JSON->true;
134
                $library;
135
            } @{$libraries};
136
137
            return $c->render(
138
                status  => 200,
139
                openapi => \@response
140
            );
141
        }
142
143
        @response = map { $_->{needs_override} = Mojo::JSON->false; $_; } @{$pickup_locations};
144
145
        return $c->render(
146
            status  => 200,
147
            openapi => \@response
148
        );
149
    }
150
    catch {
151
        $c->unhandled_exception($_);
152
    };
153
}
154
83
1;
155
1;
(-)a/api/v1/swagger/paths.json (+3 lines)
Lines 80-85 Link Here
80
  "/items/{item_id}": {
80
  "/items/{item_id}": {
81
    "$ref": "paths/items.json#/~1items~1{item_id}"
81
    "$ref": "paths/items.json#/~1items~1{item_id}"
82
  },
82
  },
83
  "/items/{item_id}/pickup_locations": {
84
    "$ref": "paths/items.json#/~1items~1{item_id}~1pickup_locations"
85
  },
83
  "/libraries": {
86
  "/libraries": {
84
    "$ref": "paths/libraries.json#/~1libraries"
87
    "$ref": "paths/libraries.json#/~1libraries"
85
  },
88
  },
(-)a/api/v1/swagger/paths/items.json (-1 / +101 lines)
Lines 124-128 Link Here
124
        }
124
        }
125
      }
125
      }
126
    }
126
    }
127
  },
128
  "/items/{item_id}/pickup_locations": {
129
    "get": {
130
      "x-mojo-to": "Items#pickup_locations",
131
      "operationId": "getItemPickupLocations",
132
      "tags": [
133
        "items",
134
        "pickup_locations"
135
      ],
136
      "parameters": [
137
        {
138
          "$ref": "../parameters.json#/item_id_pp"
139
        },
140
        {
141
          "name": "patron_id",
142
          "in": "query",
143
          "description": "Internal patron identifier",
144
          "required": true,
145
          "type": "integer"
146
        },
147
        {
148
          "$ref": "../parameters.json#/match"
149
        },
150
        {
151
          "$ref": "../parameters.json#/order_by"
152
        },
153
        {
154
          "$ref": "../parameters.json#/page"
155
        },
156
        {
157
          "$ref": "../parameters.json#/per_page"
158
        },
159
        {
160
          "$ref": "../parameters.json#/q_param"
161
        },
162
        {
163
          "$ref": "../parameters.json#/q_body"
164
        },
165
        {
166
          "$ref": "../parameters.json#/q_header"
167
        }
168
      ],
169
      "consumes": [
170
        "application/json"
171
      ],
172
      "produces": [
173
        "application/json"
174
      ],
175
      "responses": {
176
        "200": {
177
          "description": "Item pickup locations",
178
          "schema": {
179
            "type": "array",
180
            "items": {
181
              "$ref": "../definitions.json#/library"
182
            }
183
          }
184
        },
185
        "400": {
186
          "description": "Missing or wrong parameters",
187
          "schema": {
188
            "$ref": "../definitions.json#/error"
189
          }
190
        },
191
        "401": {
192
          "description": "Authentication required",
193
          "schema": {
194
            "$ref": "../definitions.json#/error"
195
          }
196
        },
197
        "403": {
198
          "description": "Access forbidden",
199
          "schema": {
200
            "$ref": "../definitions.json#/error"
201
          }
202
        },
203
        "404": {
204
          "description": "Biblio not found",
205
          "schema": {
206
            "$ref": "../definitions.json#/error"
207
          }
208
        },
209
        "500": {
210
          "description": "Internal server error",
211
          "schema": {
212
            "$ref": "../definitions.json#/error"
213
          }
214
        },
215
        "503": {
216
          "description": "Under maintenance",
217
          "schema": {
218
            "$ref": "../definitions.json#/error"
219
          }
220
        }
221
      },
222
      "x-koha-authorization": {
223
        "permissions": {
224
          "reserveforothers": "place_holds"
225
        }
226
      }
227
    }
127
  }
228
  }
128
}
229
}
129
- 

Return to bug 27931