From 51d0407816b4c83f71de36282ba474365b675414 Mon Sep 17 00:00:00 2001 From: Kristina M Date: Thu, 9 Apr 2026 18:25:08 +0200 Subject: [PATCH 1/2] fix: resolve PostgreSQL bytea type casting in user repository queries --- .../user/repository/AppUserRepository.java | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/example/team6backend/user/repository/AppUserRepository.java b/src/main/java/org/example/team6backend/user/repository/AppUserRepository.java index 8f551fd..cb4e153 100644 --- a/src/main/java/org/example/team6backend/user/repository/AppUserRepository.java +++ b/src/main/java/org/example/team6backend/user/repository/AppUserRepository.java @@ -13,38 +13,39 @@ public interface AppUserRepository extends JpaRepository { - Optional findByGithubId(String githubId); + Optional findByGithubId(String githubId); - Optional findByEmail(String email); + Optional findByEmail(String email); - List findByRole(UserRole role); + List findByRole(UserRole role); - long countByRole(UserRole role); + long countByRole(UserRole role); - long countByRoleAndActiveTrue(UserRole role); + long countByRoleAndActiveTrue(UserRole role); - Page findByRole(UserRole role, Pageable pageable); + Page findByRole(UserRole role, Pageable pageable); - Page findByActive(boolean active, Pageable pageable); + Page findByActive(boolean active, Pageable pageable); - @Query(""" + @Query(""" SELECT u FROM AppUser u - WHERE (:email IS NULL OR LOWER(COALESCE(u.email, '')) LIKE LOWER(CONCAT('%', :email, '%'))) - AND (:name IS NULL OR LOWER(COALESCE(u.name, '')) LIKE LOWER(CONCAT('%', :name, '%'))) + WHERE (:email IS NULL OR LOWER(CAST(COALESCE(u.email, '') AS string)) LIKE LOWER(CONCAT('%', CAST(:email AS string), '%'))) + AND (:name IS NULL OR LOWER(CAST(COALESCE(u.name, '') AS string)) LIKE LOWER(CONCAT('%', CAST(:name AS string), '%'))) AND (:role IS NULL OR u.role = :role) AND (:active IS NULL OR u.active = :active) """) - Page findAllWithFilters(@Param("email") String email, @Param("name") String name, - @Param("role") UserRole role, @Param("active") Boolean active, Pageable pageable); + Page findAllWithFilters(@Param("email") String email, @Param("name") String name, + @Param("role") UserRole role, @Param("active") Boolean active, Pageable pageable); - @Query(""" + @Query(""" SELECT u FROM AppUser u - WHERE LOWER(COALESCE(u.email, '')) LIKE LOWER(CONCAT('%', :search, '%')) - OR LOWER(COALESCE(u.name, '')) LIKE LOWER(CONCAT('%', :search, '%')) - OR LOWER(COALESCE(u.githubLogin, '')) LIKE LOWER(CONCAT('%', :search, '%')) - OR LOWER(COALESCE(u.githubId, '')) LIKE LOWER(CONCAT('%', :search, '%')) + WHERE (:search IS NULL OR + LOWER(CAST(COALESCE(u.email, '') AS string)) LIKE LOWER(CONCAT('%', CAST(:search AS string), '%')) + OR LOWER(CAST(COALESCE(u.name, '') AS string)) LIKE LOWER(CONCAT('%', CAST(:search AS string), '%')) + OR LOWER(CAST(COALESCE(u.githubLogin, '') AS string)) LIKE LOWER(CONCAT('%', CAST(:search AS string), '%')) + OR LOWER(CAST(COALESCE(u.githubId, '') AS string)) LIKE LOWER(CONCAT('%', CAST(:search AS string), '%'))) """) - Page searchUsers(@Param("search") String search, Pageable pageable); -} + Page searchUsers(@Param("search") String search, Pageable pageable); +} \ No newline at end of file From b8e42fb7e236d0114e7cafc6f960cd6f62fd2fd0 Mon Sep 17 00:00:00 2001 From: Kristina M Date: Thu, 9 Apr 2026 18:26:54 +0200 Subject: [PATCH 2/2] style: apply spotless --- .../user/repository/AppUserRepository.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/example/team6backend/user/repository/AppUserRepository.java b/src/main/java/org/example/team6backend/user/repository/AppUserRepository.java index cb4e153..8504900 100644 --- a/src/main/java/org/example/team6backend/user/repository/AppUserRepository.java +++ b/src/main/java/org/example/team6backend/user/repository/AppUserRepository.java @@ -13,21 +13,21 @@ public interface AppUserRepository extends JpaRepository { - Optional findByGithubId(String githubId); + Optional findByGithubId(String githubId); - Optional findByEmail(String email); + Optional findByEmail(String email); - List findByRole(UserRole role); + List findByRole(UserRole role); - long countByRole(UserRole role); + long countByRole(UserRole role); - long countByRoleAndActiveTrue(UserRole role); + long countByRoleAndActiveTrue(UserRole role); - Page findByRole(UserRole role, Pageable pageable); + Page findByRole(UserRole role, Pageable pageable); - Page findByActive(boolean active, Pageable pageable); + Page findByActive(boolean active, Pageable pageable); - @Query(""" + @Query(""" SELECT u FROM AppUser u WHERE (:email IS NULL OR LOWER(CAST(COALESCE(u.email, '') AS string)) LIKE LOWER(CONCAT('%', CAST(:email AS string), '%'))) @@ -35,17 +35,17 @@ public interface AppUserRepository extends JpaRepository { AND (:role IS NULL OR u.role = :role) AND (:active IS NULL OR u.active = :active) """) - Page findAllWithFilters(@Param("email") String email, @Param("name") String name, - @Param("role") UserRole role, @Param("active") Boolean active, Pageable pageable); + Page findAllWithFilters(@Param("email") String email, @Param("name") String name, + @Param("role") UserRole role, @Param("active") Boolean active, Pageable pageable); - @Query(""" + @Query(""" SELECT u FROM AppUser u - WHERE (:search IS NULL OR + WHERE (:search IS NULL OR LOWER(CAST(COALESCE(u.email, '') AS string)) LIKE LOWER(CONCAT('%', CAST(:search AS string), '%')) OR LOWER(CAST(COALESCE(u.name, '') AS string)) LIKE LOWER(CONCAT('%', CAST(:search AS string), '%')) OR LOWER(CAST(COALESCE(u.githubLogin, '') AS string)) LIKE LOWER(CONCAT('%', CAST(:search AS string), '%')) OR LOWER(CAST(COALESCE(u.githubId, '') AS string)) LIKE LOWER(CONCAT('%', CAST(:search AS string), '%'))) """) - Page searchUsers(@Param("search") String search, Pageable pageable); -} \ No newline at end of file + Page searchUsers(@Param("search") String search, Pageable pageable); +}