https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43494
--- Comment #2 from Martin Renvoize (ashimema) <[email protected]> --- Created attachment 205408 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205408&action=edit Bug 43494: Add REST API CRUD for library opening hours Adds a dedicated /libraries/{library_id}/opening_hours sub-resource (list/add/get/update/delete), following Koha::REST::V1::Libraries:: Calendar::WeeklyClosures's shape exactly: raw, editable rows including type and closes_opening_id, a type_description read-only convenience field resolved from the OPENING_HOURS_TYPE authorised value, and a ?type= filter on the list endpoint (handled for free by objects->search once declared as a query parameter). Business-rule violations raised by Koha::Library::OpeningHours::Slot->store (weekday range, at least one of open_time/close_time, unknown type, invalid closes_opening_id) surface as 400 bad_parameter rather than an unhandled 500. Also adds a read-only /libraries/{library_id}/opening_hours_resolved view exposing resolved_intervals() directly - closes_opening_id links already resolved server-side - for consumers that just want "when is the library open" without reimplementing that logic. Kept as a separate top-level path rather than nested under /opening_hours/ to avoid route ambiguity with the {opening_hour_id} placeholder. A public counterpart, /public/libraries/{library_id}/opening_hours_resolved, reuses the same controller method with no x-koha-authorization block, following the existing /public/libraries pattern (publicness is determined by the /public/ namespace prefix, not by permission settings) - needed so the OPAC or other unauthenticated consumers can display a library's hours without staff credentials. Fixes a real bug surfaced while writing the add() test: Slot->store computed the effective type (falling back to GENERAL) only to validate it, without writing it back onto the in-memory object, so a freshly POSTed slot with no explicit type came back with type => null in the response even though the row was correctly stored as GENERAL in the database - the DB column default was never re-read back into the object. store() now assigns the resolved value onto $self before persisting. Test plan: 1. prove t/db_dependent/api/v1/libraries_opening_hours.t 2. yarn build && restart_all, then exercise the endpoints directly, e.g.: GET /api/v1/libraries/{id}/opening_hours GET /api/v1/libraries/{id}/opening_hours?type=SELF_SERVICE POST /api/v1/libraries/{id}/opening_hours GET /api/v1/libraries/{id}/opening_hours/{opening_hour_id} PUT /api/v1/libraries/{id}/opening_hours/{opening_hour_id} DELETE /api/v1/libraries/{id}/opening_hours/{opening_hour_id} GET /api/v1/libraries/{id}/opening_hours_resolved GET /api/v1/public/libraries/{id}/opening_hours_resolved (no auth needed) 3. prove t/db_dependent/Koha/Library/OpeningHours.t t/db_dependent/Koha/Library.t t/db_dependent/Circulation/CalcDateDue.t t/db_dependent/api/v1/libraries_calendar.t t/db_dependent/api/v1/libraries.t to confirm no regressions. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug. _______________________________________________ Koha-bugs mailing list -- [email protected] To unsubscribe send an email to [email protected] website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
