Skip to content

Commit

Permalink
Change set to list in the findLatestByPostTypesAndOrigins method's Po…
Browse files Browse the repository at this point in the history
…stServiceImpl class (#443)

Adjusted SQL queries per each section by adding to ORDER BY clause ordering by post ID DESC
  • Loading branch information
V-Kaidash authored and KuzmaJava committed Sep 6, 2021
1 parent 27f60bb commit a97d1a1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Set;
import java.util.List;

@Data
@Builder
Expand All @@ -14,5 +14,5 @@
public class PostMainPageDTO {

private String fieldName;
private Set<PostDTO> postDTOS;
private List<PostDTO> postDTOS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Page<PostEntity> findAllByDirectionsAndByPostTypesAndByOrigins(Set<Integer> type
+ " WHERE ORIGIN_ID = 1))"
+ " AND P1.STATUS IN ('PUBLISHED')"
+ " AND P1.TYPE_ID NOT IN (2)"
+ " ORDER BY CREATED_AT DESC")
+ " ORDER BY CREATED_AT DESC, P1.POST_ID DESC")
Page<PostEntity> findLatestByPostTypeExpertOpinion(Pageable pageable);

@Query(nativeQuery = true,
Expand All @@ -124,7 +124,7 @@ Page<PostEntity> findAllByDirectionsAndByPostTypesAndByOrigins(Set<Integer> type
+ " WHERE ORIGIN_ID = 2)) "
+ " AND P1.STATUS IN ('PUBLISHED') "
+ " AND P1.TYPE_ID NOT IN (2) "
+ " ORDER BY CREATED_AT DESC ")
+ " ORDER BY CREATED_AT DESC, P1.POST_ID DESC ")
Page<PostEntity> findLatestByPostTypeMedia(Pageable pageable);


Expand All @@ -136,15 +136,15 @@ Page<PostEntity> findAllByDirectionsAndByPostTypesAndByOrigins(Set<Integer> type
+ " WHERE ORIGIN_ID = 3)) "
+ " AND P1.STATUS IN ('PUBLISHED') "
+ " AND P1.TYPE_ID NOT IN (2) "
+ " ORDER BY CREATED_AT DESC ")
+ " ORDER BY CREATED_AT DESC, P1.POST_ID DESC ")
Page<PostEntity> findLatestByPostTypeTranslation(Pageable pageable);

@Query(nativeQuery = true,
value = "SELECT P1.* "
+ " FROM POSTS P1 "
+ " WHERE P1.TYPE_ID IN (2) "
+ " AND P1.STATUS IN ('PUBLISHED') "
+ " ORDER BY CREATED_AT DESC ")
+ " ORDER BY CREATED_AT DESC, P1.POST_ID DESC ")
Page<PostEntity> findLatestByOriginVideo(Pageable pageable);

@Query(nativeQuery = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,19 @@ public Page<PostMainPageDTO> findLatestByPostTypesAndOrigins(Pageable pageable)
PostMainPageDTO expertOptions = PostMainPageDTO.builder()
.fieldName("expertOpinion")
.postDTOS(postRepository.findLatestByPostTypeExpertOpinion(PageRequest.of(pageable.getPageNumber(), 4))
.map(postMapper::toPostDTO).toSet()).build();
.map(postMapper::toPostDTO).toList()).build();
PostMainPageDTO media = PostMainPageDTO.builder()
.fieldName("media")
.postDTOS(postRepository.findLatestByPostTypeMedia(PageRequest.of(pageable.getPageNumber(), 4))
.map(postMapper::toPostDTO).toSet()).build();
.map(postMapper::toPostDTO).toList()).build();
PostMainPageDTO translation = PostMainPageDTO.builder()
.fieldName("translation")
.postDTOS(postRepository.findLatestByPostTypeTranslation(PageRequest.of(pageable.getPageNumber(), 4))
.map(postMapper::toPostDTO).toSet()).build();
.map(postMapper::toPostDTO).toList()).build();
PostMainPageDTO video = PostMainPageDTO.builder()
.fieldName("video")
.postDTOS(postRepository.findLatestByOriginVideo(PageRequest.of(pageable.getPageNumber(), 4))
.map(postMapper::toPostDTO).toSet()).build();
.map(postMapper::toPostDTO).toList()).build();

return new PageImpl<>(List.of(expertOptions, media, translation, video));
}
Expand Down

0 comments on commit a97d1a1

Please sign in to comment.