From 3e479c2e5f56de9ef1c6cc2f83f93394223f5689 Mon Sep 17 00:00:00 2001
From: Lari Taskula <larit@student.uef.fi>
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 and minify swagger.json
perl misc/devel/minifySwagger.pl -s api/v1/swagger/swagger.json -d api/v1/swagger/swagger.min.json
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 | 13 +++++++++++++
api/v1/swagger/definitions/patron.json | 18 +++++++++++-------
api/v1/swagger/x-primitives.json | 7 ++++---
5 files changed, 36 insertions(+), 18 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..7877aae 100644
--- a/api/v1/swagger/definitions/hold.json
+++ b/api/v1/swagger/definitions/hold.json
@@ -8,6 +8,7 @@
"$ref": "../x-primitives.json#/borrowernumber"
},
"reservedate": {
+ "type": ["string", "null"],
"description": "the date the hold was placed"
},
"biblionumber": {
@@ -17,42 +18,54 @@
"$ref": "../x-primitives.json#/branchcode"
},
"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..50259f9 100644
--- a/api/v1/swagger/definitions/patron.json
+++ b/api/v1/swagger/definitions/patron.json
@@ -139,11 +139,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 +167,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 +187,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 +251,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 +269,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..42820bf 100644
--- a/api/v1/swagger/x-primitives.json
+++ b/api/v1/swagger/x-primitives.json
@@ -1,10 +1,10 @@
{
"biblionumber": {
- "type": "string",
+ "type": "integer",
"description": "internally assigned biblio identifier"
},
"borrowernumber": {
- "type": "string",
+ "type": "integer",
"description": "internally assigned user identifier"
},
"branchcode": {
@@ -24,7 +24,7 @@
"description": "patron's first name"
},
"itemnumber": {
- "type": ["string", "null"],
+ "type": ["integer", "null"],
"description": "internally assigned item identifier"
},
"phone": {
@@ -32,6 +32,7 @@
"description": "primary phone number for patron's primary address"
},
"reserve_id": {
+ "type": "integer",
"description": "Internal hold identifier"
},
"surname": {
--
1.9.1