forked from babyfish-ct/jimmer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
project/jimmer-client/src/test/java/org/babyfish/jimmer/client/java/service/PageQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.babyfish.jimmer.client.java.service; | ||
|
||
public record PageQuery<T>( | ||
Integer pageIndex, | ||
Integer pageSize, | ||
T spec | ||
) { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...ct/jimmer-client/src/test/java/org/babyfish/jimmer/client/java/service/RecordService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.babyfish.jimmer.client.java.service; | ||
|
||
import org.babyfish.jimmer.client.common.PostMapping; | ||
import org.babyfish.jimmer.client.meta.Api; | ||
|
||
@Api("recordService") | ||
public class RecordService { | ||
@Api | ||
@PostMapping("/page/query") | ||
public PageQuery<String> pageQuery(PageQuery<String> pageQuery) { | ||
return pageQuery; | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...ect/jimmer-client/src/test/java/org/babyfish/jimmer/client/java/ts/RecordServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package org.babyfish.jimmer.client.java.ts; | ||
|
||
import org.babyfish.jimmer.client.common.OperationParserImpl; | ||
import org.babyfish.jimmer.client.common.ParameterParserImpl; | ||
import org.babyfish.jimmer.client.generator.Context; | ||
import org.babyfish.jimmer.client.generator.ts.TypeScriptContext; | ||
import org.babyfish.jimmer.client.java.service.RecordService; | ||
import org.babyfish.jimmer.client.runtime.Metadata; | ||
import org.babyfish.jimmer.client.source.Source; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.StringWriter; | ||
import java.util.Collections; | ||
|
||
public class RecordServiceTest { | ||
|
||
private static final Metadata METADATA = | ||
Metadata | ||
.newBuilder() | ||
.setOperationParser(new OperationParserImpl()) | ||
.setParameterParser(new ParameterParserImpl()) | ||
.setGroups(Collections.singleton("recordService")) | ||
.setGenericSupported(true) | ||
.build(); | ||
|
||
@Test | ||
public void testService() { | ||
Context ctx = new TypeScriptContext(METADATA); | ||
Source source = ctx.getRootSource("services/" + RecordService.class.getSimpleName()); | ||
StringWriter writer = new StringWriter(); | ||
ctx.render(source, writer); | ||
Assertions.assertEquals("import type {Executor} from '../';\n" + | ||
"import type {PageQuery} from '../model/static/';\n" + | ||
"\n" + | ||
"export class RecordService {\n" + | ||
" \n" + | ||
" constructor(private executor: Executor) {}\n" + | ||
" \n" + | ||
" readonly pageQuery: (options: RecordServiceOptions['pageQuery']) => Promise<\n" + | ||
" PageQuery<string>\n" + | ||
" > = async(options) => {\n" + | ||
" let _uri = '/page/query';\n" + | ||
" let _separator = _uri.indexOf('?') === -1 ? '?' : '&';\n" + | ||
" let _value: any = undefined;\n" + | ||
" _value = options.pageQuery.pageIndex;\n" + | ||
" if (_value !== undefined && _value !== null) {\n" + | ||
" _uri += _separator\n" + | ||
" _uri += 'pageIndex='\n" + | ||
" _uri += encodeURIComponent(_value);\n" + | ||
" _separator = '&';\n" + | ||
" }\n" + | ||
" _value = options.pageQuery.pageSize;\n" + | ||
" if (_value !== undefined && _value !== null) {\n" + | ||
" _uri += _separator\n" + | ||
" _uri += 'pageSize='\n" + | ||
" _uri += encodeURIComponent(_value);\n" + | ||
" _separator = '&';\n" + | ||
" }\n" + | ||
" return (await this.executor({uri: _uri, method: 'POST'})) as Promise<PageQuery<string>>;\n" + | ||
" }\n" + | ||
"}\n" + | ||
"\n" + | ||
"export type RecordServiceOptions = {\n" + | ||
" 'pageQuery': {\n" + | ||
" readonly pageQuery: PageQuery<string>\n" + | ||
" }\n" + | ||
"}\n", | ||
writer.toString() | ||
); | ||
} | ||
|
||
|
||
@Test | ||
public void testPageQuery() { | ||
Context ctx = new TypeScriptContext(METADATA); | ||
Source source = ctx.getRootSource("model/static/PageQuery"); | ||
StringWriter writer = new StringWriter(); | ||
ctx.render(source, writer); | ||
Assertions.assertEquals( | ||
"export interface PageQuery<T> {\n" + | ||
" readonly pageIndex?: number | undefined;\n" + | ||
" readonly pageSize?: number | undefined;\n" + | ||
" readonly spec: T;\n" + | ||
"}\n", | ||
writer.toString() | ||
); | ||
} | ||
} |