| Lines 48-65
          sub list {
      
      
        Link Here | 
        
          | 48 |         return $c->render( status => 200, openapi => $holds ); | 48 |         return $c->render( status => 200, openapi => $holds ); | 
        
          | 49 |     } | 49 |     } | 
        
          | 50 |     catch { | 50 |     catch { | 
          
            
              | 51 |         if ( blessed $_ && $_->isa('Koha::Exceptions') ) { | 51 |         $c->unhandled_exception($_); | 
            
              | 52 |             return $c->render( |  |  | 
            
              | 53 |                 status  => 500, | 
            
              | 54 |                 openapi => { error => "$_" } | 
            
              | 55 |             ); | 
            
              | 56 |         } | 
            
              | 57 |         else { | 
            
              | 58 |             return $c->render( | 
            
              | 59 |                 status  => 500, | 
            
              | 60 |                 openapi => { error => "Something went wrong, check Koha logs for details." } | 
            
              | 61 |             ); | 
            
              | 62 |         } | 
        
          | 63 |     }; | 52 |     }; | 
        
          | 64 | } | 53 | } | 
        
          | 65 |  | 54 |  | 
  
    | Lines 201-226
          sub add {
      
      
        Link Here | 
        
          | 201 |                         openapi => Koha::Holds->new->to_api_mapping->{$broken_fk} . ' not found.' | 190 |                         openapi => Koha::Holds->new->to_api_mapping->{$broken_fk} . ' not found.' | 
        
          | 202 |                     ); | 191 |                     ); | 
        
          | 203 |                 } | 192 |                 } | 
            
              | 204 |                 else { |  |  | 
            
              | 205 |                     return $c->render( | 
            
              | 206 |                         status  => 500, | 
            
              | 207 |                         openapi => { error => "Uncaught exception: $_" } | 
            
              | 208 |                     ); | 
            
              | 209 |                 } | 
            
              | 210 |             } | 
            
              | 211 |             else { | 
            
              | 212 |                 return $c->render( | 
            
              | 213 |                     status  => 500, | 
            
              | 214 |                     openapi => { error => "$_" } | 
            
              | 215 |                 ); | 
        
          | 216 |             } | 193 |             } | 
        
          | 217 |         } | 194 |         } | 
          
            
              | 218 |         else { | 195 |  | 
            
              | 219 |             return $c->render( | 196 |         $c->unhandled_exception($_); | 
            
              | 220 |                 status  => 500, |  |  | 
            
              | 221 |                 openapi => { error => "Something went wrong. check the logs." } | 
            
              | 222 |             ); | 
            
              | 223 |         } | 
        
          | 224 |     }; | 197 |     }; | 
        
          | 225 | } | 198 | } | 
        
          | 226 |  | 199 |  | 
  
    | Lines 233-268
          Method that handles modifying a Koha::Hold object
      
      
        Link Here | 
        
          | 233 | sub edit { | 206 | sub edit { | 
        
          | 234 |     my $c = shift->openapi->valid_input or return; | 207 |     my $c = shift->openapi->valid_input or return; | 
        
          | 235 |  | 208 |  | 
          
            
              | 236 |     my $hold_id = $c->validation->param('hold_id'); | 209 |     return try { | 
            
              | 237 |     my $hold = Koha::Holds->find( $hold_id ); | 210 |         my $hold_id = $c->validation->param('hold_id'); | 
            
              |  |  | 211 |         my $hold = Koha::Holds->find( $hold_id ); | 
        
          | 238 |  | 212 |  | 
          
            
              | 239 |     unless ($hold) { | 213 |         unless ($hold) { | 
            
              | 240 |         return $c->render( status  => 404, | 214 |             return $c->render( status  => 404, | 
            
              | 241 |                            openapi => {error => "Hold not found"} ); | 215 |                             openapi => {error => "Hold not found"} ); | 
            
              | 242 |     } | 216 |         } | 
        
          | 243 |  | 217 |  | 
          
            
              | 244 |     my $body = $c->req->json; | 218 |         my $body = $c->req->json; | 
        
          | 245 |  | 219 |  | 
          
            
              | 246 |     my $pickup_library_id = $body->{pickup_library_id} // $hold->branchcode; | 220 |         my $pickup_library_id = $body->{pickup_library_id} // $hold->branchcode; | 
            
              | 247 |     my $priority          = $body->{priority} // $hold->priority; | 221 |         my $priority          = $body->{priority} // $hold->priority; | 
            
              | 248 |     # suspended_until can also be set to undef | 222 |         # suspended_until can also be set to undef | 
            
              | 249 |     my $suspended_until   = exists $body->{suspended_until} ? $body->{suspended_until} : $hold->suspend_until; | 223 |         my $suspended_until   = exists $body->{suspended_until} ? $body->{suspended_until} : $hold->suspend_until; | 
        
          | 250 |  | 224 |  | 
          
            
              | 251 |     my $params = { | 225 |         my $params = { | 
            
              | 252 |         reserve_id    => $hold_id, | 226 |             reserve_id    => $hold_id, | 
            
              | 253 |         branchcode    => $pickup_library_id, | 227 |             branchcode    => $pickup_library_id, | 
            
              | 254 |         rank          => $priority, | 228 |             rank          => $priority, | 
            
              | 255 |         suspend_until => $suspended_until ? output_pref(dt_from_string($suspended_until, 'rfc3339')) : '', | 229 |             suspend_until => $suspended_until ? output_pref(dt_from_string($suspended_until, 'rfc3339')) : '', | 
            
              | 256 |         itemnumber    => $hold->itemnumber | 230 |             itemnumber    => $hold->itemnumber | 
            
              | 257 |     }; | 231 |         }; | 
        
          | 258 |  | 232 |  | 
          
            
              | 259 |     C4::Reserves::ModReserve($params); | 233 |         C4::Reserves::ModReserve($params); | 
            
              | 260 |     $hold->discard_changes; # refresh | 234 |         $hold->discard_changes; # refresh | 
        
          | 261 |  | 235 |  | 
          
            
              | 262 |     return $c->render( | 236 |         return $c->render( | 
            
              | 263 |         status  => 200, | 237 |             status  => 200, | 
            
              | 264 |         openapi => $hold->to_api | 238 |             openapi => $hold->to_api | 
            
              | 265 |     ); | 239 |         ); | 
            
              |  |  | 240 |     } | 
            
              | 241 |     catch { | 
            
              | 242 |         $c->unhandled_exception($_); | 
            
              | 243 |     }; | 
        
          | 266 | } | 244 | } | 
        
          | 267 |  | 245 |  | 
        
          | 268 | =head3 delete | 246 | =head3 delete | 
  
    | Lines 281-289
          sub delete {
      
      
        Link Here | 
        
          | 281 |         return $c->render( status => 404, openapi => { error => "Hold not found." } ); | 259 |         return $c->render( status => 404, openapi => { error => "Hold not found." } ); | 
        
          | 282 |     } | 260 |     } | 
        
          | 283 |  | 261 |  | 
          
            
              | 284 |     $hold->cancel; | 262 |     return try { | 
            
              |  |  | 263 |         $hold->cancel; | 
        
          | 285 |  | 264 |  | 
          
            
              | 286 |     return $c->render( status => 200, openapi => {} ); | 265 |         return $c->render( status => 200, openapi => {} ); | 
            
              |  |  | 266 |     } | 
            
              | 267 |     catch { | 
            
              | 268 |         $c->unhandled_exception($_); | 
            
              | 269 |     }; | 
        
          | 287 | } | 270 | } | 
        
          | 288 |  | 271 |  | 
        
          | 289 | =head3 suspend | 272 | =head3 suspend | 
  
    | Lines 329-340
          sub suspend {
      
      
        Link Here | 
        
          | 329 |         if ( blessed $_ and $_->isa('Koha::Exceptions::Hold::CannotSuspendFound') ) { | 312 |         if ( blessed $_ and $_->isa('Koha::Exceptions::Hold::CannotSuspendFound') ) { | 
        
          | 330 |             return $c->render( status => 400, openapi => { error => "$_" } ); | 313 |             return $c->render( status => 400, openapi => { error => "$_" } ); | 
        
          | 331 |         } | 314 |         } | 
          
            
              | 332 |         else { | 315 |  | 
            
              | 333 |             return $c->render( | 316 |         $c->unhandled_exception($_); | 
            
              | 334 |                 status  => 500, |  |  | 
            
              | 335 |                 openapi => { error => "Something went wrong. check the logs." } | 
            
              | 336 |             ); | 
            
              | 337 |         } | 
        
          | 338 |     }; | 317 |     }; | 
        
          | 339 | } | 318 | } | 
        
          | 340 |  | 319 |  | 
  
    | Lines 360-369
          sub resume {
      
      
        Link Here | 
        
          | 360 |         return $c->render( status => 204, openapi => {} ); | 339 |         return $c->render( status => 204, openapi => {} ); | 
        
          | 361 |     } | 340 |     } | 
        
          | 362 |     catch { | 341 |     catch { | 
          
            
              | 363 |         return $c->render( | 342 |         $c->unhandled_exception($_); | 
            
              | 364 |             status  => 500, |  |  | 
            
              | 365 |             openapi => { error => "Something went wrong. check the logs." } | 
            
              | 366 |         ); | 
        
          | 367 |     }; | 343 |     }; | 
        
          | 368 | } | 344 | } | 
        
          | 369 |  | 345 |  | 
  
    | Lines 398-407
          sub update_priority {
      
      
        Link Here | 
        
          | 398 |         return $c->render( status => 200, openapi => $priority ); | 374 |         return $c->render( status => 200, openapi => $priority ); | 
        
          | 399 |     } | 375 |     } | 
        
          | 400 |     catch { | 376 |     catch { | 
          
            
              | 401 |         return $c->render( | 377 |         $c->unhandled_exception($_); | 
            
              | 402 |             status  => 500, |  |  | 
            
              | 403 |             openapi => { error => "Something went wrong. check the logs." } | 
            
              | 404 |         ); | 
        
          | 405 |     }; | 378 |     }; | 
        
          | 406 | } | 379 | } | 
        
          | 407 |  | 380 |  |