Skip to content

Commit

Permalink
feat: improve search contacts (add city and function)
Browse files Browse the repository at this point in the history
  • Loading branch information
BettyB979 committed Mar 19, 2024
1 parent 08f6100 commit c5bbaa2
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>fr.insee.survey</groupId>
<artifactId>platine-management</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>
<name>platine-management</name>
<description>REST API for communication between DB and Platine-Management UI and Platine-My-Surveys UI</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class AddressDto {
private String cedexCode;
private String cedexName;
private String specialDistribution;
private String usualCompanyName;
private String countryCode;
private String countryName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ public interface ContactRepository extends PagingAndSortingRepository<Contact, S
*
FROM
contact c
JOIN
address a
ON
c.address_id = a.id
WHERE
(:identifier IS NULL OR UPPER(c.identifier) = UPPER(:identifier))
AND
(:name IS NULL OR UPPER(CONCAT(c.first_name, ' ', c.last_name)) LIKE UPPER(CONCAT('%', :name, '%')))
AND
(:email IS NULL OR UPPER(c.email) = UPPER(:email))
AND
(:function IS NULL OR UPPER(c.function) = UPPER(:function))
AND
(:city IS NULL OR UPPER(a.city_name) = UPPER(:city))
""",
nativeQuery = true
)
Page<Contact> findByParameters(String identifier, String name, String email, Pageable pageable);
Page<Contact> findByParameters(String identifier, String name, String email, String city, String function, Pageable pageable);


}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface ContactService {
*/
void deleteContact(String identifier);

Page<Contact> findByParameters(String identifier, String name, String email, Pageable pageable);
Page<Contact> findByParameters(String identifier, String name, String email, String city, String function, Pageable pageable);

Contact createContactAddressEvent(Contact contact, JsonNode payload);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -53,8 +56,8 @@ public void deleteContact(String identifier) {
}

@Override
public Page<Contact> findByParameters(String identifier, String name, String email, Pageable pageable) {
return contactRepository.findByParameters(identifier,name,email,pageable);
public Page<Contact> findByParameters(String identifier, String name, String email, String city, String function, Pageable pageable) {
return contactRepository.findByParameters(identifier, name, email, city, function, pageable);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public ResponseEntity<Page<SearchContactDto>> searchContacts(
@RequestParam(required = false) String identifier,
@RequestParam(required = false) String name,
@RequestParam(required = false) String email,
@RequestParam(required = false) String city,
@RequestParam(required = false) String function,
@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(defaultValue = "identifier") String sort) {
Expand All @@ -80,7 +82,7 @@ public ResponseEntity<Page<SearchContactDto>> searchContacts(

Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort));

Page<SearchContactDto> pageSearchContact = searchContactService.searchContactCrossDomain(identifier, name, email,
Page<SearchContactDto> pageSearchContact = searchContactService.searchContactCrossDomain(identifier, name, email, city, function,
pageable);
return new ResponseEntity<>(pageSearchContact, HttpStatus.OK);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ public interface SearchContactService {
* @param identifier contact identifier
* @param name (first name or and lastName)
* @param email contact email
* @param city contact city
* @param function contact function
* @return
*/
Page<SearchContactDto> searchContactCrossDomain(
String identifier,
String name,
String email,
String city,
String function,
Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public Page<SearchContactDto> searchContactCrossDomain(
String identifier,
String name,
String email,
String city,
String function,
Pageable pageable) {

List<SearchContactDto> listSearchContact = new ArrayList<>();

Page<Contact> pageContact = contactService.findByParameters(identifier, name, email, pageable);
Page<Contact> pageContact = contactService.findByParameters(identifier, name, email,city, function, pageable);

for (Contact c : pageContact) {
listSearchContact.add(transformContactTSearchContactDto(c));
Expand Down

0 comments on commit c5bbaa2

Please sign in to comment.