From 2b3f760321ce931ae3934ec180a5d53816fb4b6d Mon Sep 17 00:00:00 2001 From: JordenReuter <149687553+JordenReuter@users.noreply.github.com> Date: Wed, 31 Jul 2024 12:05:49 +0200 Subject: [PATCH] feat: aligned to api changes (#55) --- .../onecx-announcement-bff-extensions.adoc | 30 +++++------ .../AnnouncementRestController.java | 12 +++++ .../bff/rs/mappers/AnnouncementMapper.java | 3 ++ src/main/openapi/openapi-bff.yaml | 53 ++++++++++++++++++ .../rs/AnnouncementRestControllerTest.java | 54 +++++++++++++++++-- 5 files changed, 134 insertions(+), 18 deletions(-) diff --git a/docs/modules/onecx-announcement-bff/pages/onecx-announcement-bff-extensions.adoc b/docs/modules/onecx-announcement-bff/pages/onecx-announcement-bff-extensions.adoc index a05a177..0ae768d 100644 --- a/docs/modules/onecx-announcement-bff/pages/onecx-announcement-bff-extensions.adoc +++ b/docs/modules/onecx-announcement-bff/pages/onecx-announcement-bff-extensions.adoc @@ -47,32 +47,32 @@ h| Version | tkit-quarkus-log-cdi | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-cdi.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link] +| 2.28.0 | tkit-quarkus-log-rs | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-rs.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link] +| 2.28.0 | tkit-quarkus-log-json | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-json.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link] +| 2.28.0 | tkit-quarkus-rest | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-rest.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link] +| 2.28.0 | tkit-quarkus-rest-context | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-rest-context.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link] +| 2.28.0 | quarkus-hibernate-validator @@ -95,8 +95,8 @@ h| Version | onecx-permissions | https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-permissions.html[Link] -| https://github.com/onecx/onecx-quarkus/blob/0.22.0/docs/modules/onecx-quarkus/pages/includes/onecx-permissions.adoc[Link] -| 0.22.0 +| https://github.com/onecx/onecx-quarkus/blob/0.24.0/docs/modules/onecx-quarkus/pages/includes/onecx-permissions.adoc[Link] +| 0.24.0 | quarkus-oidc @@ -113,14 +113,14 @@ h| Version | tkit-quarkus-security | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-security.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link] -| 2.27.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link] +| 2.28.0 | onecx-core | https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-core.html[Link] | -| 0.22.0 +| 0.24.0 | quarkus-arc diff --git a/src/main/java/org/tkit/onecx/announcement/bff/rs/controller/AnnouncementRestController.java b/src/main/java/org/tkit/onecx/announcement/bff/rs/controller/AnnouncementRestController.java index ac39837..568cbde 100644 --- a/src/main/java/org/tkit/onecx/announcement/bff/rs/controller/AnnouncementRestController.java +++ b/src/main/java/org/tkit/onecx/announcement/bff/rs/controller/AnnouncementRestController.java @@ -116,6 +116,18 @@ public Response searchActiveAnnouncements(ActiveAnnouncementsSearchCriteriaDTO a } } + @Override + public Response searchAnnouncementBanners(AnnouncementBannerSearchCriteriaDTO announcementBannerSearchCriteriaDTO) { + try (Response response = client + .searchAnnouncementBanners( + announcementMapper.mapAnnouncementBannerSearchCriteria(announcementBannerSearchCriteriaDTO))) { + AnnouncementPageResult announcementPageResult = response.readEntity(AnnouncementPageResult.class); + AnnouncementPageResultDTO announcementPageResultDTO = announcementMapper + .mapAnnouncementPageResultToAnnouncementPageResultDTO(announcementPageResult); + return Response.status(response.getStatus()).entity(announcementPageResultDTO).build(); + } + } + @Override public Response searchAnnouncements(AnnouncementSearchCriteriaDTO announcementSearchCriteriaDTO) { diff --git a/src/main/java/org/tkit/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java b/src/main/java/org/tkit/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java index 8e8d117..fbf4773 100644 --- a/src/main/java/org/tkit/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java +++ b/src/main/java/org/tkit/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java @@ -131,4 +131,7 @@ default ActiveAnnouncementsPageResultDTO filterAndSort(ActiveAnnouncementsPageRe @Mapping(target = "removeWorkspaceNamesItem", ignore = true) @Mapping(target = "removeProductNamesItem", ignore = true) AnnouncementAssignmentsDTO map(AnnouncementProducts announcementProducts); + + AnnouncementBannerSearchCriteria mapAnnouncementBannerSearchCriteria( + AnnouncementBannerSearchCriteriaDTO announcementBannerSearchCriteriaDTO); } diff --git a/src/main/openapi/openapi-bff.yaml b/src/main/openapi/openapi-bff.yaml index 20ad633..95dbf68 100644 --- a/src/main/openapi/openapi-bff.yaml +++ b/src/main/openapi/openapi-bff.yaml @@ -37,6 +37,37 @@ paths: application/json: schema: $ref: '#/components/schemas/ProblemDetailResponse' + /announcements/banner/search: + post: + x-onecx: + permissions: + announcement: + - read + tags: + - AnnouncementInternal + summary: Find announcements by criteria + operationId: searchAnnouncementBanners + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/AnnouncementBannerSearchCriteria' + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/AnnouncementPageResult' + "400": + description: Bad request + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemDetailResponse' /announcements/active/search: post: x-onecx: @@ -357,6 +388,28 @@ components: default: 100 maximum: 1000 type: integer + AnnouncementBannerSearchCriteria: + type: object + required: + - currentDate + properties: + currentDate: + $ref: '#/components/schemas/OffsetDateTime' + productName: + type: string + workspaceName: + type: string + pageNumber: + format: int32 + description: The number of page. + default: 0 + type: integer + pageSize: + format: int32 + description: The size of page + default: 100 + maximum: 1000 + type: integer UpdateAnnouncementRequest: type: object required: diff --git a/src/test/java/org/tkit/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java b/src/test/java/org/tkit/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java index bdb31e0..ec1a724 100644 --- a/src/test/java/org/tkit/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java @@ -118,9 +118,6 @@ void getAnnouncements_shouldReturnAnnouncementPageResults() { // Request data to svc AnnouncementPageResult data = new AnnouncementPageResult(); - data.setSize(5); - data.setTotalPages(1L); - data.setNumber(2); data.setStream(announcements); // svc call prepare mock endpoint @@ -156,6 +153,57 @@ void getAnnouncements_shouldReturnAnnouncementPageResults() { Assertions.assertEquals(data.getStream().get(0), announcement); } + @Test + void getAnnouncementBanners_shouldReturnAnnouncementPageResults() { + + Announcement announcement = new Announcement(); + announcement.setProductName("productName"); + announcement.setContent("AnnouncementContent"); + List announcements = new ArrayList<>(); + announcements.add(announcement); + + // Request data to svc + AnnouncementPageResult data = new AnnouncementPageResult(); + data.setStream(announcements); + + AnnouncementBannerSearchCriteria criteria = new AnnouncementBannerSearchCriteria(); + var dateTime = OffsetDateTime.parse("2023-11-30T13:53:03.688710200+01:00"); + criteria.setCurrentDate(dateTime); + + // svc call prepare mock endpoint + mockServerClient + .when(request().withPath(ANNOUNCEMENT_SVC_INTERNAL_API_BASE_PATH + "/banner/search") + .withMethod(HttpMethod.POST)) + .withId(MOCK_ID) + .respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode()) + .withContentType(MediaType.APPLICATION_JSON) + .withBody(JsonBody.json(data))); + + // bff call input + AnnouncementBannerSearchCriteriaDTO input = new AnnouncementBannerSearchCriteriaDTO(); + input.setCurrentDate(dateTime); + + // bff call + var response = given() + .when() + .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) + .header(APM_HEADER_PARAM, ADMIN) + .contentType(APPLICATION_JSON) + .body(input) + .post("/banner/search") + .then() + .statusCode(Response.Status.OK.getStatusCode()) + .contentType(APPLICATION_JSON) + .extract().as(AnnouncementPageResultDTO.class); + + // Assertions + Assertions.assertNotNull(response); + Assertions.assertEquals(data.getNumber(), response.getNumber()); + Assertions.assertEquals(data.getSize(), response.getSize()); + Assertions.assertEquals(1, data.getStream().size()); + Assertions.assertEquals(data.getStream().get(0), announcement); + } + @Test void getAnnouncementById_shouldReturnAnnouncement() { // Request data to svc