File tree Expand file tree Collapse file tree
rentplace/src/main/java/kattsyn/dev/rentplace/services/impl Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,19 +66,28 @@ public boolean allowedToCreatePropertyOrAdmin(PropertyCreateEditDTO propertyCrea
6666 @ Transactional
6767 @ Override
6868 public List <PropertyDTO > findAll () {
69- return propertyMapper .fromProperties (propertyRepository .findAllWithRelations ());
69+ return returnWithSortedImages ( propertyMapper .fromProperties (propertyRepository .findAllWithRelations () ));
7070 }
7171
7272 @ Override
7373 public List <PropertyDTO > findAllByOwnerEmail (String email ) {
74- return propertyMapper .fromProperties (propertyRepository .findAllByOwnerEmail (email ));
74+ return returnWithSortedImages ( propertyMapper .fromProperties (propertyRepository .findAllByOwnerEmail (email ) ));
7575 }
7676
7777 @ Override
7878 public List <PropertyDTO > findAllByFilter (PropertyFilterDTO filter ) {
79- return propertyMapper .fromProperties (
79+ return returnWithSortedImages ( propertyMapper .fromProperties (
8080 propertyRepository .findAll (new PropertySpecification (filter ), buildSort (filter .getSortType ()))
81- );
81+ ));
82+ }
83+
84+ private List <PropertyDTO > returnWithSortedImages (List <PropertyDTO > propertyDTOS ) {
85+ propertyDTOS .forEach (propertyDTO
86+ -> propertyDTO
87+ .getImagesDTOs ()
88+ .sort (Comparator
89+ .comparing (ImageDTO ::isPreviewImage ).reversed ().thenComparing (ImageDTO ::getImageId )));
90+ return propertyDTOS ;
8291 }
8392
8493 private Sort buildSort (SortType sortType ) {
You can’t perform that action at this time.
0 commit comments