Skip to content

Commit

Permalink
feat: improve search contact for new pilotage front (#79)
Browse files Browse the repository at this point in the history
* feat: search contact with one parameter

* fix: param not required in search contact

* chore(deps): update versions

* Update ContactRepository.java

* fix: search contact with contains
  • Loading branch information
BettyB979 authored Jul 10, 2024
1 parent 9c25b2c commit 1bb0133
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 60 deletions.
13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
<description>REST API for communication between DB and Platine-Management UI and Platine-My-Surveys UI</description>
<properties>
<java.version>21</java.version>
<springdoc-version>2.2.0</springdoc-version>
<modelmapper-version>3.1.0</modelmapper-version>
<springdoc-version>2.6.0</springdoc-version>
<modelmapper-version>3.2.0</modelmapper-version>
<jakarta-version>3.1.0</jakarta-version>
<jeasy-version>5.0.0</jeasy-version>
<easy-version>5.0.0</easy-version>
<postgre-version>42.7.3</postgre-version>
<javafaker-version>1.0.2</javafaker-version>
<sonar.organization>inseefr</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand Down Expand Up @@ -86,7 +87,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.9</version>
<version>${postgre-version}</version>
</dependency>
<!-- SECURITY -->
<dependency>
Expand Down Expand Up @@ -131,7 +132,7 @@
<dependency>
<groupId>org.jeasy</groupId>
<artifactId>easy-random-core</artifactId>
<version>${jeasy-version}</version>
<version>${easy-version}</version>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
Expand Down Expand Up @@ -186,7 +187,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<version>0.8.12</version>
<executions>
<execution>
<id>prepare-agent</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@ public interface ContactRepository extends PagingAndSortingRepository<Contact, S
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) LIKE UPPER(CONCAT('%', :function, '%')))
AND
(:city IS NULL OR UPPER(a.city_name) = UPPER(:city))
(:param IS NULL
OR UPPER(c.identifier) LIKE UPPER(CONCAT('%',:param, '%'))
OR UPPER(CONCAT(c.first_name, ' ', c.last_name)) LIKE UPPER(CONCAT('%', :param, '%'))
OR UPPER(c.email) LIKE UPPER(CONCAT('%',:param, '%'))
)
""",
nativeQuery = true
)
Page<Contact> findByParameters(String identifier, String name, String email, String city, String function, Pageable pageable);
Page<Contact> findByParameter(String param, Pageable pageable);


}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface ContactService {
* @param identifier contact identifier
* @return contact found
*/
Contact findByIdentifier(String identifier) ;
Contact findByIdentifier(String identifier);

/**
* Update an existing contact and its address, or creates a new one
Expand All @@ -40,11 +40,12 @@ public interface ContactService {

/**
* Delete a contact. Delete also the contact address.
*
* @param identifier contact identifier
*/
void deleteContact(String identifier);

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

Contact createContactAddressEvent(Contact contact, JsonNode payload);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public void deleteContact(String identifier) {
}

@Override
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);
public Page<Contact> findByParameter(String param, Pageable pageable) {
return contactRepository.findByParameter(param, pageable);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -65,25 +63,19 @@ public class SearchContactController {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = SearchContactDto.class)))),
@ApiResponse(responseCode = "400", description = "Bad Request")
})
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,
public Page<SearchContactDto> searchContacts(
@RequestParam(required = false) String param,
@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(defaultValue = "identifier") String sort) {
@RequestParam(defaultValue = "identifier") String sort) {

log.info(
"Search contact: identifier = {}, name= {}, email= {}, page= {}, pageSize= {} ",
identifier, name, email, page, pageSize);
"Search contact: param = {} ", param, page, pageSize);

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

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


}
Expand All @@ -94,7 +86,7 @@ public ResponseEntity<Page<SearchContactDto>> searchContacts(
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = AccreditationDetailDto.class)))),
@ApiResponse(responseCode = "400", description = "Bad Request")
})
public ResponseEntity<List<AccreditationDetailDto>> getContactAccreditations(
public List<AccreditationDetailDto> getContactAccreditations(
@PathVariable("id") String id,
@RequestParam(defaultValue = "false") boolean isFilterOpened) {

Expand All @@ -114,6 +106,7 @@ public ResponseEntity<List<AccreditationDetailDto>> getContactAccreditations(
survey.getSource().getShortWording(),
survey.getYear(),
part.getCampaign().getPeriod(),
part.getCampaign().getId(),
part.getId(),
part.getClosingDate(),
su.getIdSu(),
Expand All @@ -127,7 +120,7 @@ public ResponseEntity<List<AccreditationDetailDto>> getContactAccreditations(

}

return new ResponseEntity<>(listAccreditations, HttpStatus.OK);
return listAccreditations;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
public class AccreditationDetailDto {

private String sourceId;

private String surveyId;
private String sourceWording;
private int year;
private PeriodEnum period;
private String campaignId;
private String partition;
private Date partioningClosingDate;
private String surveyUnitId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@
public interface SearchContactService {

/**
* Search contact according to diffeent parameters
* @param identifier contact identifier
* @param name (first name or and lastName)
* @param email contact email
* @param city contact city
* @param function contact function
* @return
* Search contact according to different parameters
* @param param search contact parameter (mail or identifier or name
* @return Page SearchContactDto
*/
Page<SearchContactDto> searchContactCrossDomain(
String identifier,
String name,
String email,
String city,
String function,
String param,
Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,17 @@ public class SearchContactServiceImpl implements SearchContactService {

private final ContactService contactService;

private final PartitioningService partioningService;
private final PartitioningService partitioningService;

private final QuestioningAccreditationService questioningAccreditationService;


@Override
public Page<SearchContactDto> searchContactCrossDomain(
String identifier,
String name,
String email,
String city,
String function,
Pageable pageable) {
public Page<SearchContactDto> searchContactCrossDomain(String param, Pageable pageable) {

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

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

for (Contact c : pageContact) {
listSearchContact.add(transformContactTSearchContactDto(c));
Expand All @@ -60,7 +54,7 @@ private SearchContactDto transformContactTSearchContactDto(Contact c) {
searchContact.setListSurveyUnitNames(listAccreditations.stream().map(a -> a.getQuestioning().getSurveyUnit().getIdSu()).distinct().toList());
searchContact.setListSourcesId(listAccreditations.stream().
map(a ->
partioningService.findById(a.getQuestioning().getIdPartitioning()).getCampaign().getSurvey().getSource().getId()).distinct().toList());
partitioningService.findById(a.getQuestioning().getIdPartitioning()).getCampaign().getSurvey().getSource().getId()).distinct().toList());
return searchContact;
}
}

0 comments on commit 1bb0133

Please sign in to comment.