Skip to content

Commit

Permalink
Limit combobox court results to 200 (#2433)
Browse files Browse the repository at this point in the history
RISDEV-5901
Doc offices complained that 10 is not enough to find matching courts.
  • Loading branch information
kiwikern authored Dec 18, 2024
1 parent 5f34914 commit 2b57ce4
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public CourtController(CourtService service) {
*/
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public List<Court> getCourts(@RequestParam(value = "q", required = false) String searchStr) {
return service.getCourts(searchStr);
public List<Court> getCourts(
@RequestParam(value = "q", required = false) String searchStr,
@RequestParam(value = "sz", required = false, defaultValue = "200") Integer size) {
return service.getCourts(searchStr, size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ label LIKE UPPER('%' || :searchStr || '%')
ORDER BY
weight,
label
LIMIT 10
LIMIT :size
""")
List<CourtDTO> findBySearchStr(@Param("searchStr") String searchStr);
List<CourtDTO> findBySearchStr(@Param("searchStr") String searchStr, @Param("size") Integer size);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public PostgresCourtRepositoryImpl(DatabaseCourtRepository repository) {
}

@Override
public List<Court> findBySearchStr(String searchString) {
return repository.findBySearchStr(searchString).stream()
public List<Court> findBySearchStr(String searchString, Integer size) {
return repository.findBySearchStr(searchString, size).stream()
.map(CourtTransformer::transformToDomain)
.toList();
}
Expand Down Expand Up @@ -48,8 +48,8 @@ public Optional<Court> findUniqueBySearchString(String searchString) {
}

@Override
public List<Court> findAllByOrderByTypeAscLocationAsc() {
return repository.findByOrderByTypeAscLocationAsc(Limit.of(10)).stream()
public List<Court> findAllByOrderByTypeAscLocationAsc(Integer size) {
return repository.findByOrderByTypeAscLocationAsc(Limit.of(size)).stream()
.map(CourtTransformer::transformToDomain)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public CourtService(CourtRepository courtRepository) {
this.courtRepository = courtRepository;
}

public List<Court> getCourts(String searchStr) {
public List<Court> getCourts(String searchStr, Integer size) {
if (searchStr != null && !searchStr.trim().isBlank()) {
return courtRepository.findBySearchStr(searchStr.trim());
return courtRepository.findBySearchStr(searchStr.trim(), size);
}

return courtRepository.findAllByOrderByTypeAscLocationAsc();
return courtRepository.findAllByOrderByTypeAscLocationAsc(size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

@NoRepositoryBean
public interface CourtRepository {
List<Court> findBySearchStr(String searchString);
List<Court> findBySearchStr(String searchString, Integer size);

Optional<Court> findByTypeAndLocation(String type, String location);

Optional<Court> findUniqueBySearchString(String searchString);

List<Court> findAllByOrderByTypeAscLocationAsc();
List<Court> findAllByOrderByTypeAscLocationAsc(Integer size);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.bund.digitalservice.ris.caselaw.adapter;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -28,8 +30,8 @@ class CourtControllerTest {
@MockBean private ClientRegistrationRepository clientRegistrationRepository;

@Test
void testGetCourts() {
when(service.getCourts(null)).thenReturn(new ArrayList<>());
void testGetCourtsWithoutSize() {
when(service.getCourts(anyString(), anyInt())).thenReturn(new ArrayList<>());

risWebTestClient
.withDefaultLogin()
Expand All @@ -39,6 +41,36 @@ void testGetCourts() {
.expectStatus()
.isOk();

verify(service, times(1)).getCourts(null);
verify(service, times(1)).getCourts(null, 200);
}

@Test
void testGetCourtsWithSize() {
when(service.getCourts(anyString(), anyInt())).thenReturn(new ArrayList<>());

risWebTestClient
.withDefaultLogin()
.get()
.uri("/api/v1/caselaw/courts?sz=100")
.exchange()
.expectStatus()
.isOk();

verify(service, times(1)).getCourts(null, 100);
}

@Test
void testGetCourtsWithQuery() {
when(service.getCourts(anyString(), anyInt())).thenReturn(new ArrayList<>());

risWebTestClient
.withDefaultLogin()
.get()
.uri("/api/v1/caselaw/courts?q=test")
.exchange()
.expectStatus()
.isOk();

verify(service, times(1)).getCourts("test", 200);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ void testGetTwoDifferentCourts() {
Court courtB = Court.builder().type("XYZ").location("Hamburg").build();

List<Court> returnedCourts = List.of(courtA, courtB);
when(courtRepository.findAllByOrderByTypeAscLocationAsc()).thenReturn(returnedCourts);
when(courtRepository.findAllByOrderByTypeAscLocationAsc(100)).thenReturn(returnedCourts);

List<Court> resultCourts = service.getCourts(null);
List<Court> resultCourts = service.getCourts(null, 100);

Assertions.assertEquals(returnedCourts, resultCourts);

verify(courtRepository).findAllByOrderByTypeAscLocationAsc();
verify(courtRepository).findAllByOrderByTypeAscLocationAsc(100);
}

@Test
Expand All @@ -51,13 +51,13 @@ void testGetCourtsWithSearchString() {
String trimmedSearchString = searchString.trim();

List<Court> returnedCourts = List.of(courtA, courtB);
when(courtRepository.findBySearchStr(trimmedSearchString)).thenReturn(returnedCourts);
when(courtRepository.findBySearchStr(trimmedSearchString, 100)).thenReturn(returnedCourts);

List<Court> resultCourts = service.getCourts(searchString);
List<Court> resultCourts = service.getCourts(searchString, 100);

Assertions.assertEquals(returnedCourts, resultCourts);

verify(courtRepository).findBySearchStr(trimmedSearchString);
verify(courtRepository).findBySearchStr(trimmedSearchString, 100);
}

@Test
Expand All @@ -66,12 +66,12 @@ void testGetCourtsWithBlankSearchString() {
Court courtB = Court.builder().type("XYZ").location("Hamburg").build();

List<Court> returnedCourts = List.of(courtA, courtB);
when(courtRepository.findAllByOrderByTypeAscLocationAsc()).thenReturn(returnedCourts);
when(courtRepository.findAllByOrderByTypeAscLocationAsc(100)).thenReturn(returnedCourts);

List<Court> resultCourts = service.getCourts("");
List<Court> resultCourts = service.getCourts("", 100);

Assertions.assertEquals(returnedCourts, resultCourts);

verify(courtRepository).findAllByOrderByTypeAscLocationAsc();
verify(courtRepository).findAllByOrderByTypeAscLocationAsc(100);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void testParametrizedDocumentationUnitCreation() {
when(documentNumberPatternConfig.getDocumentNumberPatterns())
.thenReturn(Map.of("DS", "XXRE0******YY"));

var court = databaseCourtRepository.findBySearchStr("AG Aachen").get(0);
var court = databaseCourtRepository.findBySearchStr("AG Aachen", 100).getFirst();

risWebTestClient
.withDefaultLogin()
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/comboboxItemService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type ComboboxItemService = {

const service: ComboboxItemService = {
getCourts: (filter: Ref<string | undefined>) =>
fetchFromEndpoint(Endpoint.courts, filter),
fetchFromEndpoint(Endpoint.courts, filter, 200),
getDocumentTypes: (filter: Ref<string | undefined>) =>
fetchFromEndpoint(Endpoint.documentTypes, filter),
getDependentLiteratureDocumentTypes: (filter: Ref<string | undefined>) =>
Expand Down

0 comments on commit 2b57ce4

Please sign in to comment.