fix(namespace): type nullable search terms

Signed-off-by: dongmucat <1127093059@qq.com>
This commit is contained in:
dongmucat 2026-07-27 17:29:12 +08:00
parent f8df616480
commit 0cbe33436d
2 changed files with 18 additions and 4 deletions

View file

@ -66,6 +66,20 @@ class NamespaceJpaRepositoryTest {
.containsExactly("underscore-team");
}
@Test
void search_acceptsNullQueryAlongsideOtherFilters() {
var page = repository.search(
NamespaceStatus.ACTIVE,
NamespaceType.TEAM,
null,
"percent-team",
PageRequest.of(0, 1)
);
assertThat(page.getContent()).extracting(Namespace::getSlug)
.containsExactly("percent-team");
}
private Namespace persist(Namespace namespace) {
entityManager.persist(namespace);
return namespace;

View file

@ -32,8 +32,8 @@ public interface NamespaceJpaRepository
AND (:type IS NULL OR n.type = :type)
AND (
:query IS NULL
OR lower(n.slug) LIKE lower(concat('%', :query, '%')) ESCAPE '!'
OR lower(n.displayName) LIKE lower(concat('%', :query, '%')) ESCAPE '!'
OR lower(n.slug) LIKE lower(concat('%', cast(:query as string), '%')) ESCAPE '!'
OR lower(n.displayName) LIKE lower(concat('%', cast(:query as string), '%')) ESCAPE '!'
)
AND (:slug IS NULL OR n.slug = :slug)
""")
@ -52,8 +52,8 @@ public interface NamespaceJpaRepository
AND (:type IS NULL OR n.type = :type)
AND (
:query IS NULL
OR lower(n.slug) LIKE lower(concat('%', :query, '%')) ESCAPE '!'
OR lower(n.displayName) LIKE lower(concat('%', :query, '%')) ESCAPE '!'
OR lower(n.slug) LIKE lower(concat('%', cast(:query as string), '%')) ESCAPE '!'
OR lower(n.displayName) LIKE lower(concat('%', cast(:query as string), '%')) ESCAPE '!'
)
AND (:slug IS NULL OR n.slug = :slug)
""")