Bug 16826 - REST API: Add API routes for getting item availability and holdability
Summary: REST API: Add API routes for getting item availability and holdability
Status: Failed QA
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Arthur Suzuki
QA Contact:
URL:
Keywords:
: 13927 (view as bug list)
Depends on: 17712 16825
Blocks: 18103 16652 23449
  Show dependency treegraph
 
Reported: 2016-06-28 14:58 UTC by Lari Taskula
Modified: 2023-09-11 15:29 UTC (History)
10 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 16826: Add API route for getting item availability (33.89 KB, patch)
2016-07-11 15:33 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (33.83 KB, patch)
2016-07-11 16:29 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (47.06 KB, patch)
2016-07-13 13:30 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (46.65 KB, patch)
2016-07-25 10:12 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (46.59 KB, patch)
2016-07-25 10:36 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (46.28 KB, patch)
2016-07-29 15:20 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (46.29 KB, patch)
2016-08-01 09:15 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (46.52 KB, patch)
2016-08-01 09:27 UTC, Jiri Kozlovsky
Details | Diff | Splinter Review
Bug 16826: [QA Follow-up] Add 'new_status' to Swagger definition (1.47 KB, patch)
2016-08-02 18:59 UTC, Jiri Kozlovsky
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (46.33 KB, patch)
2016-08-05 15:05 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (48.07 KB, patch)
2016-10-11 07:55 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (48.07 KB, patch)
2016-10-11 07:58 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (48.08 KB, patch)
2016-10-11 08:01 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (47.96 KB, patch)
2016-10-12 14:35 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (48.00 KB, patch)
2016-11-07 16:03 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add API route for getting item availability (48.52 KB, patch)
2016-11-08 13:26 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add Koha::Item::Availabilit(y/ies) for item availability (26.81 KB, patch)
2016-11-09 10:45 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add REST endpoint for displaying item availabilities (20.30 KB, patch)
2016-11-09 10:45 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add REST endpoint for displaying item availabilities (20.34 KB, patch)
2016-11-09 11:04 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add REST endpoint for displaying item availabilities (24.91 KB, patch)
2016-11-09 11:24 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Add REST endpoint for displaying item availabilities (25.47 KB, patch)
2016-11-09 11:27 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Availability Swagger definitions (22.30 KB, patch)
2016-12-27 16:56 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Swaggerize Koha::Availability objects (5.99 KB, patch)
2016-12-27 16:57 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Controllers for availability (10.96 KB, patch)
2016-12-27 16:59 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Availability Swagger definitions (26.18 KB, patch)
2017-02-13 12:34 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Swaggerize Koha::Availability objects (5.99 KB, patch)
2017-02-13 12:34 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Controllers for availability (10.96 KB, patch)
2017-02-13 12:35 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Controllers for availability (38.74 KB, patch)
2017-02-14 17:03 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Controllers for availability (27.50 KB, patch)
2017-02-14 17:09 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Availability Swagger definitions (26.41 KB, patch)
2017-02-15 16:21 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Swaggerize Koha::Availability objects (6.50 KB, patch)
2017-02-15 16:22 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: Controllers for availability (27.50 KB, patch)
2017-02-15 16:22 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 16826: (follow-up, squashable) Remove warnings (883 bytes, patch)
2017-04-26 12:42 UTC, Lari Taskula
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Lari Taskula 2016-06-28 14:58:47 UTC
Add API routes for getting item availability and holdability. Holdability check requires a target borrower (either user himself or borrowernumber).

I'm thinking of following endpoints:
GET /api/v1/items/{itemnumber}/availability
GET /api/v1/items/{itemnumber}/holdability                   For myself
GET /api/v1/items/{itemnumber}/holdability?borrowernumber=X  For X

Terms:
- availability: Does not require login or permissions. Makes a simple check if item is in a valid state for holdings. In other words, check "notforloan", "onloan", "itemlost", "withdrawn", "damaged".
- holdability: Requires login and also catalogue permission if the request is made for another borrowernumber than myself. Item is holdable if it is available and if it satisfies IsAvailableForItemLevelRequest and CanItemBeReserved in C4::Reserves + (also debarments and fines?)
Comment 1 Lari Taskula 2016-07-05 14:23:13 UTC
After thinking this issue further and researching other availability definitions that we have in Koha, I think the above definition of availability is confusing and misleading, and routes are not good. Availability is more broad term than what described in the first post, for example item can be available for in-house use but not for checkouts, and by using these routes, this kind of information should also be presented. I'm open to ideas :)
Comment 2 Jiri Kozlovsky 2016-07-05 17:50:03 UTC
How about returning JSON with all the values possible?

