From e643f79e98f4647b6c1c872c67d8fb071a0b5a46 Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@theke.io>
Date: Thu, 4 Mar 2021 06:43:01 -0300
Subject: [PATCH] Bug 27855: Make GET /patrons/:patron_id use objects.find

This patch makes the route for fetching a patron use the objects.find
helper instead of a plain Koha::Patrons->find. This gives the controller
embedding superpowers.

To test, we just need to check nothing broke:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/patrons.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
---
 Koha/REST/V1/Patrons.pm | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/Koha/REST/V1/Patrons.pm b/Koha/REST/V1/Patrons.pm
index f82af2c8f9..8c63705474 100644
--- a/Koha/REST/V1/Patrons.pm
+++ b/Koha/REST/V1/Patrons.pm
@@ -73,13 +73,19 @@ sub get {
 
     return try {
         my $patron_id = $c->validation->param('patron_id');
-        my $patron    = Koha::Patrons->find($patron_id);
+        my $patron    = $c->objects->find( Koha::Patrons->new, $patron_id );
 
         unless ($patron) {
-            return $c->render( status => 404, openapi => { error => "Patron not found." } );
+            return $c->render(
+                status  => 404,
+                openapi => { error => "Patron not found." }
+            );
         }
 
-        return $c->render( status => 200, openapi => $patron->to_api );
+        return $c->render(
+            status  => 200,
+            openapi => $patron
+        );
     }
     catch {
         $c->unhandled_exception($_);
-- 
2.20.1