From 2c76c8b6e13d0f2bf113e1cd79aed7ec33e49e34 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Tue, 16 Aug 2016 13:37:29 +0300 Subject: [PATCH] Bug 17008: Fix current data types This patch changes current Swagger definitions for patrons and holds to have data types corresponding to column data types in their database tables. To test: 1. GET http://yourlibrary/api/v1/patrons/YYY where YYY is existing borrowernumber 2. Observe that numbers / integers are in string data type. 3. Apply this patch 4. Repeat step 1. 5. Observe that numbers / integers are now actually numbers / integers. --- Koha/REST/V1/Hold.pm | 12 ++++++------ Koha/REST/V1/Patron.pm | 4 ++-- api/v1/swagger/definitions/hold.json | 16 +++++++++++++++- api/v1/swagger/definitions/patron.json | 21 +++++++++++++-------- api/v1/swagger/x-primitives.json | 11 ++++------- 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/Koha/REST/V1/Hold.pm b/Koha/REST/V1/Hold.pm index 7f0b1ff..9410396 100644 --- a/Koha/REST/V1/Hold.pm +++ b/Koha/REST/V1/Hold.pm @@ -34,9 +34,9 @@ sub list { foreach my $key (keys %$params) { delete $params->{$key} unless grep { $key eq $_ } @valid_params; } - my $holds = Koha::Holds->search($params)->unblessed; + my $holds = Koha::Holds->search($params); - return $c->$cb($holds, 200); + return $c->$cb($holds->swaggerize, 200); } sub add { @@ -106,9 +106,9 @@ sub add { }, 500); } - my $reserve = C4::Reserves::GetReserve($reserve_id); + my $reserve = Koha::Holds->find($reserve_id); - return $c->$cb($reserve, 201); + return $c->$cb($reserve->swaggerize, 201); } sub edit { @@ -138,9 +138,9 @@ sub edit { suspend_until => $suspend_until, }; C4::Reserves::ModReserve($params); - $reserve = C4::Reserves::GetReserve($reserve_id); + $reserve = Koha::Holds->find($reserve_id); - return $c->$cb($reserve, 200); + return $c->$cb($reserve->swaggerize, 200); } sub delete { diff --git a/Koha/REST/V1/Patron.pm b/Koha/REST/V1/Patron.pm index b97a154..6caa912 100644 --- a/Koha/REST/V1/Patron.pm +++ b/Koha/REST/V1/Patron.pm @@ -28,7 +28,7 @@ sub list { my $patrons = Koha::Patrons->search; - $c->$cb($patrons->unblessed, 200); + $c->$cb($patrons->swaggerize, 200); } sub get { @@ -41,7 +41,7 @@ sub get { return $c->$cb({error => "Patron not found"}, 404); } - return $c->$cb($patron->unblessed, 200); + return $c->$cb($patron->swaggerize, 200); } 1; diff --git a/api/v1/swagger/definitions/hold.json b/api/v1/swagger/definitions/hold.json index 8703920..a1d82fa 100644 --- a/api/v1/swagger/definitions/hold.json +++ b/api/v1/swagger/definitions/hold.json @@ -8,51 +8,65 @@ "$ref": "../x-primitives.json#/borrowernumber" }, "reservedate": { + "type": ["string", "null"], "description": "the date the hold was placed" }, "biblionumber": { "$ref": "../x-primitives.json#/biblionumber" }, "branchcode": { - "$ref": "../x-primitives.json#/branchcode" + "type": ["string", "null"], + "description": "code of patron's home branch" }, "notificationdate": { + "type": ["string", "null"], "description": "currently unused" }, "reminderdate": { + "type": ["string", "null"], "description": "currently unused" }, "cancellationdate": { + "type": ["string", "null"], "description": "the date the hold was cancelled" }, "reservenotes": { + "type": ["string", "null"], "description": "notes related to this hold" }, "priority": { + "type": ["integer", "null"], "description": "where in the queue the patron sits" }, "found": { + "type": ["string", "null"], "description": "a one letter code defining what the status of the hold is after it has been confirmed" }, "timestamp": { + "type": "string", "description": "date and time the hold was last updated" }, "itemnumber": { "$ref": "../x-primitives.json#/itemnumber" }, "waitingdate": { + "type": ["string", "null"], "description": "the date the item was marked as waiting for the patron at the library" }, "expirationdate": { + "type": ["string", "null"], "description": "the date the hold expires" }, "lowestPriority": { + "type": "integer", "description": "" }, "suspend": { + "type": "integer", "description": "" }, "suspend_until": { + "type": ["string", "null"], "description": "" }, "itemtype": { diff --git a/api/v1/swagger/definitions/patron.json b/api/v1/swagger/definitions/patron.json index a021502..d16c43a 100644 --- a/api/v1/swagger/definitions/patron.json +++ b/api/v1/swagger/definitions/patron.json @@ -124,7 +124,8 @@ "description": "patron's date of birth" }, "branchcode": { - "$ref": "../x-primitives.json#/branchcode" + "type": "string", + "description": "code of patron's home branch" }, "categorycode": { "type": "string", @@ -139,11 +140,11 @@ "description": "date the patron's card is set to expire" }, "gonenoaddress": { - "type": ["string", "null"], + "type": ["integer", "null"], "description": "set to 1 if library marked this patron as having an unconfirmed address" }, "lost": { - "type": ["string", "null"], + "type": ["integer", "null"], "description": "set to 1 if library marked this patron as having lost his card" }, "debarred": { @@ -167,7 +168,7 @@ "description": "used for children to include title of guarantor" }, "guarantorid": { - "type": ["string", "null"], + "type": ["integer", "null"], "description": "borrowernumber used for children or professionals to link them to guarantor or organizations" }, "borrowernotes": { @@ -187,7 +188,7 @@ "description": "patron's encrypted password" }, "flags": { - "type": ["string", "null"], + "type": ["integer", "null"], "description": "a number associated with the patron's permissions" }, "userid": { @@ -251,15 +252,15 @@ "description": "the mobile phone number where the patron would like to receive notices (if SMS turned on)" }, "sms_provider_id": { - "type": ["string", "null"], + "type": ["integer", "null"], "description": "the provider of the mobile phone number defined in smsalertnumber" }, "privacy": { - "type": "string", + "type": "integer", "description": "patron's privacy settings related to their reading history" }, "privacy_guarantor_checkouts": { - "type": "string", + "type": "integer", "description": "controls if relatives can see this patron's checkouts" }, "checkprevcheckout": { @@ -269,6 +270,10 @@ "updated_on": { "type": "string", "description": "time of last change could be useful for synchronization with external systems (among others)" + }, + "lastseen": { + "type": ["string", "null"], + "description": "last time a patron has been seed (connected at the OPAC or staff interface)" } } } diff --git a/api/v1/swagger/x-primitives.json b/api/v1/swagger/x-primitives.json index ae8750e..969343b 100644 --- a/api/v1/swagger/x-primitives.json +++ b/api/v1/swagger/x-primitives.json @@ -1,16 +1,12 @@ { "biblionumber": { - "type": "string", + "type": "integer", "description": "internally assigned biblio identifier" }, "borrowernumber": { - "type": "string", + "type": "integer", "description": "internally assigned user identifier" }, - "branchcode": { - "type": ["string", "null"], - "description": "code of patron's home branch" - }, "cardnumber": { "type": ["string", "null"], "description": "library assigned user identifier" @@ -24,7 +20,7 @@ "description": "patron's first name" }, "itemnumber": { - "type": ["string", "null"], + "type": ["integer", "null"], "description": "internally assigned item identifier" }, "phone": { @@ -32,6 +28,7 @@ "description": "primary phone number for patron's primary address" }, "reserve_id": { + "type": "integer", "description": "Internal hold identifier" }, "surname": { -- 1.9.1