Closed ronslow closed 8 years ago
getBooking = mkIdHandler jsonO handler where
handler :: () -> BookingId -> ExceptT (Reason Void) WithBookingId (Maybe Booking)
handler _ bid = lift handler'
handler' :: WithBookingId (Maybe Booking)
handler' = do
bid <- ask
lift $ handler'' bid
handler'' :: BookingId -> DiaryApi (Maybe Booking)
handler'' bid = do
diary <- DiaryApi ask
liftIO $ query diary (AS.GetBooking bid)
The moral of the story was of course to subdivide the problem into typechecked definitions and then use the typechecker to guide to the solution
Sorry for not responding sooner to this, good to see you found the solution (lift ask
).
I am following rest-examples, simplifying, and building a service to return a single Booking, identified by BookingId, from an (AcidState Diary)
The problem line of course lifts the diary into a ExceptT (Reason Void) BookingApi Booking monad, whereas I need it to be inside an ExceptT (Reason Void) WithBookingId Booking monad
Am I going about this in the right way? Is it correct to nest ReaderT in this way for subresources?
Robert