Skip to content

Commit

Permalink
feat: create condition to Find annotation and OrderBy
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed Apr 1, 2024
1 parent b66bc93 commit 9572b7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static RepositoryType of(Method method, Class<?> repositoryType) {
return DEFAULT;
}
if (method.getAnnotationsByType(OrderBy.class).length > 0) {
return ORDER_BY;
return method.getAnnotation(Find.class) == null? ORDER_BY: PARAMETER_BASED;
}
if (!repositoryType.equals(declaringClass) && isCustomRepository(declaringClass)) {
return CUSTOM_REPOSITORY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ void shouldReturnParameterBased() throws NoSuchMethodException {
Assertions.assertEquals(RepositoryType.PARAMETER_BASED, RepositoryType.of(getMethod(DevRepository.class, "find"), CrudRepository.class));
}

@Test
void shouldReturnParameterBased2() throws NoSuchMethodException {
Assertions.assertEquals(RepositoryType.PARAMETER_BASED, RepositoryType.of(getMethod(DevRepository.class, "find2"), CrudRepository.class));
}


@Test
void shouldReturnCountBy() throws NoSuchMethodException {
Assertions.assertEquals(RepositoryType.COUNT_BY, RepositoryType.of(getMethod(DevRepository.class, "countByName"), CrudRepository.class));
Expand Down Expand Up @@ -246,6 +252,9 @@ default int duplicate(int value) {
@Find
List<String> find(String name);

@Find
@OrderBy("name")
List<String> find2(String name);
CursoredPage<String> findByNameOrderByName(String name, PageRequest<String> pageable);

}
Expand Down

0 comments on commit 9572b7b

Please sign in to comment.