diff --git a/pkg/generator/templates/backends/java/auth/[artifactId]-server/src/main/java/[groupIdSlashes]/[artifactIdSlashes]/application/graphql/user/UserResolver.java.peb b/pkg/generator/templates/backends/java/auth/[artifactId]-server/src/main/java/[groupIdSlashes]/[artifactIdSlashes]/application/graphql/user/UserResolver.java.peb index 74a5a0b..b2f8b42 100644 --- a/pkg/generator/templates/backends/java/auth/[artifactId]-server/src/main/java/[groupIdSlashes]/[artifactIdSlashes]/application/graphql/user/UserResolver.java.peb +++ b/pkg/generator/templates/backends/java/auth/[artifactId]-server/src/main/java/[groupIdSlashes]/[artifactIdSlashes]/application/graphql/user/UserResolver.java.peb @@ -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 diff --git a/pkg/generator/templates/backends/java/auth/[artifactId]-server/src/main/java/[groupIdSlashes]/[artifactIdSlashes]/domain/[nameLowerCase]/UserService.java.peb b/pkg/generator/templates/backends/java/auth/[artifactId]-server/src/main/java/[groupIdSlashes]/[artifactIdSlashes]/domain/[nameLowerCase]/UserService.java.peb index 7367e52..2ad0c60 100644 --- a/pkg/generator/templates/backends/java/auth/[artifactId]-server/src/main/java/[groupIdSlashes]/[artifactIdSlashes]/domain/[nameLowerCase]/UserService.java.peb +++ b/pkg/generator/templates/backends/java/auth/[artifactId]-server/src/main/java/[groupIdSlashes]/[artifactIdSlashes]/domain/[nameLowerCase]/UserService.java.peb @@ -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 }}; @@ -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 }}))); @@ -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() diff --git a/pkg/generator/templates/backends/java/auth/[artifactId]-server/src/test/java/[groupIdSlashes]/[artifactIdSlashes]/application/graphql/user/UserResolverTests.java.peb b/pkg/generator/templates/backends/java/auth/[artifactId]-server/src/test/java/[groupIdSlashes]/[artifactIdSlashes]/application/graphql/user/UserResolverTests.java.peb index 5eaf524..73648b3 100644 --- a/pkg/generator/templates/backends/java/auth/[artifactId]-server/src/test/java/[groupIdSlashes]/[artifactIdSlashes]/application/graphql/user/UserResolverTests.java.peb +++ b/pkg/generator/templates/backends/java/auth/[artifactId]-server/src/test/java/[groupIdSlashes]/[artifactIdSlashes]/application/graphql/user/UserResolverTests.java.peb @@ -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; @@ -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.executeAndExtractJsonPath(