Skip to content

Commit

Permalink
Finish converting Kotlin to Java
Browse files Browse the repository at this point in the history
  • Loading branch information
wnederhof committed Apr 15, 2024
1 parent 4effa2b commit 6d21d20
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public class {{ namePascalCase }}Resolver {

@DgsQuery
Iterable<{{ namePascalCase }}> {{ namePluralCamelCase }}({%if hasRelations%}{{ namePascalCase }}FilterInput filter{%endif%}) {
if (filter == null) {
{%if hasRelations%}if (filter == null) {
return {{ nameCamelCase }}Service.findAll();
}
return {{ nameCamelCase }}Service.findAll({%if hasRelations%}filter{%endif%});
{%endif%}return {{ nameCamelCase }}Service.findAll({%if hasRelations%}filter{%endif%});
}

@DgsMutation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ public class {{ namePascalCase }}Service {
public {{ namePascalCase }} register(RegisterInput input) { {%for field in fields%}{%if field.isFieldRelational%}
Objects.requireNonNull({{ field.fieldTypeCamelCase }}Service.findById(input.get{{ field.fieldNamePascalCase }}()).orElse(null));
{%endif%}{%endfor%}
var {{ nameCamelCase }}Entity = {{ namePascalCase }}Entity.builder(){%for field in fields%}{%if field.isFieldRelational%}
.{{field.fieldNameCamelCase}}(input.get{{field.fieldNamePascalCase}}()){%endif%}{%endfor%}
var {{ nameCamelCase }}Entity = {{ namePascalCase }}Entity.builder(){%for field in fields%}
.{{field.fieldNameCamelCase}}({%if field.fieldNameCamelCase == "password"%}passwordEncoder.encode(input.get{{field.fieldNamePascalCase}}()){%else%}input.get{{field.fieldNamePascalCase}}(){%endif%}){%endfor%}
.build();

var {{ nameCamelCase }} = toDomainObject({{ nameCamelCase }}Repository.save({{ nameCamelCase }}Entity));
publisher.publishEvent(new {{ namePluralPascalCase }}RegisteredEvent(this, singletonList({{ nameCamelCase }})));
return {{ nameCamelCase }};
Expand All @@ -93,7 +94,7 @@ public class {{ namePascalCase }}Service {
return Optional.empty();
}
var saved{{ namePascalCase }}Entity = {{ nameCamelCase }}Repository.save(
{{ nameCamelCase }}Entity.get(){%for field in fields%}{%if field.isFieldRelational%}
{{ nameCamelCase }}Entity.get(){%for field in fields%}{%if field.fieldNameCamelCase != "username"%}
.with{{field.fieldNamePascalCase}}(input.get{{field.fieldNamePascalCase}}() != null ? input.get{{field.fieldNamePascalCase}}() : {{ nameCamelCase }}Entity.get().get{{field.fieldNamePascalCase}}()){%endif%}{%endfor%});
var {{ nameCamelCase }} = toDomainObject(saved{{ namePascalCase }}Entity);
publisher.publishEvent(new {{ namePluralPascalCase }}UpdatedEvent(this, singletonList({{ nameCamelCase }})));
Expand Down Expand Up @@ -127,7 +128,7 @@ public class {{ namePascalCase }}Service {
private {{ namePascalCase }} toDomainObject({{ namePascalCase }}Entity entity) {
return {{ namePascalCase }}.builder()
.id(entity.getId()){%for field in fields%}
.{{field.fieldNameCamelCase}}({%if field.fieldNameCamelCase == "password"%}passwordEncoder.encode(entity.get{{field.fieldNamePascalCase}}()){%else%}entity.get{{field.fieldNamePascalCase}}(){%endif%}){%endfor%}
.{{field.fieldNameCamelCase}}(entity.get{{field.fieldNamePascalCase}}()){%endfor%}
.createdAt(entity.getCreatedAt().atZone(ZoneId.systemDefault()).toOffsetDateTime())
.updatedAt(entity.getUpdatedAt() != null
? entity.getUpdatedAt().atZone(ZoneId.systemDefault()).toOffsetDateTime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -89,8 +90,8 @@ class {{ namePascalCase }}ResolverTests {
when({{ nameCamelCase }}Service.update(anyInt(), any()))
.thenReturn(Optional.of({{ nameScreamingSnakeCase }}_FIXTURE_WITH_ID_1));

var update{{ namePascalCase }}Input = Map.of({%for field in fields%}
"{{ field.fieldNameCamelCase }}", {{ field.fieldKotlinTestDummyValue }}{%if field.isNotLast%},{%endif%}{%endfor%}
var update{{ namePascalCase }}Input = Map.of({%for field in fields%}{%if field.fieldNameCamelCase != "username"%}
"{{ field.fieldNameCamelCase }}", {{ field.fieldKotlinTestDummyValue }}{%if field.isNotLast%},{%endif%}{%endif%}{%endfor%}
);

var result = dgsQueryExecutor.<String>executeAndExtractJsonPath(
Expand Down

0 comments on commit 6d21d20

Please sign in to comment.