From 0071b00012e331d1195db89b5b91d09f972e8e8b Mon Sep 17 00:00:00 2001 From: jsteenke <146953549+jsteenke@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:11:47 +0100 Subject: [PATCH] feat: fit bff project to UI (#2) * feat: init setup * feat: test added * feat: update swagger AnnouncementSearchCriteriaDTO * feat: update pom * feat: update properties * feat: helm settings * fix: change search return PageResult * fix: update method error response * feat: update openapi validation * fix: helm files changes * fix: log level delete * fix: delete response mapper --- src/main/helm/Chart.yaml | 2 +- .../AnnouncementRestController.java | 8 +-- .../bff/rs/mappers/AnnouncementMapper.java | 1 - .../bff/rs/mappers/ResponseMapper.java | 22 ------ .../openapi/openapi-announcement-bff.yaml | 70 ++++--------------- .../rs/AnnouncementRestControllerTest.java | 18 ++++- 6 files changed, 30 insertions(+), 91 deletions(-) delete mode 100644 src/main/java/io/github/onecx/announcement/bff/rs/mappers/ResponseMapper.java diff --git a/src/main/helm/Chart.yaml b/src/main/helm/Chart.yaml index 0de0e3b..93f911f 100644 --- a/src/main/helm/Chart.yaml +++ b/src/main/helm/Chart.yaml @@ -1,4 +1,4 @@ -apiVersion: v1 +apiVersion: v2 name: onecx-announcement-bff version: 0.0.0 appVersion: 0.0.0 diff --git a/src/main/java/io/github/onecx/announcement/bff/rs/controller/AnnouncementRestController.java b/src/main/java/io/github/onecx/announcement/bff/rs/controller/AnnouncementRestController.java index 73bbb21..992b5a7 100644 --- a/src/main/java/io/github/onecx/announcement/bff/rs/controller/AnnouncementRestController.java +++ b/src/main/java/io/github/onecx/announcement/bff/rs/controller/AnnouncementRestController.java @@ -14,7 +14,6 @@ import gen.io.github.onecx.announcement.bff.clients.api.AnnouncementInternalApi; import gen.io.github.onecx.announcement.bff.clients.model.*; -import gen.io.github.onecx.announcement.bff.clients.model.ProblemDetailResponse; import gen.io.github.onecx.announcement.bff.rs.internal.AnnouncementInternalApiService; import gen.io.github.onecx.announcement.bff.rs.internal.model.*; import io.github.onecx.announcement.bff.rs.mappers.AnnouncementMapper; @@ -40,7 +39,7 @@ public class AnnouncementRestController implements AnnouncementInternalApiServic ExceptionMapper exceptionMapper; @Override - public Response addAnnouncement(CreateAnnouncementRequestDTO createAnnouncementRequestDTO) { + public Response createAnnouncement(CreateAnnouncementRequestDTO createAnnouncementRequestDTO) { try (Response response = client .createAnnouncement(announcementMapper.mapCreateAnnouncement(createAnnouncementRequestDTO))) { @@ -97,11 +96,6 @@ public Response updateAnnouncementById(String id, UpdateAnnouncementRequestDTO u Announcement announcement = response.readEntity(Announcement.class); AnnouncementDTO announcementDTO = announcementMapper.mapAnnouncementToAnnouncementDTO(announcement); return Response.status(response.getStatus()).entity(announcementDTO).build(); - } catch (WebApplicationException ex) { - return Response.status(ex.getResponse().getStatus()) - .entity(problemDetailMapper - .mapProblemDetailResponse(ex.getResponse().readEntity(ProblemDetailResponse.class))) - .build(); } } diff --git a/src/main/java/io/github/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java b/src/main/java/io/github/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java index 516d3e8..34d59f4 100644 --- a/src/main/java/io/github/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java +++ b/src/main/java/io/github/onecx/announcement/bff/rs/mappers/AnnouncementMapper.java @@ -16,7 +16,6 @@ public interface AnnouncementMapper { AnnouncementSearchCriteria mapAnnouncementSearchCriteria(AnnouncementSearchCriteriaDTO searchAnnouncementRequestDTO); - @Mapping(target = "version", ignore = true) AnnouncementDTO mapAnnouncementToAnnouncementDTO(Announcement announcement); @Mapping(target = "removeStreamItem", ignore = true) diff --git a/src/main/java/io/github/onecx/announcement/bff/rs/mappers/ResponseMapper.java b/src/main/java/io/github/onecx/announcement/bff/rs/mappers/ResponseMapper.java deleted file mode 100644 index 3982fcc..0000000 --- a/src/main/java/io/github/onecx/announcement/bff/rs/mappers/ResponseMapper.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.onecx.announcement.bff.rs.mappers; - -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; - -import gen.io.github.onecx.announcement.bff.clients.model.Announcement; -import gen.io.github.onecx.announcement.bff.clients.model.AnnouncementPageResult; -import gen.io.github.onecx.announcement.bff.rs.internal.model.AnnouncementDTO; -import gen.io.github.onecx.announcement.bff.rs.internal.model.AnnouncementPageResultDTO; - -@Mapper(uses = OffsetDateTimeMapper.class) -public interface ResponseMapper { - - @Mapping(target = "version", ignore = true) - AnnouncementDTO mapAnnouncementToAnnouncementDTO(Announcement announcement); - - @Mapping(target = "removeStreamItem", ignore = true) - AnnouncementPageResultDTO mapAnnouncementPageResultToAnnouncementPageResultDTO( - AnnouncementPageResult announcementPageResult); - -} diff --git a/src/main/openapi/openapi-announcement-bff.yaml b/src/main/openapi/openapi-announcement-bff.yaml index ce7ad78..0818401 100644 --- a/src/main/openapi/openapi-announcement-bff.yaml +++ b/src/main/openapi/openapi-announcement-bff.yaml @@ -39,8 +39,8 @@ paths: post: tags: - AnnouncementInternal - summary: Add announcement - operationId: addAnnouncement + summary: Create announcement + operationId: createAnnouncement requestBody: required: true content: @@ -112,12 +112,6 @@ paths: responses: "204": description: No content - "400": - description: Bad Request - content: - application/json: - schema: - $ref: '#/components/schemas/ProblemDetailResponse' put: tags: - AnnouncementInternal @@ -130,6 +124,7 @@ paths: schema: type: string requestBody: + required: true content: application/json: schema: @@ -158,6 +153,9 @@ components: type: string CreateAnnouncementRequest: type: object + required: + - title + - startDate properties: title: type: string @@ -175,23 +173,9 @@ components: $ref: '#/components/schemas/OffsetDateTime' appId: type: string - SearchAnnouncementRequest: + AnnouncementSearchCriteria: type: object properties: - creationDateFrom: - $ref: '#/components/schemas/OffsetDateTime' - creationDateTo: - $ref: '#/components/schemas/OffsetDateTime' - creationUser: - type: string - modificationDateFrom: - $ref: '#/components/schemas/OffsetDateTime' - modificationDateTo: - $ref: '#/components/schemas/OffsetDateTime' - modificationUser: - type: string - id: - type: string title: type: string content: @@ -224,6 +208,9 @@ components: type: integer UpdateAnnouncementRequest: type: object + required: + - title + - startDate properties: title: type: string @@ -244,7 +231,7 @@ components: Announcement: type: object properties: - version: + modificationCount: format: int32 type: integer creationDate: @@ -342,37 +329,4 @@ components: name: type: string message: - type: string - AnnouncementSearchCriteria: - type: object - properties: - title: - type: string - content: - type: string - type: - $ref: '#/components/schemas/AnnouncementType' - priority: - $ref: '#/components/schemas/AnnouncementPriorityType' - status: - $ref: '#/components/schemas/AnnouncementStatus' - startDateFrom: - $ref: '#/components/schemas/OffsetDateTime' - startDateTo: - $ref: '#/components/schemas/OffsetDateTime' - endDateFrom: - $ref: '#/components/schemas/OffsetDateTime' - endDateTo: - $ref: '#/components/schemas/OffsetDateTime' - appId: - type: string - pageNumber: - format: int32 - description: The number of page. - default: 0 - type: integer - pageSize: - format: int32 - description: The size of page - default: 100 - type: integer \ No newline at end of file + type: string \ No newline at end of file diff --git a/src/test/java/io/github/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java b/src/test/java/io/github/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java index f281471..9c0f187 100644 --- a/src/test/java/io/github/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java +++ b/src/test/java/io/github/onecx/announcement/bff/rs/AnnouncementRestControllerTest.java @@ -5,6 +5,7 @@ import static org.mockserver.model.HttpRequest.request; import static org.mockserver.model.HttpResponse.response; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.List; @@ -17,6 +18,7 @@ import org.mockserver.client.MockServerClient; import org.mockserver.model.JsonBody; import org.mockserver.model.MediaType; +import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; import gen.io.github.onecx.announcement.bff.clients.model.*; import gen.io.github.onecx.announcement.bff.rs.internal.model.*; @@ -40,12 +42,16 @@ void resetMockserver() { } @Test - void addAnnouncement_shouldReturnAnnouncement() { + void createAnnouncement_shouldReturnAnnouncement() { + var offsetDateTime = OffsetDateTime.parse("2023-11-30T13:53:03.688710200+01:00"); + OffsetDateTimeMapper offsetDateTimeMapper = new OffsetDateTimeMapper(); // Request data to svc Announcement data = new Announcement(); data.setAppId("appId"); data.setContent("AnnouncmentContent"); + data.setTitle("announcementTitle"); + data.startDate(offsetDateTime); // svc call prepare mock endpoint mockServerClient @@ -59,6 +65,8 @@ void addAnnouncement_shouldReturnAnnouncement() { // bff call input CreateAnnouncementRequestDTO input = new CreateAnnouncementRequestDTO(); input.setAppId("appId1"); + input.setTitle("announcementTitle"); + input.startDate(offsetDateTime); // bff call var response = given() @@ -79,6 +87,7 @@ void addAnnouncement_shouldReturnAnnouncement() { @Test void getAnnouncements_shouldReturnAnnouncementPageResults() { + Announcement announcement = new Announcement(); announcement.setAppId("appId"); announcement.setContent("AnnouncmentContent"); @@ -252,6 +261,9 @@ void deleteAnnouncementById() { @Test void updateAnnouncementById() { + var offsetDateTime = OffsetDateTime.parse("2023-11-30T13:53:03.688710200+01:00"); + OffsetDateTimeMapper offsetDateTimeMapper = new OffsetDateTimeMapper(); + String updateId = "updateId_NO_CONTENT"; Announcement data = new Announcement(); data.setAppId("appIdTest1"); @@ -267,6 +279,8 @@ void updateAnnouncementById() { .withBody(JsonBody.json(data))); UpdateAnnouncementRequestDTO input = new UpdateAnnouncementRequestDTO(); + input.setStartDate(offsetDateTime); + input.setTitle("appTitle"); // bff call given() .when() @@ -309,7 +323,7 @@ void updateAnnouncementById_shouldReturnBadRequest() { } @Test - void addAnnouncements_shouldReturnBadRequest_whenRunningIntoValidationConstraints() { + void createAnnouncement_shouldReturnBadRequest_whenRunningIntoValidationConstraints() { ProblemDetailResponse data = new ProblemDetailResponse(); data.setErrorCode("CONSTRAINT_VIOLATIONS");