Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented filtering by olbast' #1394

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dao/src/main/java/greencity/repository/AddressRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,14 @@ public interface AddressRepository extends CrudRepository<Address, Long> {
*/
@Query(value = "SELECT * FROM address WHERE user_id =:userId AND status != 'DELETED' LIMIT 1", nativeQuery = true)
Optional<Address> findAnyByUserIdAndAddressStatusNotDeleted(Long userId);

/**
* Method returns first address {@link Address} from each distinct region.
*
* @return list of {@link Address}
*/
@Query(
value = "SELECT a FROM Address a WHERE a.id IN (SELECT MIN(ad.id) "
+ "FROM Address ad WHERE ad.region = a.region)")
List<Address> findDistinctRegions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public TableParamsDto getParametersForOrdersTable(String uuid) {
new ColumnDTO(new TitleDto("violationsAmount", "Кількість порушень клієнта", "Violations"),
"violationsAmount", 20, false, true, false, 12, EditType.READ_ONLY, new ArrayList<>(), customersInfo),
new ColumnDTO(new TitleDto("region", "Область", "Region"), "region", 20, false,
true, false, 35, EditType.READ_ONLY, new ArrayList<>(), exportAddress),
true, true, 35, EditType.READ_ONLY, regionsList(), exportAddress),
new ColumnDTO(new TitleDto("city", "Місто", "City"), "city", 20,
false,
true, true, 36, EditType.READ_ONLY, cityList(), exportAddress),
Expand Down Expand Up @@ -791,4 +791,16 @@ private boolean isOrderBlockedByAnotherEmployee(Order order, Long employeeId) {
return order.getBlockedByEmployee() != null
&& !Objects.equals(employeeId, order.getBlockedByEmployee().getId());
}

private List<OptionForColumnDTO> regionsList() {
return addressRepository.findDistinctRegions()
.stream()
.map(address -> OptionForColumnDTO
.builder()
.key(address.getId().toString())
.en(address.getRegionEn())
.ua(address.getRegion())
.build())
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ void getParametersForOrdersTest() {
.thenReturn(addressList);
when(addressRepository.findDistinctCities())
.thenReturn(addressList);

when(addressRepository.findDistinctRegions())
.thenReturn(addressList);
assertNotNull(ordersAdminsPageService.getParametersForOrdersTable("1"));
}

Expand Down
Loading