Skip to content

Commit

Permalink
RI-203: validation des groupes et des offres
Browse files Browse the repository at this point in the history
* code review
  • Loading branch information
nekorpeche committed Dec 11, 2021
1 parent f00335b commit e785e3a
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class GroupAdapter {
protected static final String DEFAULT_GROUP_IMAGE_URI = "assets/img/avatar-ia-group.png";

private FileService fileService;
private final UserAdapter userAdapter;

public Group toModel(GroupDto dto, User user) {
return Group.builder()
Expand All @@ -31,6 +30,8 @@ public Group toModel(GroupDto dto, User user) {

public GroupDto toDto(Group model) {
final String imageUrl = model.getImage() != null ? fileService.buildFileUri(model.getImage().getObjectKey()) : DEFAULT_GROUP_IMAGE_URI;
final String username = model.getUser() != null ? model.getUser().getUsername() : "";
final Long userId = model.getUser() != null ? model.getUser().getId() : null;
return GroupDto.builder()
.id(model.getId())
.name(model.getName())
Expand All @@ -39,8 +40,8 @@ public GroupDto toDto(Group model) {
.createdAt(model.getCreatedAt())
.imageUrl(imageUrl)
.valid(model.isValid())
.username(model.getUser().getUsername())
.userId(model.getUser().getId())
.username(username)
.userId(userId)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public ResponseEntity<GroupDto> createSubreddit(@RequestBody GroupDto group) {
return ResponseEntity.status(CREATED).body(saveDto);
}

@GetMapping(ACTIVE_GROUPS)
public ResponseEntity<Page<GroupDto>> getAllActiveGroups(
@GetMapping(VALIDATED_GROUPS_URI)
public ResponseEntity<Page<GroupDto>> getAllValidGroups(
@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "rows", defaultValue = "10") int rows,
@RequestParam(value = "sortBy", defaultValue = "id") String sortBy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ResponseEntity<Page<JobPostingDto>> getAllByCriteria(
return ResponseEntity.ok(jobPostingDtos);
}

@GetMapping(ACTIVE_JOBS)
@GetMapping(VALIDATED_JOBS)
public ResponseEntity<Page<JobPostingDto>> getAllActiveByCriteria(
@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "rows", defaultValue = "10") int rows,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class Group {
private Instant createdAt;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "user_id")
private User user;

@ManyToOne(fetch = LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public interface JobPostingRepositoryCustom {
* @param pageable l'objet de pagination
* @param search la chaîne de caratères à rechercher dans les champs title, description, keywords
* @param contractType le type de contrat à rechercher (CDD, CDI)
* @param active
* @param valid la validation de l'offre par l'administrateur
* @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, final Boolean archive, Boolean active);
Page<JobPosting> findAllWithCriteria(final Pageable pageable, final String search, final String contractType, final Boolean archive, Boolean valid);

}
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, Boolean archive, Boolean active) {
public Page<JobPosting> findAllWithCriteria(Pageable pageable, String search, String contractType, Boolean archive, Boolean valid) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<JobPosting> query = criteriaBuilder.createQuery(JobPosting.class);
Root<JobPosting> queryRoot = query.from(JobPosting.class);
Expand Down Expand Up @@ -53,8 +53,8 @@ public Page<JobPosting> findAllWithCriteria(Pageable pageable, String search, St
predicates.add(criteriaBuilder.equal(queryRoot.get("archive"), archive));
}

if (active != null) {
predicates.add(criteriaBuilder.equal(queryRoot.get("active"), active));
if (valid != null) {
predicates.add(criteriaBuilder.equal(queryRoot.get("valid"), valid));
}

// combinaison des différents prédicats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.dynonuggets.refonteimplicaction.repository.UserRepository;
import com.dynonuggets.refonteimplicaction.repository.SubredditRepository;
import com.dynonuggets.refonteimplicaction.repository.UserRepository;
import com.dynonuggets.refonteimplicaction.utils.Message;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -24,6 +23,7 @@
import java.util.List;

import static com.dynonuggets.refonteimplicaction.utils.Message.GROUP_NOT_FOUND_MESSAGE;
import static com.dynonuggets.refonteimplicaction.utils.Message.USER_NOT_FOUND_MESSAGE;
import static java.util.stream.Collectors.toList;

@Service
Expand All @@ -42,7 +42,7 @@ public GroupDto save(MultipartFile image, GroupDto groupDto) {
final FileModel fileModel = cloudService.uploadImage(image);
final FileModel fileSave = fileRepository.save(fileModel);
User user = userRepository.findById(groupDto.getUserId())
.orElseThrow(() -> new UserNotFoundException(String.format(Message.USER_NOT_FOUND_MESSAGE, groupDto.getUserId())));
.orElseThrow(() -> new UserNotFoundException(String.format(USER_NOT_FOUND_MESSAGE, groupDto.getUserId())));
Group group = groupAdapter.toModel(groupDto, user);
group.setImage(fileSave);
group.setCreatedAt(Instant.now());
Expand All @@ -56,7 +56,7 @@ public GroupDto save(MultipartFile image, GroupDto groupDto) {
@Transactional
public GroupDto save(GroupDto groupDto) {
User user = userRepository.findById(groupDto.getUserId())
.orElseThrow(() -> new UserNotFoundException(String.format(Message.USER_NOT_FOUND_MESSAGE, groupDto.getUserId())));
.orElseThrow(() -> new UserNotFoundException(String.format(USER_NOT_FOUND_MESSAGE, groupDto.getUserId())));
Group group = groupAdapter.toModel(groupDto, user);
group.setCreatedAt(Instant.now());
group.setUser(authService.getCurrentUser());
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 archive, boolean applyCheck, Boolean active) {
public Page<JobPostingDto> getAllWithCriteria(Pageable pageable, String search, String contractType, Boolean archive, boolean applyCheck, Boolean valid) {
// récupération des jobs
final Page<JobPosting> jobs = jobPostingRepository.findAllWithCriteria(pageable, search, contractType, archive, active);
final Page<JobPosting> jobs = jobPostingRepository.findAllWithCriteria(pageable, search, contractType, archive, valid);
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 @@ -21,7 +21,7 @@ public class ApiUrls {
public static final String ARCHIVE_JOBS_URI = "/archive";
public static final String GET_PENDING_JOB_URI = "/pending";
public static final String VALIDATE_JOB_URI = "/validate";
public static final String ACTIVE_JOBS = "/active";
public static final String VALIDATED_JOBS = "/validated";

// POSTS
public static final String POSTS_BASE_URI = "/api/posts";
Expand All @@ -34,7 +34,7 @@ public class ApiUrls {
public static final String CREATE_NO_IMAGE = "/no-image";
public static final String GET_PENDING_GROUP_URI = "/pending";
public static final String VALIDATE_GROUP_URI = "/validate";
public static final String ACTIVE_GROUPS = "/active";
public static final String VALIDATED_GROUPS_URI = "/validated";
public static final String SUBSCRIBE_GROUP = "/{groupName}/subscribe";

// COMMENTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ void should_map_to_dto_with_count_when_model_has_posts() {

assertThat(actualDto.getNumberOfPosts()).isEqualTo(expectedModel.getPosts().size());
assertThat(actualDto.getImageUrl()).isEqualTo(GroupAdapter.DEFAULT_GROUP_IMAGE_URI);
assertThat(actualDto.getUsername()).isEqualTo(expectedModel.getUser().getUsername());
assertThat(actualDto.getUserId()).isEqualTo(expectedModel.getUser().getId());
}

@Test
Expand Down Expand Up @@ -118,5 +120,7 @@ void should_map_to_dto_with_image_url_when_model_has_image() {

assertThat(actualDto.getNumberOfPosts()).isZero();
assertThat(actualDto.getImageUrl()).contains(expectedUrl);
assertThat(actualDto.getUsername()).isEqualTo(expectedModel.getUser().getUsername());
assertThat(actualDto.getUserId()).isEqualTo(expectedModel.getUser().getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void should_list_all_subreddit_with_no_authentication() throws Exception {
given(userRepository.findById(any())).willReturn(Optional.of(user));

// when
final ResultActions resultActions = mvc.perform(get(GROUPS_BASE_URI + ACTIVE_GROUPS).contentType(APPLICATION_JSON));
final ResultActions resultActions = mvc.perform(get(GROUPS_BASE_URI + VALIDATED_GROUPS_URI).contentType(APPLICATION_JSON));

// then
resultActions.andDo(print())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class PendingGroupTableComponent extends BaseWithPaginationComponent<Grou

isLoading = true;
selectedOrderCode: string;
sortDirection = SortDirectionEnum;
rowsPerPage = this.pageable.rowsPerPages[0];

constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {Component} from '@angular/core';
import {BaseWithPaginationComponent} from '../../../../shared/components/base-with-pagination/base-with-pagination.component';
import {JobPosting} from '../../../../shared/models/job-posting';
import {JobSortEnum} from '../../../../job/enums/job-sort.enum';
import {SortDirectionEnum} from '../../../../shared/enums/sort-direction.enum';
import {ToasterService} from '../../../../core/services/toaster.service';
import {JobService} from '../../../../job/services/job.service';
import {ActivatedRoute} from '@angular/router';
Expand All @@ -18,9 +16,6 @@ export class PendingJobTableComponent extends BaseWithPaginationComponent<JobPos

isLoading = true;
// Pagination et filtres
orderByEnums = JobSortEnum.all();
selectedOrderCode: string;
sortDirection = SortDirectionEnum;
rowsPerPage = this.pageable.rowsPerPages[0];

constructor(
Expand All @@ -35,9 +30,7 @@ export class PendingJobTableComponent extends BaseWithPaginationComponent<JobPos
this.jobsService
.validateJob(job)
.subscribe(
() => {
this.paginate({first: this.pageable.first, rows: this.pageable.rows});
},
() => this.paginate({first: this.pageable.first, rows: this.pageable.rows}),
() => this.toastService.error('Oops', `Une erreur est survenue lors de la validation de l'offre.`),
() => this.toastService.success('Succès', `L'offre ${job.title} est désormais validée.`),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class ApiEndpointsService {
archive: archive !== null ? `${archive}` : null
};
return ApiEndpointsService.createUrlWithQueryParameters(
Uris.JOBS.ACTIVE_JOBS,
Uris.JOBS.VALIDATED_JOBS,
(qs: QueryStringParameters) => {
this.buildQueryStringFromFilters(objectParam, qs);
});
Expand Down Expand Up @@ -364,7 +364,7 @@ export class ApiEndpointsService {
}

findAllActiveGroupsEndpoint(pageable: Pageable): string {
return ApiEndpointsService.createUrlWithPageable(Uris.GROUP.ACTIVE_GROUPS, pageable);
return ApiEndpointsService.createUrlWithPageable(Uris.GROUP.VALIDATED_GROUPS, pageable);
}

getValidateGroupEndpoint(): string {
Expand Down
8 changes: 6 additions & 2 deletions frontend-implicaction/src/app/shared/models/uris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ export class Uris {
static readonly BASE_URI = 'job-postings';
static readonly GET_ALL_PENDING_JOBS = 'job-postings/pending';
static readonly VALIDATE_JOB = 'job-postings/validate';
static readonly ACTIVE_JOBS = 'job-postings/active';
static readonly VALIDATED_JOBS = 'job-postings/validated';
static readonly TOGGLE_ARCHIVE = 'job-postings/archive';

static readonly VALIDATE_GROUP = 'groups/validate';
static readonly GET_ALL_PENDING_GROUPS = 'groups/pending';
static readonly VALIDATED_GROUPS = 'groups/validated';
};

/**
Expand Down Expand Up @@ -97,7 +101,7 @@ export class Uris {
static readonly ACTIVATE_GROUP = 'groups/activate';
static readonly VALIDATE_GROUP = 'groups/validate';
static readonly GET_ALL_PENDING_GROUPS = 'groups/pending';
static readonly ACTIVE_GROUPS = 'groups/active';
static readonly VALIDATED_GROUPS = 'groups/validated';
};

/**
Expand Down

0 comments on commit e785e3a

Please sign in to comment.