@Test public void testBulkPublishShifts() { this.createTwoShiftsAndVerify(); BulkPublishShiftsRequest bulkPublishShiftsRequest1 = BulkPublishShiftsRequest.builder() .companyId(company.getId()) .jobId(job.getId()) .teamId(team.getId()) .shiftStartAfter(Instant.now().minus(1, ChronoUnit.DAYS)) .shiftStartBefore(Instant.now().plus(5, ChronoUnit.DAYS)) .published(false) .build(); when(botClient.alertRemovedShifts(any(AlertRemovedShiftsRequest.class))) .thenReturn(BaseResponse.builder().message("Removed Shifts Alerted").build()); GenericShiftListResponse shiftListResponse = companyClient.bulkPublishShifts(AuthConstant.AUTHORIZATION_SUPPORT_USER, bulkPublishShiftsRequest1); log.info(shiftListResponse.toString()); assertThat(shiftListResponse.isSuccess()).isTrue(); ShiftList shiftList = shiftListResponse.getShiftList(); ShiftDto shiftDto1Clone = shiftDto1.toBuilder().published(false).build(); ShiftDto shiftDto2Clone = shiftDto2.toBuilder().published(false).build(); assertThat(shiftList.getShifts()).containsExactly(shiftDto1Clone, shiftDto2Clone); ArgumentCaptor<AlertRemovedShiftsRequest> argument1 = ArgumentCaptor.forClass(AlertRemovedShiftsRequest.class); verify(botClient, times(1)).alertRemovedShifts(argument1.capture()); AlertRemovedShiftsRequest alertRemovedShiftsRequest = argument1.getValue(); assertThat(alertRemovedShiftsRequest.getUserId()).isEqualTo(shiftDto1.getUserId()); assertThat(alertRemovedShiftsRequest.getOldShifts()).containsExactly(shiftDto1, shiftDto2); BulkPublishShiftsRequest bulkPublishShiftsRequest2 = BulkPublishShiftsRequest.builder() .companyId(company.getId()) .jobId(job.getId()) .teamId(team.getId()) .shiftStartAfter(Instant.now().minus(1, ChronoUnit.DAYS)) .shiftStartBefore(Instant.now().plus(5, ChronoUnit.DAYS)) .published(true) .build(); when(botClient.alertNewShifts(any(AlertNewShiftsRequest.class))) .thenReturn(BaseResponse.builder().message("New Shifts Alerted").build()); shiftListResponse = companyClient.bulkPublishShifts(AuthConstant.AUTHORIZATION_SUPPORT_USER, bulkPublishShiftsRequest2); log.info(shiftListResponse.toString()); assertThat(shiftListResponse.isSuccess()).isTrue(); shiftList = shiftListResponse.getShiftList(); assertThat(shiftList.getShifts()).containsExactly(shiftDto1, shiftDto2); ArgumentCaptor<AlertNewShiftsRequest> argument2 = ArgumentCaptor.forClass(AlertNewShiftsRequest.class); verify(botClient, times(1)).alertNewShifts(argument2.capture()); AlertNewShiftsRequest alertNewShiftsRequest = argument2.getValue(); assertThat(alertNewShiftsRequest.getUserId()).isEqualTo(shiftDto1.getUserId()); assertThat(alertNewShiftsRequest.getNewShifts()).containsExactly(shiftDto1Clone, shiftDto2Clone); }
@PostMapping(path = "/bulk_publish") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericShiftListResponse bulkPublishShifts(@RequestBody @Validated BulkPublishShiftsRequest request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionTeamWorker(request.getCompanyId(), request.getTeamId()); } ShiftList shiftList = shiftService.bulkPublishShifts(request); return new GenericShiftListResponse(shiftList); }
ShiftController { @PostMapping(path = "/bulk_publish") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericShiftListResponse bulkPublishShifts(@RequestBody @Validated BulkPublishShiftsRequest request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionTeamWorker(request.getCompanyId(), request.getTeamId()); } ShiftList shiftList = shiftService.bulkPublishShifts(request); return new GenericShiftListResponse(shiftList); } }
ShiftController { @PostMapping(path = "/bulk_publish") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericShiftListResponse bulkPublishShifts(@RequestBody @Validated BulkPublishShiftsRequest request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionTeamWorker(request.getCompanyId(), request.getTeamId()); } ShiftList shiftList = shiftService.bulkPublishShifts(request); return new GenericShiftListResponse(shiftList); }  }
ShiftController { @PostMapping(path = "/bulk_publish") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericShiftListResponse bulkPublishShifts(@RequestBody @Validated BulkPublishShiftsRequest request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionTeamWorker(request.getCompanyId(), request.getTeamId()); } ShiftList shiftList = shiftService.bulkPublishShifts(request); return new GenericShiftListResponse(shiftList); }  @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftResponse createShift(@RequestBody @Validated CreateShiftRequest request); @PostMapping(path = "/list_worker_shifts") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_BOT_SERVICE, AuthConstant.AUTHORIZATION_ICAL_SERVICE }) GenericShiftListResponse listWorkerShifts(@RequestBody @Validated WorkerShiftListRequest request); @PostMapping(path = "/list_shifts") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftListResponse listShifts(@RequestBody @Validated ShiftListRequest request); @PostMapping(path = "/bulk_publish") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftListResponse bulkPublishShifts(@RequestBody @Validated BulkPublishShiftsRequest request); @GetMapping(path = "/get") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftResponse getShift(@RequestParam String shiftId, @RequestParam String teamId, @RequestParam  String companyId); @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftResponse updateShift(@RequestBody @Validated ShiftDto shiftDto); @DeleteMapping(path = "/delete") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) BaseResponse deleteShift(@RequestParam String shiftId, @RequestParam String teamId, @RequestParam String companyId); }
ShiftController { @PostMapping(path = "/bulk_publish") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericShiftListResponse bulkPublishShifts(@RequestBody @Validated BulkPublishShiftsRequest request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionTeamWorker(request.getCompanyId(), request.getTeamId()); } ShiftList shiftList = shiftService.bulkPublishShifts(request); return new GenericShiftListResponse(shiftList); }  @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftResponse createShift(@RequestBody @Validated CreateShiftRequest request); @PostMapping(path = "/list_worker_shifts") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_BOT_SERVICE, AuthConstant.AUTHORIZATION_ICAL_SERVICE }) GenericShiftListResponse listWorkerShifts(@RequestBody @Validated WorkerShiftListRequest request); @PostMapping(path = "/list_shifts") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftListResponse listShifts(@RequestBody @Validated ShiftListRequest request); @PostMapping(path = "/bulk_publish") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftListResponse bulkPublishShifts(@RequestBody @Validated BulkPublishShiftsRequest request); @GetMapping(path = "/get") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftResponse getShift(@RequestParam String shiftId, @RequestParam String teamId, @RequestParam  String companyId); @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftResponse updateShift(@RequestBody @Validated ShiftDto shiftDto); @DeleteMapping(path = "/delete") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) BaseResponse deleteShift(@RequestParam String shiftId, @RequestParam String teamId, @RequestParam String companyId);  }