-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RI-112: [admin/companies] ajoute un composant de filtre au tableau des compagnies #168
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
41faab2
RI-112: filtrage d'une offre
nekorpeche e0a1ec7
RI-136: ajoute un composant de filtre au tableau des compagnies
nekorpeche a6a430b
RI-112: ajoute un composant de filtre au tableau des compagnies
nekorpeche 78c31e5
RI-112: ajoute un composant de filtre au tableau des compagnies
nekorpeche 2fb3391
RI-112: ajoute un composant de filtre au tableau des compagnies
nekorpeche 39b7239
RI-112: ajoute un composant de filtre au tableau des compagnies
matthieuaudemard 9f60543
RI-112: ajoute un composant de filtre au tableau des compagnies
matthieuaudemard 4bcf5ee
RI-112: ajoute un composant de filtre au tableau des compagnies
matthieuaudemard 9c66bfb
RI-112: ajoute un composant de filtre au tableau des compagnies
matthieuaudemard 24eff5e
RI-112: [admin/company] ajoute un composant de filtre au tableau des …
nekorpeche 95e8ecc
RI-112: [admin/company] ajoute un composant de filtre au tableau des …
nekorpeche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...src/main/java/com/dynonuggets/refonteimplicaction/repository/CompanyRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.dynonuggets.refonteimplicaction.repository; | ||
|
||
import com.dynonuggets.refonteimplicaction.model.Company; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public interface CompanyRepositoryCustom { | ||
/** | ||
* @param pageable l'objet de pagination | ||
* @param keyword la chaîne de caractère à rechercher dans les champs keyword, description | ||
* @return la liste de résultats paginée des Company correspondant aux critères | ||
*/ | ||
Page<Company> findAllWithCriteria(final Pageable pageable, final String keyword); | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
.../main/java/com/dynonuggets/refonteimplicaction/repository/impl/CompanyRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.dynonuggets.refonteimplicaction.repository.impl; | ||
|
||
import com.dynonuggets.refonteimplicaction.model.Company; | ||
import com.dynonuggets.refonteimplicaction.repository.CompanyRepositoryCustom; | ||
import lombok.AllArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.query.QueryUtils; | ||
import org.springframework.data.support.PageableExecutionUtils; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.criteria.CriteriaBuilder; | ||
import javax.persistence.criteria.CriteriaQuery; | ||
import javax.persistence.criteria.Predicate; | ||
import javax.persistence.criteria.Root; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
public class CompanyRepositoryImpl implements CompanyRepositoryCustom { | ||
private final EntityManager entityManager; | ||
|
||
@Override | ||
public Page<Company> findAllWithCriteria(Pageable pageable, String keyword) { | ||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); | ||
CriteriaQuery<Company> query = criteriaBuilder.createQuery(Company.class); | ||
Root<Company> queryRoot = query.from(Company.class); | ||
List<Predicate> predicates = new ArrayList<>(); | ||
|
||
// gestion du tri des résultats | ||
if (!pageable.getSort().isEmpty()) { | ||
query.orderBy(QueryUtils.toOrders(pageable.getSort(), queryRoot, criteriaBuilder)); | ||
} | ||
|
||
// recherche par mot clé dans le nom et description | ||
if (StringUtils.isNotEmpty(keyword)) { | ||
keyword = "%" + keyword + "%"; | ||
Predicate namePredicate = criteriaBuilder.like(queryRoot.get("name"), keyword); | ||
Predicate descriptionPredicate = criteriaBuilder.like(queryRoot.get("description"), keyword); | ||
predicates.add(criteriaBuilder.or(namePredicate, descriptionPredicate)); | ||
} | ||
|
||
|
||
// combinaison des différents prédicats | ||
Predicate finalPredicate = criteriaBuilder.and(predicates.toArray(new Predicate[0])); | ||
|
||
query.where(finalPredicate); | ||
|
||
CriteriaQuery<Long> countQuery = criteriaBuilder.createQuery(Long.class); | ||
countQuery.select(criteriaBuilder.count(countQuery.from(Company.class))); | ||
final Long totalCount = entityManager.createQuery(countQuery).getSingleResult(); | ||
final int firstResult = pageable.getPageNumber() * pageable.getPageSize(); | ||
|
||
// lancement de la requête et mise en place de la pagination | ||
final List<Company> results = entityManager.createQuery(query) | ||
.setFirstResult(firstResult) | ||
.setMaxResults(pageable.getPageSize()) | ||
.getResultList(); | ||
return PageableExecutionUtils.getPage(results, pageable, () -> totalCount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je vois bien que la valeur est affectée ici, mais aussi qu'elle ne sert à rien d'autre.