@@ -40,23 +40,26 @@ private Pageable rewriteSort(Pageable pageable) {
4040
4141 Sort composed = Sort .unsorted ();
4242 boolean hasUserRoleOrder = false ;
43-
43+ boolean hasTeamOrder = false ;
44+ final String roleRankCase =
45+ "(CASE " +
46+ " WHEN u.userRole = 'GUEST' THEN 0 " +
47+ " WHEN u.userRole = 'MEMBER' THEN 1 " +
48+ " WHEN u.userRole = 'CORE' THEN 2 " +
49+ " WHEN u.userRole = 'LEAD' THEN 3 " +
50+ " WHEN u.userRole = 'ORGANIZER' THEN 4 " +
51+ " WHEN u.userRole = 'ADMIN' THEN 5 " +
52+ " ELSE -1 END)" ;
4453 for (Sort .Order o : original ) {
4554 String prop = o .getProperty ();
4655 Sort .Direction dir = o .getDirection ();
4756
4857 if ("userRole" .equals (prop )) {
4958 hasUserRoleOrder = true ;
50- String roleRankCase =
51- "(CASE " +
52- " WHEN u.userRole = 'GUEST' THEN 0 " +
53- " WHEN u.userRole = 'MEMBER' THEN 1 " +
54- " WHEN u.userRole = 'CORE' THEN 2 " +
55- " WHEN u.userRole = 'LEAD' THEN 3 " +
56- " WHEN u.userRole = 'ORGANIZER' THEN 4 " +
57- " WHEN u.userRole = 'ADMIN' THEN 5 " +
58- " ELSE -1 END)" ;
5959 composed = composed .and (JpaSort .unsafe (dir , roleRankCase ));
60+ } else if ("team" .equals (prop )) {
61+ hasTeamOrder = true ;
62+ composed = composed .and (Sort .by (new Sort .Order (dir , "team" )));
6063 } else {
6164 composed = composed .and (Sort .by (new Sort .Order (dir , prop )));
6265 }
@@ -66,6 +69,10 @@ private Pageable rewriteSort(Pageable pageable) {
6669 composed = composed .and (Sort .by ("name" ).ascending ());
6770 }
6871
72+ if (hasTeamOrder ) {
73+ composed = composed .and (JpaSort .unsafe (Sort .Direction .DESC , roleRankCase ));
74+ composed = composed .and (Sort .by ("name" ).ascending ());
75+ }
6976 return PageRequest .of (pageable .getPageNumber (), pageable .getPageSize (), composed );
7077 }
7178
0 commit comments