Done ticket GEPAFINBE-150
This commit is contained in:
@@ -226,7 +226,7 @@ public class AssignedApplicationsDao {
|
||||
log.info("Assigned Application deleted with ID: {}", id);
|
||||
}
|
||||
|
||||
public List<AssignedApplicationsResponse> getAllAssignedApplications(HttpServletRequest request, Long userId) {
|
||||
public List<AssignedApplicationsResponse> getAllAssignedApplications(HttpServletRequest request, Long userId,List<AssignedApplicationEnum> statusList) {
|
||||
UserEntity user = validator.validateUser(request);
|
||||
if(validator.checkIsPreInstructor() && userId == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.USER_ID_NOT_NULL_MSG));
|
||||
@@ -234,18 +234,24 @@ public class AssignedApplicationsDao {
|
||||
if(userId != null) {
|
||||
validator.validatePreInstructor(request, userId);
|
||||
}
|
||||
Specification<AssignedApplicationsEntity> spec = search(user.getHub().getId() ,userId);
|
||||
Specification<AssignedApplicationsEntity> spec = search(user.getHub().getId() ,userId,statusList);
|
||||
List<AssignedApplicationsEntity> assignedApplicationsEntityList = assignedApplicationsRepository.findAll(spec);
|
||||
return assignedApplicationsEntityList.stream()
|
||||
.map(entity -> convertEntityToResponse(entity))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
private Specification<AssignedApplicationsEntity> search(Long hubId, Long userId) {
|
||||
private Specification<AssignedApplicationsEntity> search(Long hubId, Long userId,List<AssignedApplicationEnum> statusList) {
|
||||
return (root, query, builder) -> {
|
||||
Predicate predicate = builder.isFalse(root.get("isDeleted"));
|
||||
if (userId != null) {
|
||||
predicate = builder.and(predicate, builder.equal(root.get("userId"), userId));
|
||||
}
|
||||
if (statusList != null && !statusList.isEmpty()) {
|
||||
List<String> statusNames = statusList.stream()
|
||||
.map(Enum::name)
|
||||
.collect(Collectors.toList());
|
||||
predicate = builder.and(predicate, root.get("status").in(statusNames));
|
||||
}
|
||||
query.orderBy(
|
||||
builder.desc(builder.isNotNull(root.get(GepafinConstant.ASSIGNED_AT))),
|
||||
builder.desc(root.get(GepafinConstant.ASSIGNED_AT))
|
||||
|
||||
Reference in New Issue
Block a user