Merge pull request #200 from Kitzanos/feature/GEPAFINBE-161
GEPAFINBE-161(Update Instructor Dashboard API Access)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
@@ -10,6 +12,9 @@ import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
import net.gepafin.tendermanagement.service.CompanyService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ForbiddenAccessException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -278,14 +283,16 @@ public class DashboardDao {
|
||||
AmendmentWidgetResponseBean amendmentWidgetResponseBean = initializeAmendmentResponseBean();
|
||||
|
||||
Long hubId = userEntity.getHub().getId();
|
||||
List<Long> applicationIds = getApplicationIdsForUserOrHub(userEntity,hubId);
|
||||
List<Long> applicationIds = getApplicationIdsForUserOrHub(userEntity,hubId,null);
|
||||
setAmendmentCounts(applicationIds,amendmentWidgetResponseBean, hubId);
|
||||
calculateExpiringRequestsIn48Hours(applicationIds,amendmentWidgetResponseBean, hubId);
|
||||
calculateAverageResponseDays(applicationIds,amendmentWidgetResponseBean,hubId);
|
||||
return amendmentWidgetResponseBean;
|
||||
}
|
||||
public List<Long> getApplicationIdsForUserOrHub(UserEntity userEntity, Long hubId) {
|
||||
if (validator.checkIsPreInstructor()) {
|
||||
public List<Long> getApplicationIdsForUserOrHub(UserEntity userEntity, Long hubId , Long userId) {
|
||||
if (userId != null) {
|
||||
return assignedApplicationsRepository.findApplicationIdsByUserIdAndIsDeletedFalse(userId);
|
||||
} else if (validator.checkIsPreInstructor()) {
|
||||
return assignedApplicationsRepository.findApplicationIdsByUserIdAndIsDeletedFalse(userEntity.getId());
|
||||
} else {
|
||||
return applicationRepository.findApplicationIdsByHubId(hubId);
|
||||
@@ -423,10 +430,21 @@ public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
public PreInstructorWidgetResponseBean getDashboardWidgetForPreInstructor(UserEntity userEntity) {
|
||||
public PreInstructorWidgetResponseBean getDashboardWidgetForPreInstructor(HttpServletRequest request, Long userId) {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
if (validator.checkIsPreInstructor() && userId == null) {
|
||||
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.USER_ID_NOT_NULL_MSG));
|
||||
}
|
||||
if (userId != null) {
|
||||
validator.validatePreInstructor(request, userId);
|
||||
if (validator.checkIsInstructorManager() && !userEntity.getId().equals(userId)) {
|
||||
throw new ForbiddenAccessException(Status.FORBIDDEN,
|
||||
Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
|
||||
}
|
||||
}
|
||||
PreInstructorWidgetResponseBean preInstructorWidgetResponseBean = initializeDashboardPreInstructorResponseBean();
|
||||
Long hubId = userEntity.getHub().getId();
|
||||
List<Long> applicationIds = getApplicationIdsForUserOrHub(userEntity, hubId);
|
||||
List<Long> applicationIds = getApplicationIdsForUserOrHub(userEntity, hubId,userId);
|
||||
setPreInstructorWidgets(applicationIds, preInstructorWidgetResponseBean,hubId);
|
||||
calculateAverageEvaluationTime(applicationIds, preInstructorWidgetResponseBean, hubId);
|
||||
return preInstructorWidgetResponseBean;
|
||||
|
||||
@@ -15,7 +15,7 @@ public interface DashboardService {
|
||||
public BeneficiaryWidgetResponseBean getDashboardWidgetForBeneficiary(HttpServletRequest request, Long companyId);
|
||||
public ApplicationWidgetResponseBean getApplicationDetails(HttpServletRequest request);
|
||||
public AmendmentWidgetResponseBean getAmendmentDetails(HttpServletRequest request);
|
||||
public PreInstructorWidgetResponseBean getDashboardWidgetForPreInstructor(HttpServletRequest request);
|
||||
public PreInstructorWidgetResponseBean getDashboardWidgetForPreInstructor(HttpServletRequest request,Long userId);
|
||||
public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(HttpServletRequest request);
|
||||
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ public class DashboardServiceImpl implements DashboardService {
|
||||
return dashboardDao.getAmendmentDetails(userEntity);
|
||||
}
|
||||
@Override
|
||||
public PreInstructorWidgetResponseBean getDashboardWidgetForPreInstructor(HttpServletRequest request) {
|
||||
UserEntity userEntity = validator.validateUser(request);
|
||||
return dashboardDao.getDashboardWidgetForPreInstructor(userEntity);
|
||||
public PreInstructorWidgetResponseBean getDashboardWidgetForPreInstructor(HttpServletRequest request,Long userId) {
|
||||
validator.validateUser(request);
|
||||
return dashboardDao.getDashboardWidgetForPreInstructor(request,userId);
|
||||
}
|
||||
@Override
|
||||
public AssignedApplicationWidgetResponseBean getApplicationDetailsForEvaluation(HttpServletRequest request) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
public interface DashboardApi {
|
||||
|
||||
@@ -107,7 +108,7 @@ public interface DashboardApi {
|
||||
@GetMapping(value = "/instructor/amendment",
|
||||
produces = { "application/json" })
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN') || hasRole('ROLE_INSTRUCTOR_MANAGER')|| hasRole('ROLE_PRE_INSTRUCTOR')")
|
||||
ResponseEntity<Response<PreInstructorWidgetResponseBean>> getDashboardWidgetForPreInstructor(HttpServletRequest request);
|
||||
ResponseEntity<Response<PreInstructorWidgetResponseBean>> getDashboardWidgetForPreInstructor(HttpServletRequest request, @Parameter(description = "The User ID", required = false) @RequestParam(value = "userId",required = false) Long userId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -75,12 +75,12 @@ public class DashboardApiController implements DashboardApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<PreInstructorWidgetResponseBean>> getDashboardWidgetForPreInstructor(HttpServletRequest request) {
|
||||
public ResponseEntity<Response<PreInstructorWidgetResponseBean>> getDashboardWidgetForPreInstructor(HttpServletRequest request,Long userId) {
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Get dashboard stats widget for amendment page" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_DASHBOARD_WIDGET_FOR_PRE_INSTRUCTOR).build());
|
||||
|
||||
PreInstructorWidgetResponseBean widgetResponseBean= dashboardService.getDashboardWidgetForPreInstructor(request);
|
||||
PreInstructorWidgetResponseBean widgetResponseBean= dashboardService.getDashboardWidgetForPreInstructor(request,userId);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(widgetResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.DASHBOARD_WIDGET_FETCHED_SUCCESSFULLY)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user