Skip to content

Commit

Permalink
Merge pull request #11 from ingjavierbarrios/memory-table
Browse files Browse the repository at this point in the history
Changes in wrapper file of SpringBoot Generator Code for supporting i…
  • Loading branch information
jbarriospq committed Jan 13, 2021
2 parents c285011 + 6dcbdbd commit 60c3b28
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 3 deletions.
6 changes: 6 additions & 0 deletions redistributable/SpringBoot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<artifactId>jackson-module-scala_2.13</artifactId>
<version>2.11.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json4s/json4s-jackson -->
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_2.13</artifactId>
<version>3.7.0-M7</version>
</dependency>

</dependencies>

Expand Down
128 changes: 125 additions & 3 deletions src/Morphir/SpringBoot/Backend.elm
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,43 @@ mapStatefulAppImplementation opt distribution currentPackagePath currentModulePa
, imports = []
, typeDecls =
[ Scala.Documented (Just (String.join "" [ "Generated based on ", currentModulePath |> Path.toString Name.toTitleCase "." ]))
(Scala.withoutAnnotation
(Class
{ modifiers =
[ Case ]
, name =
"TupleKeyCommand"
, typeArgs =
[ TypeVar "K", TypeVar "C" ]
, ctorArgs =
[ [ { modifiers = []
, tpe = TypeVar "K"
, name =
"@scala.beans.BeanProperty "
++ "@com.fasterxml.jackson.annotation.JsonProperty (\""
++ "key"
++ "\") "
++ "key"
, defaultValue = Nothing
}
, { modifiers = []
, tpe = TypeVar "C"
, name =
"@scala.beans.BeanProperty "
++ "@com.fasterxml.jackson.annotation.JsonProperty (\""
++ "command"
++ "\") "
++ "command"
, defaultValue = Nothing
}
]
]
, extends = []
, members = []
}
)
)
, Scala.Documented (Just (String.join "" [ "Generated based on ", currentModulePath |> Path.toString Name.toTitleCase "." ]))
(Scala.withoutAnnotation
(Class
{ modifiers =
Expand Down Expand Up @@ -372,6 +409,14 @@ mapStatefulAppImplementation opt distribution currentPackagePath currentModulePa
, value = Scala.Variable (dotSep scalaPackagePath ++ ".MainApplication.metricRegistry.meter(\"statefulAppRequests\")")
}
)
, Scala.withoutAnnotation
(ValueDecl
{ modifiers = []
, pattern = NamedMatch "table"
, valueType = Nothing
, value = Scala.Variable "new scala.collection.mutable.HashMap[K, S]"
}
)
, Annotated
[ "@org.springframework.web.bind.annotation.PostMapping(value= Array(\"/v1.0/command\"), consumes = Array(org.springframework.http.MediaType.APPLICATION_JSON_VALUE), produces = Array(\"application/json\"))"
]
Expand All @@ -381,16 +426,73 @@ mapStatefulAppImplementation opt distribution currentPackagePath currentModulePa
, typeArgs = []
, args =
[ [ ArgDecl []
(TypeVar "C")
"@org.springframework.web.bind.annotation.RequestBody command"
(TypeApply (TypeVar "TupleKeyCommand")
[ TypeVar "K", TypeVar "C" ]
)
"@org.springframework.web.bind.annotation.RequestBody input"
Nothing
]
]
, returnType = Just (TypeVar "E")
, body =
Just
(Scala.Variable
("{requests.mark" ++ newLine ++ "process(command, None)._2}")
("{requests.mark"
++ newLine
++ "val state = table.get(input.key)"
++ newLine
++ "val result = process(input.command, state)"
++ newLine
++ "update(input.key, state, result)"
++ newLine
++ "result._2}"
)
)
}
)
, Scala.withoutAnnotation
(FunctionDecl
{ modifiers = []
, name = "update"
, typeArgs = []
, args =
[ [ ArgDecl []
(TypeVar "K")
"key"
Nothing
, ArgDecl []
(TypeApply (TypeVar "Option") [ TypeVar "S" ])
"state"
Nothing
, ArgDecl []
(TupleType [ TypeApply (TypeRef [ "morphir.sdk.Maybe" ] "Maybe") [ TypeVar "S" ], TypeVar "E" ])
"result"
Nothing
]
]
, returnType = Nothing
, body =
Just
(Match
(Scala.Tuple [ Scala.Variable "state", Scala.Variable "result" ])
(Scala.MatchCases
[ ( TupleMatch
[ NamedMatch "None"
, TupleMatch [ UnapplyMatch [ "morphir.sdk.Maybe" ] "Just(a)" [], WildcardMatch ]
]
, Scala.Apply (Scala.Ref [ "table" ] "addOne") [ ArgValue Nothing (Scala.Tuple [ Scala.Variable "key", Scala.Variable "a" ]) ]
)
, ( TupleMatch
[ NamedMatch "Some(_)"
, TupleMatch [ UnapplyMatch [ "morphir.sdk.Maybe" ] "Nothing" [], WildcardMatch ]
]
, Scala.Apply (Scala.Ref [ "table" ] "remove") [ ArgValue Nothing (Scala.Variable "key") ]
)
, ( WildcardMatch
, Scala.Variable "None"
)
]
)
)
}
)
Expand Down Expand Up @@ -440,6 +542,26 @@ mapStatefulAppImplementation opt distribution currentPackagePath currentModulePa
)
}
)
, Annotated
[ "@org.springframework.web.bind.annotation.RequestMapping(value = Array(\"/v1.0/list\"))"
]
(FunctionDecl
{ modifiers = []
, name = "list"
, typeArgs = []
, args =
[]
, returnType = Nothing
, body =
Just
(Scala.Variable
("{implicit val formats = org.json4s.DefaultFormats"
++ newLine
++ "org.json4s.jackson.Serialization.write(table)}"
)
)
}
)
]
}
)
Expand Down

0 comments on commit 60c3b28

Please sign in to comment.