module IHP.IDE.CodeGen.ActionGenerator (buildPlan) where
import IHP.Prelude
import qualified Data.Text as Text
import IHP.IDE.CodeGen.Types
import qualified IHP.IDE.SchemaDesigner.Parser as SchemaDesigner
import IHP.IDE.SchemaDesigner.Types
import qualified IHP.IDE.CodeGen.ViewGenerator as ViewGenerator
data ActionConfig = ActionConfig
{ ActionConfig -> Text
controllerName :: Text
, ActionConfig -> Text
applicationName :: Text
, ActionConfig -> Text
modelName :: Text
, ActionConfig -> Text
actionName :: Text
} deriving (ActionConfig -> ActionConfig -> Bool
(ActionConfig -> ActionConfig -> Bool)
-> (ActionConfig -> ActionConfig -> Bool) -> Eq ActionConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ActionConfig -> ActionConfig -> Bool
== :: ActionConfig -> ActionConfig -> Bool
$c/= :: ActionConfig -> ActionConfig -> Bool
/= :: ActionConfig -> ActionConfig -> Bool
Eq, Int -> ActionConfig -> ShowS
[ActionConfig] -> ShowS
ActionConfig -> String
(Int -> ActionConfig -> ShowS)
-> (ActionConfig -> String)
-> ([ActionConfig] -> ShowS)
-> Show ActionConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ActionConfig -> ShowS
showsPrec :: Int -> ActionConfig -> ShowS
$cshow :: ActionConfig -> String
show :: ActionConfig -> String
$cshowList :: [ActionConfig] -> ShowS
showList :: [ActionConfig] -> ShowS
Show)
buildPlan :: Text -> Text -> Text -> Bool -> IO (Either Text [GeneratorAction])
buildPlan :: Text -> Text -> Text -> Bool -> IO (Either Text [GeneratorAction])
buildPlan Text
actionName Text
applicationName Text
controllerName Bool
doGenerateView=
if (Text -> Bool
forall mono. MonoFoldable mono => mono -> Bool
null Text
actionName Bool -> Bool -> Bool
|| Text -> Bool
forall mono. MonoFoldable mono => mono -> Bool
null Text
controllerName)
then Either Text [GeneratorAction] -> IO (Either Text [GeneratorAction])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Text [GeneratorAction]
-> IO (Either Text [GeneratorAction]))
-> Either Text [GeneratorAction]
-> IO (Either Text [GeneratorAction])
forall a b. (a -> b) -> a -> b
$ Text -> Either Text [GeneratorAction]
forall a b. a -> Either a b
Left Text
"Neither action name nor controller name can be empty"
else do
[Statement]
schema <- IO (Either ByteString [Statement])
SchemaDesigner.parseSchemaSql IO (Either ByteString [Statement])
-> (Either ByteString [Statement] -> IO [Statement])
-> IO [Statement]
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left ByteString
parserError -> [Statement] -> IO [Statement]
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
Right [Statement]
statements -> [Statement] -> IO [Statement]
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Statement]
statements
let actionConfig :: ActionConfig
actionConfig = ActionConfig {Text
$sel:controllerName:ActionConfig :: Text
controllerName :: Text
controllerName, Text
$sel:applicationName:ActionConfig :: Text
applicationName :: Text
applicationName, Text
$sel:modelName:ActionConfig :: Text
modelName :: Text
modelName, Text
$sel:actionName:ActionConfig :: Text
actionName :: Text
actionName }
let actionPlan :: [GeneratorAction]
actionPlan = [Statement] -> ActionConfig -> Bool -> [GeneratorAction]
generateGenericAction [Statement]
schema ActionConfig
actionConfig Bool
doGenerateView
if Bool
doGenerateView
then do
Either Text [GeneratorAction]
viewPlan <- Text -> Text -> Text -> IO (Either Text [GeneratorAction])
ViewGenerator.buildPlan Text
viewName Text
applicationName Text
controllerName
case Either Text [GeneratorAction]
viewPlan of
Right [GeneratorAction]
viewPlan' -> Either Text [GeneratorAction] -> IO (Either Text [GeneratorAction])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Text [GeneratorAction]
-> IO (Either Text [GeneratorAction]))
-> Either Text [GeneratorAction]
-> IO (Either Text [GeneratorAction])
forall a b. (a -> b) -> a -> b
$ [GeneratorAction] -> Either Text [GeneratorAction]
forall a b. b -> Either a b
Right ([GeneratorAction] -> Either Text [GeneratorAction])
-> [GeneratorAction] -> Either Text [GeneratorAction]
forall a b. (a -> b) -> a -> b
$ [GeneratorAction]
actionPlan [GeneratorAction] -> [GeneratorAction] -> [GeneratorAction]
forall {a}. Semigroup a => a -> a -> a
++ [GeneratorAction]
viewPlan'
Left Text
error -> Either Text [GeneratorAction] -> IO (Either Text [GeneratorAction])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Text [GeneratorAction]
-> IO (Either Text [GeneratorAction]))
-> Either Text [GeneratorAction]
-> IO (Either Text [GeneratorAction])
forall a b. (a -> b) -> a -> b
$ Text -> Either Text [GeneratorAction]
forall a b. a -> Either a b
Left Text
error
else Either Text [GeneratorAction] -> IO (Either Text [GeneratorAction])
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Text [GeneratorAction]
-> IO (Either Text [GeneratorAction]))
-> Either Text [GeneratorAction]
-> IO (Either Text [GeneratorAction])
forall a b. (a -> b) -> a -> b
$ [GeneratorAction] -> Either Text [GeneratorAction]
forall a b. b -> Either a b
Right ([GeneratorAction] -> Either Text [GeneratorAction])
-> [GeneratorAction] -> Either Text [GeneratorAction]
forall a b. (a -> b) -> a -> b
$ [GeneratorAction]
actionPlan
where
viewName :: Text
viewName = Text -> Text
ucfirst (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ if Text
"Action" Text -> Text -> Bool
`isSuffixOf` Text
actionName
then Int -> Text -> Text
Text.dropEnd Int
6 Text
actionName
else Text
actionName
modelName :: Text
modelName = Text -> Text
tableNameToModelName Text
controllerName
generateGenericAction :: [Statement] -> ActionConfig -> Bool -> [GeneratorAction]
generateGenericAction :: [Statement] -> ActionConfig -> Bool -> [GeneratorAction]
generateGenericAction [Statement]
schema ActionConfig
config Bool
doGenerateView =
let
controllerName :: Text
controllerName = ActionConfig
config.controllerName
name :: Text
name = Text -> Text
ucfirst (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ ActionConfig
config.actionName
singularName :: Text
singularName = ActionConfig
config.modelName
nameWithSuffix :: Text
nameWithSuffix = if Text
"Action" Text -> Text -> Bool
`isSuffixOf` Text
name
then Text
name
else Text
name Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action"
viewName :: Text
viewName = if Text
"Action" Text -> Text -> Bool
`isSuffixOf` Text
name
then Int -> Text -> Text
Text.dropEnd Int
6 Text
name
else Text
name
indexAction :: Text
indexAction = Text -> Text
pluralize Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action"
specialCases :: [(Text, Text)]
specialCases = [
(Text
indexAction, Text
indexContent)
, (Text
"Show" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action", Text
showContent)
, (Text
"Edit" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action", Text
editContent)
, (Text
"Update" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action", Text
updateContent)
, (Text
"Create" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action", Text
createContent)
, (Text
"Delete" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action", Text
deleteContent)
]
actionContent :: Text
actionContent = if Bool
doGenerateView
then
Text
" action " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
nameWithSuffix Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" = " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"do" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" render " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
viewName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"View { .. }\n"
else
Text
""
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" action " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
nameWithSuffix Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" = " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"do" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" redirectTo "Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
controllerName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action\n"
modelVariablePlural :: Text
modelVariablePlural = Text -> Text
lcfirst Text
name
modelVariableSingular :: Text
modelVariableSingular = Text -> Text
lcfirst Text
singularName
idFieldName :: Text
idFieldName = Text -> Text
lcfirst Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Id"
idType :: Text
idType = Text
"Id " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName
model :: Text
model = Text -> Text
ucfirst Text
singularName
indexContent :: Text
indexContent =
Text
""
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" action " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
name Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action = do\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariablePlural Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" <- query @" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
model Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" |> fetch\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" render IndexView { .. }\n"
newContent :: Text
newContent =
Text
""
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" action New" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action = do\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" let " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" = newRecord\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" render NewView { .. }\n"
showContent :: Text
showContent =
Text
""
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" action Show" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action { " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
idFieldName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" } = do\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" <- fetch " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
idFieldName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" render ShowView { .. }\n"
editContent :: Text
editContent =
Text
""
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" action Edit" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action { " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
idFieldName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" } = do\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" <- fetch " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
idFieldName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" render EditView { .. }\n"
updateContent :: Text
updateContent =
Text
""
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" action Update" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action { " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
idFieldName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" } = do\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" <- fetch " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
idFieldName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" |> build" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" |> ifValid \\case\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" Left " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" -> render EditView { .. }\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" Right " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" -> do\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" <- " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" |> updateRecord\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" setSuccessMessage \"" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
model Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" updated\"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" redirectTo Edit" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action { .. }\n"
createContent :: Text
createContent =
Text
""
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" action Create" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action = do\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" let " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" = newRecord @" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
model Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" |> build" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" |> ifValid \\case\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" Left " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" -> render NewView { .. }\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" Right " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" -> do\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" <- " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" |> createRecord\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" setSuccessMessage \"" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
model Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" created\"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" redirectTo " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
name Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action\n"
deleteContent :: Text
deleteContent =
Text
""
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" action Delete" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
singularName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action { " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
idFieldName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" } = do\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" <- fetch " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
idFieldName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" deleteRecord " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
modelVariableSingular Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" setSuccessMessage \"" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
model Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" deleted\"\n"
Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" redirectTo " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
name Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"Action\n"
typesContentGeneric :: Text
typesContentGeneric =
Text
" | " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
nameWithSuffix
typesContentWithParameter :: Text
typesContentWithParameter =
Text
" | " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
nameWithSuffix Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" { " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
idFieldName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
" :: !(" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
idType Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
") }\n"
chosenContent :: Text
chosenContent = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
actionContent (Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
nameWithSuffix [(Text, Text)]
specialCases)
chosenType :: Text
chosenType = if Text
chosenContent Text -> [Text] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
actionContent, Text
newContent, Text
createContent, Text
indexContent]
then Text
typesContentGeneric
else Text
typesContentWithParameter
in
[ AddAction { $sel:filePath:CreateFile :: Text
filePath = ActionConfig
config.applicationName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"/Controller/" Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
controllerName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
".hs", $sel:fileContent:CreateFile :: Text
fileContent = Text
chosenContent}
, AddToDataConstructor { $sel:dataConstructor:CreateFile :: Text
dataConstructor = Text
"data " Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
controllerName, $sel:filePath:CreateFile :: Text
filePath = ActionConfig
config.applicationName Text -> Text -> Text
forall {a}. Semigroup a => a -> a -> a
<> Text
"/Types.hs", $sel:fileContent:CreateFile :: Text
fileContent = Text
chosenType }
]