Skip to content

Commit

Permalink
more info on add service
Browse files Browse the repository at this point in the history
  • Loading branch information
mamico committed Aug 1, 2024
1 parent 2373994 commit cd50623
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src/design/plone/ioprenoto/restapi/services/booking/add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# TODO: il codice qui è temporaneo, va spostato in redturtle.prenotazioni
# di conseguenza l'implementazione si semplifica

from plone import api
from redturtle.prenotazioni.interfaces import ISerializeToPrenotazioneSearchableItem
from redturtle.prenotazioni.restapi.services.booking.add import (
AddBooking as BaseAddBooking,
)
from zope.component import getMultiAdapter


class AddBooking(BaseAddBooking):
def reply(self):
result = super().reply()
catalog = api.portal.get_tool("portal_catalog")
uid = result["UID"]
booking = catalog.unrestrictedSearchResults(UID=uid)[0]._unrestrictedGetObject()

response = getMultiAdapter(
(booking, self.request), ISerializeToPrenotazioneSearchableItem
)(fullobjects=True)

# BBB:
response["UID"] = response["booking_id"]
response["@type"] = booking.portal_type
response["gate"] = response["booking_gate"]
response["id"] = response["@id"].split("/")[-1]
response["booking_folder_uid"] = (
response["booking_folder"]["uid"] if "booking_folder" in response else None
)
if "notify_on_confirm" not in response:
prenotazioni_folder = booking.getPrenotazioniFolder()
response["notify_on_confirm"] = prenotazioni_folder.notify_on_confirm
return response
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@
name="@booking"
/>

<plone:service
method="POST"
factory=".add.AddBooking"
for="redturtle.prenotazioni.content.prenotazioni_folder.IPrenotazioniFolder"
permission="zope2.View"
name="@booking"
layer="design.plone.ioprenoto.interfaces.IDesignPloneIoprenotoLayer"
/>

</configure>
11 changes: 9 additions & 2 deletions src/design/plone/ioprenoto/restapi/services/booking/get.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# TODO: il codice qui è temporaneo, va spostato in redturtle.prenotazioni

from redturtle.prenotazioni.restapi.services.booking.get import BookingInfo as Base
from AccessControl import Unauthorized
from plone import api
from zope.component import getMultiAdapter
from redturtle.prenotazioni.interfaces import ISerializeToPrenotazioneSearchableItem
from redturtle.prenotazioni.restapi.services.booking.get import BookingInfo as Base
from zope.component import getMultiAdapter


class BookingInfo(Base):
Expand Down Expand Up @@ -50,6 +50,13 @@ def reply(self):
)(fullobjects=True)

# BBB:
response["UID"] = response["booking_id"]
response["@type"] = booking.portal_type
response["gate"] = response["booking_gate"]
response["id"] = response["@id"].split("/")[-1]
response["booking_folder_uid"] = (
response["booking_folder"]["uid"] if "booking_folder" in response else None
)
if "notify_on_confirm" not in response:
prenotazioni_folder = booking.getPrenotazioniFolder()
response["notify_on_confirm"] = prenotazioni_folder.notify_on_confirm
Expand Down
9 changes: 9 additions & 0 deletions src/design/plone/ioprenoto/tests/test_booking_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ def test_get_bookings(self):
)
self.assertEqual(res.status_code, 200)
booking = res.json()
self.assertEqual(
booking["booking_folder"]["@id"],
self.prenotazioni_folder.absolute_url(),
)
self.assertEqual(booking["booking_address"]["@id"], self.venue.absolute_url())
self.assertEqual(
booking["booking_office"]["@id"],
self.unita_organizzativa.absolute_url(),
)

res = self.api_session.get(
self.portal.absolute_url() + "/@bookings?fullobjects=1"
Expand Down

0 comments on commit cd50623

Please sign in to comment.