Skip to content

Commit a7a0942

Browse files
committed
/series/add: sort countries by name.
1 parent b29c16e commit a7a0942

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/main/java/ru/mystamps/web/dao/CountryDao.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
*/
1818
package ru.mystamps.web.dao;
1919

20-
import org.springframework.data.repository.CrudRepository;
20+
import org.springframework.data.repository.PagingAndSortingRepository;
2121

2222
import ru.mystamps.web.entity.Country;
2323

24-
public interface CountryDao extends CrudRepository<Country, Integer> {
24+
public interface CountryDao extends PagingAndSortingRepository<Country, Integer> {
2525
int countByName(String name);
2626
}

src/main/java/ru/mystamps/web/service/CountryServiceImpl.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.util.Date;
2323

24+
import org.springframework.data.domain.Sort;
2425
import org.springframework.security.access.prepost.PreAuthorize;
2526
import org.springframework.transaction.annotation.Transactional;
2627

@@ -37,6 +38,8 @@
3738
public class CountryServiceImpl implements CountryService {
3839
private static final Logger LOG = LoggerFactory.getLogger(CountryServiceImpl.class);
3940

41+
private static final Sort SORT_BY_NAME = new Sort("name");
42+
4043
private final CountryDao countryDao;
4144

4245
@Inject
@@ -71,7 +74,7 @@ public Country add(AddCountryDto dto, User user) {
7174
@Override
7275
@Transactional(readOnly = true)
7376
public Iterable<Country> findAll() {
74-
return countryDao.findAll();
77+
return countryDao.findAll(SORT_BY_NAME);
7578
}
7679

7780
@Override

src/test/groovy/ru/mystamps/web/service/CountryServiceTest.groovy

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package ru.mystamps.web.service
1919

20+
import org.springframework.data.domain.Sort
21+
2022
import spock.lang.Specification
2123

2224
import ru.mystamps.web.dao.CountryDao
@@ -144,7 +146,7 @@ class CountryServiceTest extends Specification {
144146
and:
145147
List<Country> expectedCountries = [ country1, country2 ]
146148
and:
147-
countryDao.findAll() >> expectedCountries
149+
countryDao.findAll(_ as Sort) >> expectedCountries
148150
when:
149151
Iterable<Country> resultCountries = service.findAll()
150152
then:

0 commit comments

Comments
 (0)