Context
I have a record with a field that is of type Day
(which corresponds to a field with type DATE
in my Postgresql database). I have a Create action which works fine (records are saved to the database). However, from the Create action, if I try to redirect to another action and pass in the field with type Day
like:
-- PostsController.hs
action CreatePostAction = do
let post = newRecord @Post
post
|> buildPost
|> ifValid \case
Left post -> do
render NewView { .. }
Right post -> do
let date1 = get #date1 post
redirectTo SomeAction { .. }
I get this error:
Query parameter "date1" needs to be a "UUID" but got "2021-10-16"
Routing failed with: BadType {expectedType = "UUID", value = Just "2021-10-23", field = "date1"}
even though SomeAction
's param type is Day
:
-- Types.hs
data PostsController = SomeAction { date1 :: Day }
Question
Why is the error thrown? And why is the expected type UUID when it should be Day?
CodePudding user response:
IHP's AutoRoute only works with the following data types:
- Text
- [Text]
- Maybe Text
- Int
- [Int]
- Maybe Int
- Id
You can find more details in the docs: https://ihp.digitallyinduced.com/Guide/routing.html#parameter-types
I suggest that you use SomeAction { date1 :: Text }
as a workaround. You could also use SomeAction
without any explicit args and then access the date using param
like this:
action SomeAction = do
let date1 :: Day = param "date1"