diff --git a/judo-ui-typescript-rest-axios/src/main/resources/data-axios/classServiceImpl.ts.hbs b/judo-ui-typescript-rest-axios/src/main/resources/data-axios/classServiceImpl.ts.hbs index 85a0f9c..6058dc9 100644 --- a/judo-ui-typescript-rest-axios/src/main/resources/data-axios/classServiceImpl.ts.hbs +++ b/judo-ui-typescript-rest-axios/src/main/resources/data-axios/classServiceImpl.ts.hbs @@ -188,6 +188,48 @@ export class {{ serviceClassName classType }}Impl extends JudoAxiosService imple }); } {{/ if }} + + {{# each relation.target.operations as | operation | }} + /** + * @throws {AxiosError}{{# if (hasFaults operation) }}With data containing {@link{{ faultContainerName operation }} } for business related errors (status code is 422).{{/ if }} + * @throws {AxiosError} With data containing {@link Array} for status codes: 400, 401, 403. + */ + async {{ operation.name }}For{{ firstToUpper relation.name }}({{# if operation.isMapped }}owner: JudoIdentifiable<{{ classDataName relation.target "" }}>{{/ if }}{{# if operation.input }}{{# if operation.isMapped }},{{/ if }}target:{{ classDataName operation.input.target "" }}{{/ if }}): Promise<{{# if operation.output }}{{ classDataName operation.output.target "Stored" }}{{ else }}void{{/ if }}> { + const path = '{{ operationRestPath relation.target operation '' }}'; + const response = await this.axios.post(this.getPathForActor(path){{# if operation.input }}, target{{ else }}, undefined{{/ if }}{{# if operation.isMapped }}, { + headers: { + 'X-Judo-SignedIdentifier': owner.__signedIdentifier!, + }, + } {{/ if }}); + + {{# if operation.output }} + return response.data; + {{/ if }} + } + + {{# if operation.input }} + {{# if operation.input.target.isTemplateable }} + async getTemplateFor{{ firstToUpper operation.name }}For{{ firstToUpper relation.name }}(): Promise<{{ classDataName operation.input.target "" }}> { + const path = '{{ restPath operation.input.target "/~template" "" "" }}'; + const response = await this.axios.get(this.getPathForActor(path)); + + return response.data; + } + {{/ if }} + {{/ if }} + + {{# if operation.isInputRangeable }} + /** + * @throws {AxiosError} With data containing {@link Array} for status codes: 401, 403. + */ + async getRangeFor{{ firstToUpper operation.name }}For{{ firstToUpper relation.name }}(owner?: {{ classDataName relation.target "Stored" }}, queryCustomizer?:{{ classDataName operation.input.target "QueryCustomizer" }}): Promise> { + const path = '{{ operationRestPath relation.target operation '/~range' }}'; + const response = await this.axios.post(this.getPathForActor(path), { owner: owner ?? {}, queryCustomizer: queryCustomizer ?? {} }); + + return response.data; + } + {{/ if }} + {{/ each }} {{/ each }} {{# each classType.operations as | operation | }} diff --git a/judo-ui-typescript-rest-axios/src/main/resources/data-axios/relationServiceImpl.ts.hbs b/judo-ui-typescript-rest-axios/src/main/resources/data-axios/relationServiceImpl.ts.hbs index 453d79f..a03a091 100644 --- a/judo-ui-typescript-rest-axios/src/main/resources/data-axios/relationServiceImpl.ts.hbs +++ b/judo-ui-typescript-rest-axios/src/main/resources/data-axios/relationServiceImpl.ts.hbs @@ -360,6 +360,55 @@ export class {{ serviceRelationName relation }}Impl extends JudoAxiosService imp } {{/ neq }} {{/ if }} + + {{# each targetRelation.target.operations as | operation | }} + /** + * From: targetRelation.target.operations + * @throws {AxiosError}{{# if (hasFaults operation) }}With data containing {@link{{ faultContainerName operation }} } for business related errors (status code is 422).{{/ if }} + * @throws {AxiosError} With data containing {@link Array} for status codes: 400, 401, 403. + */ + async {{ operation.name }}For{{ firstToUpper targetRelation.name }}({{# unless operation.isStatic }}owner: JudoIdentifiable<{{ classDataName targetRelation.target "" }}>{{/ unless }}{{# if operation.input }}{{# unless operation.isStatic }}, {{/ unless }}target:{{ classDataName operation.input.target "" }}{{/ if }}): Promise<{{# if operation.output }}{{ classDataName operation.output.target "Stored" }}{{ else }}void{{/ if }}> { + const path = '{{ operationRestPath relation.target operation '' }}'; + const response = await this.axios.post(this.getPathForActor(path){{# if operation.input }}, target{{ else }}, undefined{{/ if }}{{# unless operation.isStatic }}, { + headers: { + 'X-Judo-SignedIdentifier': owner.__signedIdentifier!, + }, + } {{/ unless }}); + + {{# if operation.output }} + return response.data; + {{/ if }} + } + + {{# if operation.input }} + {{# if operation.input.target.isTemplateable }} + async getTemplateFor{{ firstToUpper operation.name }}For{{ firstToUpper targetRelation.name }}(): Promise<{{ classDataName operation.input.target "" }}> { + const path = '{{ restPath operation.input.target "/~template" "" "" }}'; + const response = await this.axios.get(this.getPathForActor(path)); + + return response.data; + } + {{/ if }} + {{/ if }} + + {{# if operation.isInputRangeable }} + {{# neq relation.name targetRelation.name }} + /** + * From: targetRelation.target.operations operation.isInputRangeable + * @throws {AxiosError} With data containing {@link Array} for status codes: 401, 403. + */ + async getRangeFor{{ firstToUpper operation.name }}For{{ firstToUpper targetRelation.name }}({{# unless operation.isStatic }}owner: JudoIdentifiable<{{ classDataName targetRelation.target "" }}> | {{ classDataName targetRelation.target "" }}, {{/ unless }}queryCustomizer?:{{ classDataName operation.input.target "QueryCustomizer" }}): Promise> { + const path = '{{ operationRestPath targetRelation.target operation '/~range' }}'; + const response = await this.axios.post(this.getPathForActor(path), { + {{# unless operation.isStatic }}owner: owner ?? {},{{/ unless }} + queryCustomizer: queryCustomizer ?? {} + }); + + return response.data; + } + {{/ neq }} + {{/ if }} + {{/ each }} {{/ each }} {{# each relation.target.operations as | operation | }} diff --git a/judo-ui-typescript-rest-service/src/main/java/hu/blackbelt/judo/ui/generator/typescript/rest/service/UiServiceHelper.java b/judo-ui-typescript-rest-service/src/main/java/hu/blackbelt/judo/ui/generator/typescript/rest/service/UiServiceHelper.java index 856d322..e494535 100644 --- a/judo-ui-typescript-rest-service/src/main/java/hu/blackbelt/judo/ui/generator/typescript/rest/service/UiServiceHelper.java +++ b/judo-ui-typescript-rest-service/src/main/java/hu/blackbelt/judo/ui/generator/typescript/rest/service/UiServiceHelper.java @@ -65,9 +65,17 @@ public static String joinedTokensForApiImport(RelationType relation){ tokens.add(classDataName(targetRelation.getTarget(), "QueryCustomizer")); tokens.add(classDataName(targetRelation.getTarget(), "Stored")); tokens.add(classDataName(targetRelation.getTarget(), "")); + + fillImportTokens(tokens, targetRelation); } - for (OperationType operation: relation.getTarget().getOperations()) { + fillImportTokens(tokens, relation); + + return String.join(", ", tokens); + } + + private static void fillImportTokens(HashSet tokens, RelationType targetRelation) { + for (OperationType operation: targetRelation.getTarget().getOperations()) { if (operation.getInput() != null) { tokens.add(classDataName(operation.getInput().getTarget(), "")); tokens.add(classDataName(operation.getInput().getTarget(), "Stored")); @@ -82,8 +90,6 @@ public static String joinedTokensForApiImport(RelationType relation){ tokens.add(classDataName(operation.getInput().getTarget(), "")); } } - - return String.join(", ", tokens); } public static String joinedTokensForApiImportForAccessRelationServiceImpl(RelationType relation){ @@ -119,24 +125,32 @@ public static String joinedTokensForApiImportClassService(ClassType classType){ tokens.add(classDataName(relation.getTarget(), "")); tokens.add(classDataName(relation.getTarget(),"Stored")); tokens.add(classDataName(relation.getTarget(),"QueryCustomizer")); + + for (OperationType operation: relation.getTarget().getOperations()) { + fillOperationTokens(operation, tokens); + } } for (OperationType operation: classType.getOperations()) { - if (operation.getInput() != null) { - tokens.add(classDataName(operation.getInput().getTarget(), "")); - } + fillOperationTokens(operation, tokens); + } - if (operation.getOutput() != null) { - tokens.add(classDataName(operation.getOutput().getTarget(), "Stored")); - } + return String.join(", ", tokens); + } - if (operation.getIsInputRangeable()) { - tokens.add(classDataName(operation.getInput().getTarget(), "QueryCustomizer")); - tokens.add(classDataName(operation.getInput().getTarget(), "Stored")); - } + private static void fillOperationTokens(OperationType operation, HashSet tokens) { + if (operation.getInput() != null) { + tokens.add(classDataName(operation.getInput().getTarget(), "")); } - return String.join(", ", tokens); + if (operation.getOutput() != null) { + tokens.add(classDataName(operation.getOutput().getTarget(), "Stored")); + } + + if (operation.getIsInputRangeable()) { + tokens.add(classDataName(operation.getInput().getTarget(), "QueryCustomizer")); + tokens.add(classDataName(operation.getInput().getTarget(), "Stored")); + } } public static ClassType getRelationOwnerAsClassType(RelationType relationType){ diff --git a/judo-ui-typescript-rest-service/src/main/resources/data-service/classService.ts.hbs b/judo-ui-typescript-rest-service/src/main/resources/data-service/classService.ts.hbs index b7eb5aa..dc138a3 100644 --- a/judo-ui-typescript-rest-service/src/main/resources/data-service/classService.ts.hbs +++ b/judo-ui-typescript-rest-service/src/main/resources/data-service/classService.ts.hbs @@ -59,6 +59,20 @@ export interface {{ serviceClassName classType }} { delete{{ firstToUpper relation.name }}(target: JudoIdentifiable<{{ classDataName relation.target "" }}>): Promise; {{/ if }} + {{# each relation.target.operations as | operation | }} + {{ operation.name }}For{{ firstToUpper relation.name }}({{# if operation.isMapped }}owner: JudoIdentifiable<{{ classDataName relation.target "" }}>{{/ if }}{{# if operation.input }}{{# if operation.isMapped }}, {{/ if }}target: {{ classDataName operation.input.target "" }}{{/ if }}): Promise<{{# if operation.output }}{{ classDataName operation.output.target "Stored" }}{{ else }}void{{/ if }}>; + + {{# if operation.input }} + {{# if operation.input.target.isTemplateable }} + getTemplateFor{{ firstToUpper operation.name }}For{{ firstToUpper relation.name }}(): Promise<{{ classDataName operation.input.target "" }}>; + {{/ if }} + {{/ if }} + + {{# if operation.isInputRangeable }} + getRangeFor{{ firstToUpper operation.name }}For{{ firstToUpper relation.name }}(owner?: {{ classDataName relation.target "Stored" }}, queryCustomizer?: {{ classDataName operation.input.target "QueryCustomizer" }}): Promise>; + {{/ if }} + {{/ each }} + {{/ each }} {{# each classType.operations as | operation | }} {{ operation.name }}({{# if operation.isMapped }}owner: JudoIdentifiable<{{ classDataName classType "" }}>{{/ if }}{{# if operation.input }}{{# if operation.isMapped }}, {{/ if }}target: {{ classDataName operation.input.target "" }}{{/ if }}): Promise<{{# if operation.output }}{{ classDataName operation.output.target "Stored" }}{{ else }}void{{/ if }}>; diff --git a/judo-ui-typescript-rest-service/src/main/resources/data-service/relationService.ts.hbs b/judo-ui-typescript-rest-service/src/main/resources/data-service/relationService.ts.hbs index 0c8a36e..387eb7f 100644 --- a/judo-ui-typescript-rest-service/src/main/resources/data-service/relationService.ts.hbs +++ b/judo-ui-typescript-rest-service/src/main/resources/data-service/relationService.ts.hbs @@ -112,6 +112,22 @@ export interface {{ serviceRelationName relation }} { remove{{ firstToUpper targetRelation.name }}(owner: JudoIdentifiable<{{ classDataName relation.target "" }}>, selected: Array>): Promise; {{/ neq }} {{/ if }} + + {{# each targetRelation.target.operations as | operation | }} + {{ operation.name }}For{{ firstToUpper targetRelation.name }}({{# unless operation.isStatic }}owner: JudoIdentifiable<{{ classDataName targetRelation.target "" }}>{{/ unless }}{{# if operation.input }}{{# unless operation.isStatic }}, {{/ unless }}target: {{ classDataName operation.input.target "" }}{{/ if }}): Promise<{{# if operation.output }}{{ classDataName operation.output.target "Stored" }}{{ else }}void{{/ if }}>; + + {{# if operation.input }} + {{# if operation.input.target.isTemplateable }} + getTemplateFor{{ firstToUpper operation.name }}For{{ firstToUpper targetRelation.name }}(): Promise<{{ classDataName operation.input.target "" }}>; + {{/ if }} + {{/ if }} + + {{# if operation.isInputRangeable }} + {{# neq relation.name targetRelation.name }} + getRangeFor{{ firstToUpper operation.name }}For{{ firstToUpper targetRelation.name }}({{# unless operation.isStatic }}owner: JudoIdentifiable<{{ classDataName targetRelation.target "" }}> | {{ classDataName targetRelation.target "" }}, {{/ unless }}queryCustomizer?: {{ classDataName operation.input.target "QueryCustomizer" }}): Promise>; + {{/ neq }} + {{/ if }} + {{/ each }} {{/ each}} {{# each relation.target.operations as | operation | }}