diff --git a/data-api/open-api-specification.yml b/data-api/open-api-specification.yml index 72d5fc9..863c668 100644 --- a/data-api/open-api-specification.yml +++ b/data-api/open-api-specification.yml @@ -1011,7 +1011,7 @@ paths: in: 'query' schema: type: boolean - allowEmptyValue: true + default: true - name: 'notification-type' in: 'query' schema: @@ -1029,13 +1029,6 @@ paths: type: 'string' example: "2017-01-01" format: date - - name: 'sort' - in: 'query' - schema: - type: 'array' - items: - type: 'string' - - $ref: '#/components/parameters/maxRecords' responses: '200': description: 'Successful operation' @@ -1060,15 +1053,6 @@ components: type: apiKey in: header name: Authorization - parameters: - maxRecords: - in: query - name: 'max-records' - required: false - schema: - type: 'integer' - default: 100 - example: 123 schemas: baseOffice: type: 'object' diff --git a/data-service/src/main/java/uk/gov/laa/ccms/data/controller/NotificationsController.java b/data-service/src/main/java/uk/gov/laa/ccms/data/controller/NotificationsController.java index 7233908..9b27175 100644 --- a/data-service/src/main/java/uk/gov/laa/ccms/data/controller/NotificationsController.java +++ b/data-service/src/main/java/uk/gov/laa/ccms/data/controller/NotificationsController.java @@ -1,7 +1,6 @@ package uk.gov.laa.ccms.data.controller; import java.time.LocalDate; -import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; @@ -27,18 +26,34 @@ public class NotificationsController implements NotificationsApi { private final NotificationService notificationService; + /** + * Retrieves a list of notifications based on various search criteria. + * + * @param caseReferenceNumber the case reference number to filter notifications + * @param providerCaseReference the provider-specific case reference to filter notifications + * @param assignedToUserId the user ID to filter notifications assigned to a specific user + * @param clientSurname the client's surname to filter notifications for a specific client + * @param feeEarnerId the ID of the fee earner to filter notifications associated with them + * @param includeClosed a flag to indicate whether to include closed notifications in the results + * @param notificationType the type of notifications to filter by + * @param dateFrom the starting date to filter notifications by a specific date range + * @param dateTo the ending date to filter notifications by a specific date range + * @param pageable the pagination and sorting information for the result set + * @return a {@code ResponseEntity} containing the retrieved list of notifications if found, + * or a {@code ResponseEntity} with HTTP status 404 if no notifications are found + */ @Override public ResponseEntity getNotifications(String caseReferenceNumber, String providerCaseReference, String assignedToUserId, String clientSurname, Integer feeEarnerId, Boolean includeClosed, String notificationType, LocalDate dateFrom, - LocalDate dateTo, List sort, Integer maxRecords, Pageable pageable) { + LocalDate dateTo, Pageable pageable) { Optional notifications = notificationService.getNotifications( caseReferenceNumber, providerCaseReference, assignedToUserId, clientSurname, feeEarnerId, - includeClosed, + Boolean.TRUE.equals(includeClosed), notificationType, dateFrom, dateTo, @@ -46,6 +61,13 @@ public ResponseEntity getNotifications(String caseReferenceNumber return notifications.map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build()); } + /** + * Retrieves a summary of user notifications for the specified login ID. + * + * @param loginId the login ID of the user for whom the notification summary is to be retrieved + * @return a {@code ResponseEntity} containing the {@code NotificationSummary} if found, + * or a {@code ResponseEntity} with HTTP status 404 if no summary is available + */ @Override public ResponseEntity getUserNotificationSummary(String loginId) { return notificationService.getUserNotificationSummary(loginId).map(ResponseEntity::ok) diff --git a/data-service/src/main/java/uk/gov/laa/ccms/data/service/NotificationService.java b/data-service/src/main/java/uk/gov/laa/ccms/data/service/NotificationService.java index b50559f..c3d9c76 100644 --- a/data-service/src/main/java/uk/gov/laa/ccms/data/service/NotificationService.java +++ b/data-service/src/main/java/uk/gov/laa/ccms/data/service/NotificationService.java @@ -67,7 +67,7 @@ public Optional getUserNotificationSummary(String userId) { */ public Optional getNotifications(String caseReferenceNumber, String providerCaseReference, String assignedToUserId, String clientSurname, - Integer feeEarnerId, Boolean includeClosed, String notificationType, LocalDate dateFrom, + Integer feeEarnerId, boolean includeClosed, String notificationType, LocalDate dateFrom, LocalDate dateTo, Pageable pageable) { Page byAssignedTo = notificationRepository.findAll( NotificationSpecification.withFilters(caseReferenceNumber, diff --git a/data-service/src/test/java/uk/gov/laa/ccms/data/controller/NotificationsControllerTest.java b/data-service/src/test/java/uk/gov/laa/ccms/data/controller/NotificationsControllerTest.java index 1cd349d..16a7f03 100644 --- a/data-service/src/test/java/uk/gov/laa/ccms/data/controller/NotificationsControllerTest.java +++ b/data-service/src/test/java/uk/gov/laa/ccms/data/controller/NotificationsControllerTest.java @@ -14,14 +14,18 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.web.context.WebApplicationContext; import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; +import uk.gov.laa.ccms.data.model.Notification; import uk.gov.laa.ccms.data.model.NotificationSummary; +import uk.gov.laa.ccms.data.model.Notifications; import uk.gov.laa.ccms.data.service.NotificationService; @ExtendWith({SpringExtension.class}) @@ -44,7 +48,9 @@ class NotificationsControllerTest { @BeforeEach public void setup() { - mockMvc = standaloneSetup(notificationsController).build(); + mockMvc = standaloneSetup(notificationsController) + .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) + .build(); objectMapper = new ObjectMapper(); } @@ -74,4 +80,31 @@ void getUserNotificationSummary_notFound() throws Exception { .andDo(print()) .andExpect(status().isNotFound()); } + + @Test + @DisplayName("getNotifications: Returns data") + void getNotifications_returnsData() throws Exception { + //Given + Notifications expected = new Notifications().addContentItem(new Notification().notificationId("123")); + when(notificationService.getNotifications(Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.any(), Mockito.any(), + Mockito.any(), Mockito.any())).thenReturn(Optional.of( + expected)); + // Then + String jsonContent = objectMapper.writeValueAsString(expected); + this.mockMvc.perform(get("/notifications")) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(content().json(jsonContent)); + } + + @Test + @DisplayName("getNotifications: Not found") + void getNotifications_notFound() throws Exception { + //Given + // Then + this.mockMvc.perform(get("/notifications")) + .andDo(print()) + .andExpect(status().isNotFound()); + } } \ No newline at end of file