Let's say for availability:
{ in_house: true, checkout: false }
Comment 3 Lari Taskula 2016-07-11 15:33:57 UTC Comment hidden (obsolete)
Comment 4 Lari Taskula 2016-07-11 16:26:44 UTC
(In reply to Jiří Kozlovský from comment #2)
> How about returning JSON with all the values possible?
> 
> Let's say for availability:
> { in_house: true, checkout: false }
I think this is a good option for showing different types of availabilities.

Anyway, to start pushing this feature forward, I wanted to upload a patch containing my current progress. It has the problem that I was thinking about earlier. For example the patch above considers an item with "notforloan" status as unavailable, while it could still be for reading room use. Btw, is this the definition of in-house use? Also, what other cases should we consider? I could modify this patch to better inform the different types of availabilities. Before that, it would be great to have input from others as well :)
Comment 5 Lari Taskula 2016-07-11 16:29:24 UTC Comment hidden (obsolete)
Comment 6 Lari Taskula 2016-07-13 12:39:00 UTC
How about something like this for general/anonymous availability? 

GET /availability/items?itemnumber=2225

returns for example:
[{
  "barcode":"TEST000002",
  "biblioitemnumber":"629",
  "biblionumber":"629",
  "checkout": {
    "available":false,
    "description":["notforloan","reserved"],
    "expected_available":null
  },
  "hold_queue_length":1,
  "holdingbranch":"CPL",
  "homebranch":"FFL",
  "itemcallnumber":"782.42166092",
  "itemnumber":"2225",
  "local_use": {
    "available":false,
    "description":["reserved"],
    "expected_available":null
   },
  "location":"some_location",
  "onsite_checkout": {
    "available":false,
    "description":["onsite_checkouts_disabled"],
    "expected_available":null
  }
}]
((+add hold-availability) In this example local_use = checkout with ignoring notforloan, and onsite_checkout = OnSiteCheckouts syspref ? (local_use ? true:false):false)

Anyway, what about when checking availability for a specific patron? Is it better to use the same route or use a completely different route? The reason I consider separation between anonymous availability and logged-in availability is my fear that this endpoint will be super busy, and availability for a specific patron is probably a heavy operation. On the other hand, if I used this route, I think I would just want one route with always giving me the correct availability status (checkout, hold, local_use, onsite_checkout etc) for an item, regardless of me being logged-in or not. Opinions are welcome.
Comment 7 Lari Taskula 2016-07-13 13:30:37 UTC Comment hidden (obsolete)
Comment 8 Lari Taskula 2016-07-25 10:12:42 UTC Comment hidden (obsolete)
Comment 9 Lari Taskula 2016-07-25 10:36:38 UTC Comment hidden (obsolete)
Comment 10 Lari Taskula 2016-07-29 15:20:22 UTC Comment hidden (obsolete)
Comment 11 Jiri Kozlovsky 2016-07-31 10:27:38 UTC
It works for me so far. Are you going to do any further changes to this bug or you are willing to mark it as Needs Signoff?

All tests passed for me, so I could sign this off.
Comment 12 Jiri Kozlovsky 2016-08-01 05:47:19 UTC
How about returning the due_date of current checkout so that user can create better idea when it'll be available for him?

I know you already include "expected_available", which is nice, but when there is also a hold on checkedout item, there is empty value in it.

What do you think?
Comment 13 Lari Taskula 2016-08-01 09:14:13 UTC
(In reply to Jiří Kozlovský from comment #11)
> It works for me so far. Are you going to do any further changes to this bug
> or you are willing to mark it as Needs Signoff?
I could mark it as Needs Signoff, maybe it will initiate some more interest on this :)

