Skip to content

Commit

Permalink
fix for legacy (jdl) CRUD methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangsa committed Nov 6, 2024
1 parent 3a93d73 commit 9bbd837
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ public void enterService_legacy(io.github.zenwave360.zdl.antlr.ZdlParser.Service
.with("javadoc", serviceJavadoc)
.with("aggregates", serviceAggregates)
.with("options", Map.of("rest", true))
.with("methods", createCRUDMethods(serviceAggregates))
.with("methods", createCRUDMethods(serviceName, serviceAggregates))
);
model.appendTo("services", serviceName, currentStack.peek());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,27 +182,29 @@ static int[] getLocations(ParserRuleContext ctx) {
}


static Map createCRUDMethods(List<String> entities) {
static Map createCRUDMethods(String serviceName, List<String> entities) {
var methods = new FluentMap();
for (String entity : entities) {
createCRUDMethods(entity.trim()).forEach(k -> methods.put((String) k.get("name"), k));
createCRUDMethods(serviceName, entity.trim()).forEach(k -> methods.put((String) k.get("name"), k));
}
return methods;
}

static List<Map> createCRUDMethods(String entity) {
static List<Map> createCRUDMethods(String serviceName, String entity) {
var path = "/" + inflector.kebabCase(inflector.pluralize(entity.toLowerCase()));
var entityIdPath = path + "/{"+ inflector.lowerCamelCase(entity) + "Id}";
var crudMethods = new ArrayList<Map>();
crudMethods.add(new FluentMap()
.with("name", "create" + entity)
.with("serviceName", serviceName)
.with("parameter", entity)
.with("returnType", entity)
.with("options", new FluentMap().with("post", path))
.with("optionsList", List.of(Map.of("name", "post", "value", path)))
);
crudMethods.add(new FluentMap()
.with("name", "update" + entity)
.with("serviceName", serviceName)
.with("paramId", "id")
.with("parameter", entity)
.with("returnType", entity)
Expand All @@ -212,6 +214,7 @@ static List<Map> createCRUDMethods(String entity) {
);
crudMethods.add(new FluentMap()
.with("name", "get" + entity)
.with("serviceName", serviceName)
.with("paramId", "id")
.with("returnType", entity)
.with("returnTypeIsOptional", true)
Expand All @@ -220,6 +223,7 @@ static List<Map> createCRUDMethods(String entity) {
);
crudMethods.add(new FluentMap()
.with("name", "list" + pluralize(entity))
.with("serviceName", serviceName)
.with("paginated", true)
.with("returnType", entity)
.with("returnTypeIsArray", true)
Expand All @@ -230,6 +234,7 @@ static List<Map> createCRUDMethods(String entity) {
);
crudMethods.add(new FluentMap()
.with("name", "delete" + entity)
.with("serviceName", serviceName)
.with("paramId", "id")
.with("options", new FluentMap().with("delete", entityIdPath))
.with("optionsList", List.of(Map.of("name", "delete", "value", entityIdPath)))
Expand Down

0 comments on commit 9bbd837

Please sign in to comment.