Skip to content

Commit

Permalink
fix: improve search endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
BettyB979 committed Dec 18, 2024
1 parent 03ee34f commit 986d604
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,52 +71,18 @@ OR UPPER(first_name || ' ' || last_name) LIKE :param || '%'
@Query(
value = """
SELECT
*
c.identifier as identifier,
c.email as email,
c.first_name as firstName,
c.last_name as lastName
FROM
contact c
WHERE
UPPER(c.last_name) LIKE :param || '%'
UNION
SELECT
*
FROM
contact c
WHERE
UPPER(first_name || ' ' || last_name) LIKE :param || '%'
UNION
SELECT
*
FROM
contact c
WHERE
UPPER(c.email) LIKE :param || '%'
UNION
SELECT
*
FROM
contact c
WHERE
UPPER(c.identifier) LIKE :param || '%'
OR UPPER(first_name || ' ' || last_name) LIKE :param || '%'
OR UPPER(c.email) LIKE :param || '%'
OR UPPER(c.identifier) LIKE :param || '%'
""",
countQuery = """
SELECT COUNT(*)
FROM (
SELECT 1
FROM contact c
WHERE UPPER(c.last_name) LIKE :param || '%'
UNION
SELECT 1
FROM contact c
WHERE UPPER(c.first_name || ' ' || c.last_name) LIKE :param || '%'
UNION
SELECT 1
FROM contact c
WHERE UPPER(c.email) LIKE :param || '%'
UNION
SELECT 1
FROM contact c
WHERE UPPER(c.identifier) LIKE :param || '%'
) AS count_query""",
nativeQuery = true
)
Page<SearchContactDto> findByParam(String param, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ Questioning findByIdPartitioningAndSurveyUnitIdSu(String idPartitioning,
LEFT JOIN FETCH q.questioningEvents evt
LEFT JOIN FETCH q.questioningCommunications comm
JOIN FETCH q.surveyUnit su
WHERE UPPER(q.surveyUnit.idSu) = :searchParam
WHERE q.surveyUnit.idSu = :searchParam
UNION
SELECT q FROM Questioning q
LEFT JOIN FETCH q.questioningAccreditations acc
LEFT JOIN FETCH q.questioningEvents evt
LEFT JOIN FETCH q.questioningCommunications comm
JOIN FETCH q.surveyUnit su
WHERE UPPER(q.surveyUnit.identificationName) = :searchParam
WHERE q.surveyUnit.identificationName = :searchParam
UNION
SELECT q FROM Questioning q
LEFT JOIN FETCH q.questioningAccreditations acc
LEFT JOIN FETCH q.questioningEvents evt
LEFT JOIN FETCH q.questioningCommunications comm
JOIN FETCH q.surveyUnit su
WHERE UPPER(q.surveyUnit.identificationCode) = :searchParam
WHERE q.surveyUnit.identificationCode = :searchParam
UNION
SELECT q FROM Questioning q
LEFT JOIN FETCH q.questioningAccreditations acc
Expand All @@ -47,7 +47,7 @@ WHERE UPPER(q.surveyUnit.identificationCode) = :searchParam
WHERE EXISTS (
SELECT 1 FROM QuestioningAccreditation qa
WHERE qa.questioning = q
AND UPPER(qa.idContact) = :searchParam)
AND qa.idContact = :searchParam)
""")
List<Questioning> findQuestioningByParam(String searchParam);

Expand Down

0 comments on commit 986d604

Please sign in to comment.