(In reply to Jiří Kozlovský from comment #12)
> I know you already include "expected_available", which is nice, but when
> there is also a hold on checkedout item, there is empty value in it.
Thanks Jiří, good catch! Updating the patch to fix this.
Comment 14 Lari Taskula 2016-08-01 09:15:24 UTC Comment hidden (obsolete)
Comment 15 Jiri Kozlovsky 2016-08-01 09:27:42 UTC Comment hidden (obsolete)
Comment 16 Jiri Kozlovsky 2016-08-01 09:28:39 UTC
(In reply to Lari Taskula from comment #14)
> Created attachment 53826 [details] [review] [review]
> Bug 16826: Add API route for getting item availability
> 
> Fixes missing "expected_available" from checkout-availability if the item
> has holds.

Now it works as expected, nice job!
Comment 17 Jiri Kozlovsky 2016-08-02 18:59:17 UTC Comment hidden (obsolete)
Comment 18 Jiri Kozlovsky 2016-08-02 19:01:16 UTC
Comment on attachment 53922 [details] [review]
Bug 16826: [QA Follow-up] Add 'new_status' to Swagger definition

Sorry about this patch, I've messed up bug id - had to be 16825 instead of 16826.
Comment 19 Lari Taskula 2016-08-05 15:05:36 UTC
Created attachment 54053 [details] [review]
Bug 16826: Add API route for getting item availability

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>

Fixed small mistakes in documentation and removed itemnumberPathParam from Swagger;
it belongs to Bug 16825.
Comment 20 Lari Taskula 2016-10-11 07:55:51 UTC
Created attachment 56128 [details] [review]
Bug 16826: Add API route for getting item availability

GET /availability/items?itemnumber=123
GET /availability/items?itemnumber=123+456+789
GET /availability/items?biblionumber=321
GET /availability/items?biblionumber=321+654+987

This patch adds above routes for checking anonymous item availability. Patron
status is not checked.

The returned data is for example:
{
  "checkout": {
     "available": false,
     "description": ["onloan"],
     "expected_available": "2016-07-13"
  },
  "hold": {
     "available": true,
     "description": [],
     "expected_available": null
  },
  "local_use": {
     "available": false,
     "description": ["onloan"],
     "expected_available": "2016-07-13"
  },
  "onsite_checkout": {
     "available": false,
     "description": ["onsite_checkouts_disabled"],
     "expected_available": null
  },
  "hold_queue_length": 1,
  + some basic item information on locations, bib/bib(item)numbers etc.
}

Possible values in availability description are an empty array and any of:
"onloan", "reserved", "damaged", "withdrawn", "itemlost", "restricted",
"notforloan", "ordered". (+"onsite_checkouts_disabled" for onsite_checkout)

To test:
1. Apply patch and run minifySwagger.pl
   perl misc/devel/minifySwagger.pl -s api/v1/swagger/swagger.json -d api/v1/swagger
2. Play around with an item. Place a hold on it, checkout, set it damaged etc.
3. Make GET requests to /api/v1/availability/items?itemnumber=YYY, where
   YYY is an existing itemnumber. You can also try with biblionumber=XXX
   query parameter, where XXX is an existing biblionumber.
4. Check that the availability statuses are correct and that availability
   description lists the appropriate status for unavailability.
5. Repeat steps 1-3 until you are confident the route works as expected.
6. Run the following tests:
   - t/Koha/Item/Availability.t
   - t/db_dependent/Items.t
   - t/db_dependent/api/v1/availability.t

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>
Comment 21 Lari Taskula 2016-10-11 07:56:22 UTC
Rebased on top of master.
Comment 22 Lari Taskula 2016-10-11 07:58:12 UTC
Created attachment 56129 [details] [review]
Bug 16826: Add API route for getting item availability

Fixing typo in test plan. This plan applies:

To test:
1. Apply patch and run minifySwagger.pl
   perl misc/devel/minifySwagger.pl -s api/v1/swagger/swagger.json -d api/v1/swagger
2. Play around with an item. Place a hold on it, checkout, set it damaged etc.
3. Make GET requests to /api/v1/availability/items?itemnumber=YYY, where
   YYY is an existing itemnumber. You can also try with biblionumber=XXX
   query parameter, where XXX is an existing biblionumber.
4. Check that the availability statuses are correct and that availability
   description lists the appropriate status for unavailability.
5. Repeat steps 2-4 until you are confident the route works as expected.
6. Run the following tests:
   - t/Koha/Item/Availability.t
   - t/db_dependent/Items.t
   - t/db_dependent/api/v1/availability.t

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>
Comment 23 Lari Taskula 2016-10-11 08:01:42 UTC
Created attachment 56130 [details] [review]
Bug 16826: Add API route for getting item availability

Fixing one more typo in test plan:

To test:
1. Apply patch and run minifySwagger.pl
   perl misc/devel/minifySwagger.pl -s api/v1/swagger/swagger.json -d api/v1/swagger/swagger.min.json
2. Play around with an item. Place a hold on it, checkout, set it damaged etc.
3. Make GET requests to /api/v1/availability/items?itemnumber=YYY, where
   YYY is an existing itemnumber. You can also try with biblionumber=XXX
   query parameter, where XXX is an existing biblionumber.
4. Check that the availability statuses are correct and that availability
   description lists the appropriate status for unavailability.
5. Repeat steps 2-4 until you are confident the route works as expected.
6. Run the following tests:
   - t/Koha/Item/Availability.t
   - t/db_dependent/Items.t
   - t/db_dependent/api/v1/availability.t

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>
Comment 24 Lari Taskula 2016-10-12 14:35:58 UTC
Created attachment 56295 [details] [review]
Bug 16826: Add API route for getting item availability

GET /availability/items?itemnumber=123
GET /availability/items?itemnumber=123+456+789
GET /availability/items?biblionumber=321
GET /availability/items?biblionumber=321+654+987

This patch adds above routes for checking anonymous item availability. Patron
status is not checked.

The returned data is for example:
{
  "checkout": {
     "available": false,
     "description": ["onloan"],
     "expected_available": "2016-07-13"
  },
  "hold": {
     "available": true,
     "description": [],
     "expected_available": null
  },
  "local_use": {
     "available": false,
     "description": ["onloan"],
     "expected_available": "2016-07-13"
  },
  "onsite_checkout": {
     "available": false,
     "description": ["onsite_checkouts_disabled"],
     "expected_available": null
  },
  "hold_queue_length": 1,
  + some basic item information on locations, bib/bib(item)numbers etc.
}

Possible values in availability description are an empty array and any of:
"onloan", "reserved", "damaged", "withdrawn", "itemlost", "restricted",
"notforloan", "ordered". (+"onsite_checkouts_disabled" for onsite_checkout)

To test:
1. Apply patch
2. Play around with an item. Place a hold on it, checkout, set it damaged etc.
3. Make GET requests to /api/v1/availability/items?itemnumber=YYY, where
   YYY is an existing itemnumber. You can also try with biblionumber=XXX
   query parameter, where XXX is an existing biblionumber.
4. Check that the availability statuses are correct and that availability
   description lists the appropriate status for unavailability.
5. Repeat steps 2-4 until you are confident the route works as expected.
6. Run the following tests:
   - t/Koha/Item/Availability.t
   - t/db_dependent/Items.t
   - t/db_dependent/api/v1/availability.t

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>
Comment 25 Lari Taskula 2016-10-12 14:36:24 UTC
Removed minifying step from test plan after Bug 17432 was pushed.
Comment 26 Lari Taskula 2016-11-07 16:03:48 UTC
Created attachment 57271 [details] [review]
Bug 16826: Add API route for getting item availability

GET /availability/items?itemnumber=123
GET /availability/items?itemnumber=123+456+789
GET /availability/items?biblionumber=321
GET /availability/items?biblionumber=321+654+987

This patch adds above routes for checking anonymous item availability. Patron
status is not checked.

The returned data is for example:
{
  "checkout": {
     "available": false,
     "description": ["onloan"],
     "expected_available": "2016-07-13"
  },
  "hold": {
     "available": true,
     "description": [],
     "expected_available": null
  },
  "local_use": {
     "available": false,
     "description": ["onloan"],
     "expected_available": "2016-07-13"
  },
  "onsite_checkout": {
     "available": false,
     "description": ["onsite_checkouts_disabled"],
     "expected_available": null
  },
  "hold_queue_length": 1,
  + some basic item information on locations, bib/bib(item)numbers etc.
}

Possible values in availability description are an empty array and any of:
"onloan", "reserved", "damaged", "withdrawn", "itemlost", "restricted",
"notforloan", "ordered". (+"onsite_checkouts_disabled" for onsite_checkout)

To test:
1. Apply patch
2. Play around with an item. Place a hold on it, checkout, set it damaged etc.
3. Make GET requests to /api/v1/availability/items?itemnumber=YYY, where
   YYY is an existing itemnumber. You can also try with biblionumber=XXX
   query parameter, where XXX is an existing biblionumber.
4. Check that the availability statuses are correct and that availability
   description lists the appropriate status for unavailability.
5. Repeat steps 2-4 until you are confident the route works as expected.
6. Run the following tests:
   - t/Koha/Item/Availability.t
   - t/db_dependent/Items.t
   - t/db_dependent/api/v1/availability.t

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>
Comment 27 Lari Taskula 2016-11-08 13:26:20 UTC
Created attachment 57321 [details] [review]
Bug 16826: Add API route for getting item availability

GET /availability/items?itemnumber=123
GET /availability/items?itemnumber=123+456+789
GET /availability/items?biblionumber=321
GET /availability/items?biblionumber=321+654+987

This patch adds above routes for checking anonymous item availability. Patron
status is not checked.

The returned data is for example:
{
  "checkout": {
     "available": false,
     "description": ["onloan"],
     "expected_available": "2016-07-13"
  },
  "hold": {
     "available": true,
     "description": [],
     "expected_available": null
  },
  "local_use": {
     "available": false,
     "description": ["onloan"],
     "expected_available": "2016-07-13"
  },
  "onsite_checkout": {
     "available": false,
     "description": ["onsite_checkouts_disabled"],
     "expected_available": null
  },
  "hold_queue_length": 1,
  + some basic item information on locations, bib/bib(item)numbers etc.
}

Possible values in availability description are an empty array and any of:
"onloan", "reserved", "damaged", "withdrawn", "itemlost", "restricted",
"notforloan", "ordered". (+"onsite_checkouts_disabled" for onsite_checkout)

To test:
1. Apply patch
2. Play around with an item. Place a hold on it, checkout, set it damaged etc.
3. Make GET requests to /api/v1/availability/items?itemnumber=YYY, where
   YYY is an existing itemnumber. You can also try with biblionumber=XXX
   query parameter, where XXX is an existing biblionumber.
4. Check that the availability statuses are correct and that availability
   description lists the appropriate status for unavailability.
5. Repeat steps 2-4 until you are confident the route works as expected.
6. Run the following tests:
   - t/Koha/Item/Availability.t
   - t/db_dependent/Items.t
   - t/db_dependent/api/v1/availability.t

Signed-off-by: Jiri Kozlovsky <mail@jkozlovsky.cz>

Fixed a bug in finding existing holds. Added some more tests to cover it.
Comment 28 Lari Taskula 2016-11-09 10:45:29 UTC
Created attachment 57369 [details] [review]
Bug 16826: Add Koha::Item::Availabilit(y/ies) for item availability

This patch adds classes for calculating and storing item availability information.

Usage is simple, e.g. holdability;
my $item = Koha::Items->find(123);
my $holdability = $item->availabilities->hold;
if ($holdability->available) {
  # available for hold!
} else {
  # $holdability->description holds the reason for unavailability
}

To test:
1. Run t/db_dependent/Koha/Item/Availability.t
Comment 29 Lari Taskula 2016-11-09 10:45:53 UTC
Created attachment 57370 [details] [review]
Bug 16826: Add REST endpoint for displaying item availabilities

GET /availability/items?itemnumber=123
GET /availability/items?itemnumber=123+456+789
GET /availability/items?biblionumber=321
GET /availability/items?biblionumber=321+654+987

This patch adds above routes for checking anonymous item availability. Patron
status is not checked.

The returned data is for example:
{
  "checkout": {
     "available": false,
     "description": ["onloan"],
     "expected_available": "2016-07-13"
  },
  "hold": {
     "available": true,
     "description": [],
     "expected_available": null
  },
  "local_use": {
     "available": false,
     "description": ["onloan"],
     "expected_available": "2016-07-13"
  },
  "onsite_checkout": {
     "available": false,
     "description": ["onsite_checkouts_disabled"],
     "expected_available": null
  },
  "hold_queue_length": 1,
  + some basic item information on locations, bib/bib(item)numbers etc.
}

Possible values in availability description are an empty array and any of:
"onloan", "reserved", "damaged", "withdrawn", "itemlost", "restricted",
"notforloan", "ordered". (+"onsite_checkouts_disabled" for onsite_checkout)

To test:
1. Apply patch
2. Play around with an item. Place a hold on it, checkout, set it damaged etc.
3. Make GET requests to /api/v1/availability/items?itemnumber=YYY, where
   YYY is an existing itemnumber. You can also try with biblionumber=XXX
   query parameter, where XXX is an existing biblionumber.
4. Check that the availability statuses are correct and that availability
   description lists the appropriate status for unavailability.
5. Repeat steps 2-4 until you are confident the route works as expected.
6. Run t/db_dependent/api/v1/availability.t
Comment 30 Lari Taskula 2016-11-09 10:57:21 UTC
I fixed some bugs that I found during testing, and also thought the old patch should be split into two; first for introducing new classes and the second for API. I hope this makes it a bit more understandable and easier to test. All availability logic was moved from Koha::Item to Koha::Item::Availabilities. I think this way is cleaner and we avoided previously added 170 lines of code from Koha::Item that could (and should) as well be in its own module. I left a simple link into Koha::Item, $item->availabilities that you can easily use for accessing availability data. Another way is to create a new Koha::Item::Availabilities object and passing $item for the constructor.

Also I added some useful item data in return JSON.

Since these updates changed a lot, I set this Bug back into Needs Signoff status.
Comment 31 Lari Taskula 2016-11-09 11:04:11 UTC
Created attachment 57371 [details] [review]
Bug 16826: Add REST endpoint for displaying item availabilities
Comment 32 Lari Taskula 2016-11-09 11:24:44 UTC
Created attachment 57373 [details] [review]
Bug 16826: Add REST endpoint for displaying item availabilities

Include missing Swagger spec files.
Comment 33 Lari Taskula 2016-11-09 11:27:00 UTC
Created attachment 57382 [details] [review]
Bug 16826: Add REST endpoint for displaying item availabilities

Include missing Swagger spec files part 2
Comment 34 Lari Taskula 2016-11-09 12:33:04 UTC
Checks for circulation rules and patron status will be delivered in follow-ups asap.
Comment 35 Lari Taskula 2016-12-27 16:56:49 UTC
Created attachment 58456 [details] [review]
Bug 16826: Availability Swagger definitions

GET /availability/biblio/hold
GET /availability/biblio/search
GET /availability/item/checkout
GET /availability/item/hold
GET /availability/item/search
Comment 36 Lari Taskula 2016-12-27 16:57:10 UTC
Created attachment 58457 [details] [review]
Bug 16826: Swaggerize Koha::Availability objects

Koha::Biblio::Availability->swaggerize
Koha::Item::Availability->swaggerize

Constructs a HASHref that contains all availability data to be returned in a JSON
object. Numifies numbers to be numbers instead of strings. E.g. biblio swaggerize

{
  "biblionumber": 1234,
  "availability": {
    "available": true,
    "notes": {
      "Patron::SomethingToNote": {
        "cool": 1
      }
    }
  },
  "item_availabilities": [
    {
      "itemnumber": 5678,
      "availability": {
        "available": false,
        "unavailabilities": {
          "Item::Withdrawn": {}
        }
      }
    }
  ]
}
Comment 37 Lari Taskula 2016-12-27 16:59:21 UTC
Created attachment 58458 [details] [review]
Bug 16826: Controllers for availability
Comment 38 Lari Taskula 2016-12-27 17:00:40 UTC
I added Bug 17712 as a dependency and attached new patches that use Koha::Availabiltiy to provide more detailed availability answer via REST API. I also marked the old patches obsolete.
Comment 39 Lari Taskula 2017-02-13 12:34:43 UTC
Created attachment 60155 [details] [review]
Bug 16826: Availability Swagger definitions

GET /availability/biblio/hold
GET /availability/biblio/search
GET /availability/item/checkout
GET /availability/item/hold
GET /availability/item/search
Comment 40 Lari Taskula 2017-02-13 12:34:57 UTC
Created attachment 60156 [details] [review]
Bug 16826: Swaggerize Koha::Availability objects

Koha::Biblio::Availability->swaggerize
Koha::Item::Availability->swaggerize

Constructs a HASHref that contains all availability data to be returned in a JSON
object. Numifies numbers to be numbers instead of strings. E.g. biblio swaggerize

{
  "biblionumber": 1234,
  "availability": {
    "available": true,
    "notes": {
      "Patron::SomethingToNote": {
        "cool": 1
      }
    }
  },
  "item_availabilities": [
    {
      "itemnumber": 5678,
      "availability": {
        "available": false,
        "unavailabilities": {
          "Item::Withdrawn": {}
        }
      }
    }
  ]
}
Comment 41 Lari Taskula 2017-02-13 12:35:10 UTC
Created attachment 60157 [details] [review]
Bug 16826: Controllers for availability
Comment 42 Lari Taskula 2017-02-14 17:03:33 UTC
Created attachment 60218 [details] [review]
Bug 16826: Controllers for availability

GET /availability/biblio/hold
GET /availability/biblio/search
GET /availability/item/checkout
GET /availability/item/hold
GET /availability/item/search

Includes API tests.

To test:
1. prove t/db_dependent/api/v1/availability.t
2. Use Swagger-UI or make direct GET requests to specified availability
   endpoints, and make sure the returned data looks ok.
Comment 43 Lari Taskula 2017-02-14 17:09:44 UTC
Created attachment 60219 [details] [review]
Bug 16826: Controllers for availability

GET /availability/biblio/hold
GET /availability/biblio/search
GET /availability/item/checkout
GET /availability/item/hold
GET /availability/item/search

Includes API tests.

To test:
1. prove t/db_dependent/api/v1/availability.t
2. Use Swagger-UI or make direct GET requests to specified availability
   endpoints, and make sure the returned data looks ok.
Comment 44 Lari Taskula 2017-02-15 16:21:54 UTC
Created attachment 60267 [details] [review]
Bug 16826: Availability Swagger definitions

GET /availability/biblio/hold
GET /availability/biblio/search
GET /availability/item/checkout
GET /availability/item/hold
GET /availability/item/search
Comment 45 Lari Taskula 2017-02-15 16:22:07 UTC
Created attachment 60268 [details] [review]
Bug 16826: Swaggerize Koha::Availability objects

Koha::Biblio::Availability->swaggerize
Koha::Item::Availability->swaggerize

Constructs a HASHref that contains all availability data to be returned in a JSON
object. Numifies numbers to be numbers instead of strings. E.g. biblio swaggerize

{
  "biblionumber": 1234,
  "availability": {
    "available": true,
    "notes": {
      "Patron::SomethingToNote": {
        "cool": 1
      }
    }
  },
  "item_availabilities": [
    {
      "itemnumber": 5678,
      "availability": {
        "available": false,
        "unavailabilities": {
          "Item::Withdrawn": {}
        }
      }
    }
  ]
}
Comment 46 Lari Taskula 2017-02-15 16:22:21 UTC
Created attachment 60269 [details] [review]
Bug 16826: Controllers for availability

GET /availability/biblio/hold
GET /availability/biblio/search
GET /availability/item/checkout
GET /availability/item/hold
GET /availability/item/search

Includes API tests.

To test:
1. prove t/db_dependent/api/v1/availability.t
2. Use Swagger-UI or make direct GET requests to specified availability
   endpoints, and make sure the returned data looks ok.
Comment 47 Lari Taskula 2017-04-26 12:42:39 UTC
Created attachment 62727 [details] [review]
Bug 16826: (follow-up, squashable) Remove warnings

Squash to Swaggerize Koha::Availability objects
Comment 48 Jiri Kozlovsky 2017-08-27 23:07:10 UTC
Changing this to Needs Sign-off (I can see no discussion in here)

Btw Lari, nice job !
Comment 49 Tomás Cohen Arazi 2017-09-25 12:51:42 UTC
I don't agree with the proposed endpoints layout. I belive we should have /items/{item_id}/availability instead.

The ->swaggerize methods aren't needed anymore as Koha::Object(s) implement the TO_JSON method with similar behaviour. This was obviously written before the TO_JSON addition.
Comment 50 Julian Maurice 2018-09-21 08:21:08 UTC
(In reply to Tomás Cohen Arazi from comment #49)
> I don't agree with the proposed endpoints layout. I belive we should have
> /items/{item_id}/availability instead.
> 
> The ->swaggerize methods aren't needed anymore as Koha::Object(s) implement
> the TO_JSON method with similar behaviour. This was obviously written before
> the TO_JSON addition.

Looks like it's Failed QA then ?

Also, it would be nice to have more opinions on what the endpoints should be (/availability/object vs /object/availability)
Comment 51 Tomás Cohen Arazi 2018-09-21 12:23:54 UTC
(In reply to Julian Maurice from comment #50)
> (In reply to Tomás Cohen Arazi from comment #49)
> > I don't agree with the proposed endpoints layout. I belive we should have
> > /items/{item_id}/availability instead.
> > 
> > The ->swaggerize methods aren't needed anymore as Koha::Object(s) implement
> > the TO_JSON method with similar behaviour. This was obviously written before
> > the TO_JSON addition.
> 
> Looks like it's Failed QA then ?

Yes.

> Also, it would be nice to have more opinions on what the endpoints should be
> (/availability/object vs /object/availability)

I agree! It really depends on how it is going to be used.
Comment 52 Nick Clemens 2018-10-24 10:35:45 UTC
HI Lari, I just wanted to mention bug 21116 - tcohen worked on this as a way of prototyping new endpoints so the structures could be worked out a bit more before adding them to Koha - might be useful here or elsewhere
Comment 53 Lari Taskula 2020-03-17 21:18:21 UTC
I'm no longer able to work on this, so I'm setting assignee to default. Feel free to continue this work.
Comment 54 Julian Maurice 2020-05-22 09:35:10 UTC
*** Bug 13927 has been marked as a duplicate of this bug. ***
Comment 55 David Cook 2023-05-16 04:50:13 UTC
I'd love to revisit this.

For now, I'm planning to look at https://github.com/NatLibFi/koha-plugin-rest-di since the folk in Finland have been kind enough to make their work available there!
Comment 56 Martin Renvoize 2023-05-16 05:53:46 UTC
I took a short cut to add an availability endpoint in bug 23336 but I'd love to see a more thorough treatment done longer term. The availability code needs a cleanup along the lines of what NatLibFi do I believe but I didn't have the sponsorship to go the distance that way.

Happy to help though
Comment 57 David Cook 2023-05-17 01:23:23 UTC
(In reply to Martin Renvoize from comment #56)
> I took a short cut to add an availability endpoint in bug 23336 but I'd love
> to see a more thorough treatment done longer term. The availability code
> needs a cleanup along the lines of what NatLibFi do I believe but I didn't
> have the sponsorship to go the distance that way.

I've been wondering a bit if the word "availability" means different things to different people as well. 

For me, I'm interested in the "Status" message that we see on the OPAC. Is that the same thing needed for the checkout or is it a bit different?
Comment 58 David Cook 2023-05-17 06:49:29 UTC
(In reply to David Cook from comment #55)
> I'd love to revisit this.
> 
> For now, I'm planning to look at
> https://github.com/NatLibFi/koha-plugin-rest-di since the folk in Finland
> have been kind enough to make their work available there!

I've just been talking to Ere on Zoom. I'm going to use the plugin API for now while I do a demo for a library, and if that goes well, then I'd be interested in working with Ere and anyone else (Tomas? Martin?) who want to help move this into core Koha.
Comment 59 Katrin Fischer 2023-09-09 21:33:30 UTC
(In reply to David Cook from comment #58)
> (In reply to David Cook from comment #55)
> > I'd love to revisit this.
> > 
> > For now, I'm planning to look at
> > https://github.com/NatLibFi/koha-plugin-rest-di since the folk in Finland
> > have been kind enough to make their work available there!
> 
> I've just been talking to Ere on Zoom. I'm going to use the plugin API for
> now while I do a demo for a library, and if that goes well, then I'd be
> interested in working with Ere and anyone else (Tomas? Martin?) who want to
> help move this into core Koha.

How did it go?
Comment 60 David Cook 2023-09-11 03:52:40 UTC
(In reply to Katrin Fischer from comment #59)
> How did it go?

I've had a few issues with the plugin, but Ere and I have worked on them. 

Overall, I don't have anyone actively using the integration I was working on that needed the plugin, so it hasn't advanced since May/June.
Comment 61 Martin Renvoize 2023-09-11 15:29:27 UTC
We add a 'get_availability' API in bug 23336.  It was initially inspired by the work in the aforementioned plugin, however the scope was narrowed.. It would be great to continue that work to clean up the availability calculations and migrate them into Koha:: namespace asap.