diff --git a/.github/workflows/spring-boot-graphql-querydsl.yml b/.github/workflows/spring-boot-graphql-querydsl.yml deleted file mode 100644 index 05246354e..000000000 --- a/.github/workflows/spring-boot-graphql-querydsl.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: spring-boot-graphql-querydsl - -on: - push: - paths: - - "graphql/spring-boot-graphql-querydsl/**" - branches: [main] - pull_request: - paths: - - "graphql/spring-boot-graphql-querydsl/**" - types: - - opened - - synchronize - - reopened - -jobs: - build: - name: Run Unit & Integration Tests - runs-on: ubuntu-latest - defaults: - run: - working-directory: "graphql/spring-boot-graphql-querydsl" - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - - name: Set up JDK 17 - uses: actions/setup-java@v3.13.0 - with: - java-version: 17 - distribution: "zulu" - cache: "gradle" - - - name: Build and analyze - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: ./gradlew clean spotlessApply build --info diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/mapper/PostMapper.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/mapper/PostMapper.java index 492a36361..e5fbe9eb4 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/mapper/PostMapper.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/mapper/PostMapper.java @@ -7,13 +7,11 @@ import com.example.graphql.querydsl.model.response.PostResponse; import com.example.graphql.querydsl.model.response.TagResponse; import java.util.List; -import org.mapstruct.DecoratedWith; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; -@Mapper -@DecoratedWith(PostMapperDecorator.class) +@Mapper(uses = PostMapperHelper.class) public interface PostMapper { @Mapping(target = "tags", ignore = true) @@ -39,5 +37,6 @@ public interface PostMapper { List toResponseList(List postList); + @Mapping(target = "tags", ignore = true) Post setTags(List tagRequests, Post post); } diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/mapper/PostMapperDecorator.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/mapper/PostMapperHelper.java similarity index 91% rename from graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/mapper/PostMapperDecorator.java rename to graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/mapper/PostMapperHelper.java index de42b28b3..7953e7fc4 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/mapper/PostMapperDecorator.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/mapper/PostMapperHelper.java @@ -22,7 +22,7 @@ import org.springframework.util.CollectionUtils; @Mapper -public abstract class PostMapperDecorator implements PostMapper { +public abstract class PostMapperHelper { @Autowired private TagRepository tagRepository; @@ -38,11 +38,11 @@ void setAfterMappingToPost(CreatePostRequest createPostRequest, @MappingTarget P new PostComment().setReview(postCommentRequest.review()).setCreatedOn(LocalDateTime.now()))); } - setTags(createPostRequest.tags(), post); + updateTagsToPost(createPostRequest.tags(), post); } - @Override - public Post setTags(List tagRequests, Post post) { + @AfterMapping + void updateTagsToPost(List tagRequests, @MappingTarget Post post) { if (!CollectionUtils.isEmpty(tagRequests)) { tagRequests.forEach(tagRequest -> { Predicate predicate = QTag.tag.name.equalsIgnoreCase(tagRequest.name()); @@ -56,6 +56,5 @@ public Post setTags(List tagRequests, Post post) { } }); } - return post; } } diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostRepository.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostRepository.java index fb634725d..8463164c8 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostRepository.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostRepository.java @@ -26,6 +26,6 @@ default void customize(QuerydslBindings bindings, QPost root) { "select o from Post o left join fetch o.details pd left join fetch o.comments where pd.createdBy = :createdBy") List findByDetails_CreatedByEqualsIgnoreCase(@Param("createdBy") String createdBy); - @Query("select p from Post p left join fetch p.tags where p in :posts") + @Query("select p from Post p left join fetch p.tags where p in :posts ORDER BY p.id") List findAllPostsWithTags(@Param("posts") List posts); }