Skip to content

Commit

Permalink
feat: fix issue with mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Nov 11, 2023
1 parent ef13cc6 commit a085764
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 48 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/spring-boot-graphql-querydsl.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -39,5 +37,6 @@ public interface PostMapper {

List<PostResponse> toResponseList(List<Post> postList);

@Mapping(target = "tags", ignore = true)
Post setTags(List<TagRequest> tagRequests, Post post);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.springframework.util.CollectionUtils;

@Mapper
public abstract class PostMapperDecorator implements PostMapper {
public abstract class PostMapperHelper {

@Autowired
private TagRepository tagRepository;
Expand All @@ -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<TagRequest> tagRequests, Post post) {
@AfterMapping
void updateTagsToPost(List<TagRequest> tagRequests, @MappingTarget Post post) {
if (!CollectionUtils.isEmpty(tagRequests)) {
tagRequests.forEach(tagRequest -> {
Predicate predicate = QTag.tag.name.equalsIgnoreCase(tagRequest.name());
Expand All @@ -56,6 +56,5 @@ public Post setTags(List<TagRequest> tagRequests, Post post) {
}
});
}
return post;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Post> 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<Post> findAllPostsWithTags(@Param("posts") List<Post> posts);
}

0 comments on commit a085764

Please sign in to comment.