Skip to content
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-174: modifier les listing des offres pour n'afficher que les offres non archivées #207

Merged
merged 4 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.dynonuggets.refonteimplicaction.exception.ImplicactionException;
import com.dynonuggets.refonteimplicaction.service.JobPostingService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -36,11 +37,13 @@ public ResponseEntity<Page<JobPostingDto>> getAllByCriteria(
@RequestParam(value = "sortOrder", defaultValue = "ASC") String sortOrder,
@RequestParam(value = "search", defaultValue = "") String search,
@RequestParam(value = "contractType", required = false) String contractType,
@RequestParam(value = "checkApply", required = false) String applyCheckAsString
@RequestParam(value = "checkApply", required = false) String checkApplyAsString,
@RequestParam(value = "archive", required = false) String archiveAsString
) {
Pageable pageable = PageRequest.of(page, rows, Sort.by(Sort.Direction.valueOf(sortOrder), sortBy));
final boolean applyCheck = Boolean.parseBoolean(applyCheckAsString);
Page<JobPostingDto> jobPostingDtos = jobPostingService.getAllWithCriteria(pageable, search, contractType, applyCheck);
final boolean applyCheck = Boolean.parseBoolean(checkApplyAsString);
final Boolean isArchive = StringUtils.isNotBlank(archiveAsString) ? Boolean.parseBoolean(archiveAsString) : null;
Page<JobPostingDto> jobPostingDtos = jobPostingService.getAllWithCriteria(pageable, search, contractType, isArchive, applyCheck);
return ResponseEntity.ok(jobPostingDtos);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface JobPostingRepositoryCustom {
* @param contractType le type de contrat à rechercher (CDD, CDI)
* @return la liste de résultats paginée des JobPostings correspondant aux critères
*/
Page<JobPosting> findAllWithCriteria(final Pageable pageable, final String search, final String contractType);
Page<JobPosting> findAllWithCriteria(final Pageable pageable, final String search, final String contractType, final Boolean archive);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class JobPostingRepositoryImpl implements JobPostingRepositoryCustom {
private final EntityManager entityManager;

@Override
public Page<JobPosting> findAllWithCriteria(Pageable pageable, String search, String contractType) {
public Page<JobPosting> findAllWithCriteria(Pageable pageable, String search, String contractType, Boolean archive) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<JobPosting> query = criteriaBuilder.createQuery(JobPosting.class);
Root<JobPosting> queryRoot = query.from(JobPosting.class);
Expand All @@ -49,6 +49,9 @@ public Page<JobPosting> findAllWithCriteria(Pageable pageable, String search, St
predicates.add(criteriaBuilder.equal(queryRoot.get("contractType"), ContractTypeEnum.valueOf(contractType)));
}

if (archive != null) {
predicates.add(criteriaBuilder.equal(queryRoot.get("archive"), archive));
}
// combinaison des différents prédicats
Predicate finalPredicate = criteriaBuilder.and(predicates.toArray(new Predicate[0]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public JobPostingDto getJobById(Long jobId) {
return jobDto;
}

public Page<JobPostingDto> getAllWithCriteria(Pageable pageable, String search, String contractType, boolean applyCheck) {
public Page<JobPostingDto> getAllWithCriteria(Pageable pageable, String search, String contractType, Boolean archive, boolean applyCheck) {
// récupération des jobs
final Page<JobPosting> jobs = jobPostingRepository.findAllWithCriteria(pageable, search, contractType);
final Page<JobPosting> jobs = jobPostingRepository.findAllWithCriteria(pageable, search, contractType, archive);
if (applyCheck) {
final List<Long> jobIds = jobs.stream().map(JobPosting::getId).collect(toList());
final List<Long> jobAppliesIds = getAllAppliesWithJobIdsIn(jobIds, authService.getCurrentUser().getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ void getJobPostingsListShouldListAllJobs() throws Exception {
// given
Page<JobPostingDto> jobPostingPageMockResponse = new PageImpl<>(jobPostings);

given(jobPostingService.getAllWithCriteria(any(), anyString(), anyString(), anyBoolean())).willReturn(jobPostingPageMockResponse);
given(jobPostingService.getAllWithCriteria(any(), anyString(), anyString(), anyBoolean(), anyBoolean())).willReturn(jobPostingPageMockResponse);

// when
ResultActions resultActions = mvc.perform(
get(JOBS_BASE_URI).param("contractType", CDD.name())
get(JOBS_BASE_URI).param("contractType", CDD.name()).param("archive", "true")

).andDo(print());

Expand All @@ -74,15 +74,15 @@ void getJobPostingsListShouldListAllJobs() throws Exception {
.andExpect(jsonPath(contentPath + ".salary", is(jobPostings.get(i).getSalary())));
}

verify(jobPostingService, times(1)).getAllWithCriteria(any(), anyString(), anyString(), anyBoolean());
verify(jobPostingService, times(1)).getAllWithCriteria(any(), anyString(), anyString(), anyBoolean(), anyBoolean());
}

@Test
void getAllWithoutJwtShouldBeForbidden() throws Exception {
mvc.perform(get(JOBS_BASE_URI)).andDo(print())
.andExpect(status().isForbidden());

verify(jobPostingService, times(0)).getAllWithCriteria(any(), anyString(), anyString(), anyBoolean());
verify(jobPostingService, times(0)).getAllWithCriteria(any(), anyString(), anyString(), anyBoolean(), anyBoolean());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ void should_get_all_jobs_with_criteria_and_check_apply() {
Page<JobPosting> jobPage = new PageImpl<>(jobs);
Pageable pageable = PageRequest.of(0, 10);
User currentUser = User.builder().id(123L).build();
given(jobPostingRepository.findAllWithCriteria(any(), anyString(), anyString())).willReturn(jobPage);
given(jobPostingRepository.findAllWithCriteria(any(), anyString(), anyString(), anyBoolean())).willReturn(jobPage);
given(jobApplicationRepository.findAllByJob_IdInAndUser_Id(anyList(), anyLong())).willReturn(Collections.emptyList());
given(authService.getCurrentUser()).willReturn(currentUser);
given(jobPostingAdapter.toDto(any())).willReturn(JobPostingDto.builder().build());

// when
final Page<JobPostingDto> actual = JobPostingService.getAllWithCriteria(pageable, "", CDD.name(), true);
final Page<JobPostingDto> actual = JobPostingService.getAllWithCriteria(pageable, "", CDD.name(), false, true);

// then
assertThat(actual.getTotalElements()).isEqualTo(jobPage.getTotalElements());
Expand All @@ -67,10 +67,10 @@ void should_get_all_jobs_with_criteria_and_check_apply_false() {
List<JobPosting> jobs = Collections.singletonList(JobPosting.builder().id(123L).contractType(CDD).build());
Page<JobPosting> jobPage = new PageImpl<>(jobs);
Pageable pageable = PageRequest.of(0, 10);
given(jobPostingRepository.findAllWithCriteria(any(), anyString(), anyString())).willReturn(jobPage);
given(jobPostingRepository.findAllWithCriteria(any(), anyString(), anyString(), anyBoolean())).willReturn(jobPage);

// when
final Page<JobPostingDto> actual = JobPostingService.getAllWithCriteria(pageable, "", CDD.name(), false);
final Page<JobPostingDto> actual = JobPostingService.getAllWithCriteria(pageable, "", CDD.name(), false, false);

// then
assertThat(actual.getTotalElements()).isEqualTo(jobPage.getTotalElements());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,16 @@ export class ApiEndpointsService {
* Jobs
*/

getAllJobEndpoint(pageable: Pageable, criteria: JobCriteriaFilter, checkApply: boolean): string {
getAllJobEndpoint(pageable: Pageable, criteria: JobCriteriaFilter, archive: boolean, checkApply: boolean): string {
// on merge les filtres et les attributs de pagination
const objectParam = {
...criteria,
rows: pageable.rows,
page: pageable.page,
sortBy: pageable.sortBy,
sortOrder: pageable.sortOrder,
checkApply
checkApply,
archive: archive !== null ? `${archive}` : null
};
return ApiEndpointsService.createUrlWithQueryParameters(
Uris.JOBS.BASE_URI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class JobsListComponent extends BaseWithPaginationComponent<JobPosting, J

protected innerPaginate(): void {
this.jobsService
.getAllByCriteria(this.pageable, this.criteria, true)
.getAllByCriteria(this.pageable, this.criteria, false)
.pipe(finalize(() => this.isLoading = false))
.subscribe(
data => {
Expand Down
4 changes: 2 additions & 2 deletions frontend-implicaction/src/app/job/services/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class JobService {
) {
}

getAllByCriteria(pageable: Pageable, criteria: JobCriteriaFilter, applyCheck = false): Observable<any> {
return this.http.get(this.apiEndpointsService.getAllJobEndpoint(pageable, criteria, applyCheck));
getAllByCriteria(pageable: Pageable, criteria: JobCriteriaFilter, archive = null, applyCheck = false): Observable<any> {
return this.http.get(this.apiEndpointsService.getAllJobEndpoint(pageable, criteria, archive, applyCheck));
}

getById(jobId: string): Observable<JobPosting> {
Expand Down