diff --git a/src/main/java/org/tkit/onecx/welcome/bff/rs/controllers/ImagesRestController.java b/src/main/java/org/tkit/onecx/welcome/bff/rs/controllers/ImagesRestController.java index cc524a2..f515228 100644 --- a/src/main/java/org/tkit/onecx/welcome/bff/rs/controllers/ImagesRestController.java +++ b/src/main/java/org/tkit/onecx/welcome/bff/rs/controllers/ImagesRestController.java @@ -18,9 +18,7 @@ import org.tkit.quarkus.log.cdi.LogService; import gen.org.tkit.onecx.welcome.bff.rs.internal.ImagesInternalApiService; -import gen.org.tkit.onecx.welcome.bff.rs.internal.model.ImageDataResponseDTO; -import gen.org.tkit.onecx.welcome.bff.rs.internal.model.ImageInfoDTO; -import gen.org.tkit.onecx.welcome.bff.rs.internal.model.ProblemDetailResponseDTO; +import gen.org.tkit.onecx.welcome.bff.rs.internal.model.*; import gen.org.tkit.onecx.welcome.client.api.ImagesInternalApi; import gen.org.tkit.onecx.welcome.client.model.ImageDataResponse; import gen.org.tkit.onecx.welcome.client.model.ImageInfo; @@ -102,6 +100,18 @@ public Response updateImageInfo(String id, ImageInfoDTO imageInfoDTO) { } } + @Override + public Response updateImageOrder(ImageInfoReorderRequestDTO imageInfoReorderRequestDTO) { + if (!imageInfoReorderRequestDTO.getImageInfos().isEmpty()) { + for (ImageInfoDTO imageInfoDTO : imageInfoReorderRequestDTO.getImageInfos()) { + welcomeClient.updateImageInfo(imageInfoDTO.getId(), + mapper.map(imageInfoDTO)).close(); + } + return Response.status(Response.Status.OK).build(); + } + return Response.status(Response.Status.BAD_REQUEST).build(); + } + @ServerExceptionMapper public RestResponse constraint(ConstraintViolationException ex) { return exceptionMapper.constraint(ex); diff --git a/src/main/openapi/onecx-welcome-bff.yaml b/src/main/openapi/onecx-welcome-bff.yaml index a2975a3..e0d00cf 100644 --- a/src/main/openapi/onecx-welcome-bff.yaml +++ b/src/main/openapi/onecx-welcome-bff.yaml @@ -100,6 +100,10 @@ paths: responses: "201": description: CREATED + content: + application/json: + schema: + $ref: '#/components/schemas/ImageInfo' "400": description: BAD REQUEST content: @@ -124,6 +128,31 @@ paths: type: array items: $ref: '#/components/schemas/ImageInfo' + /images/info/reorder: + post: + x-onecx: + permissions: + welcome: + - write + tags: + - imagesInternal + description: update order of Images + operationId: updateImageOrder + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ImageInfoReorderRequest' + responses: + "200": + description: UPDATED + "400": + description: BAD REQUEST + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemDetailResponse' /images: post: x-onecx: @@ -268,6 +297,13 @@ components: $ref: '#/components/schemas/OffsetDateTime' modificationUser: type: string + ImageInfoReorderRequest: + type: object + properties: + imageInfos: + type: array + items: + $ref: '#/components/schemas/ImageInfo' OffsetDateTime: format: date-time type: string diff --git a/src/test/java/org/tkit/onecx/welcome/bff/rs/ImageRestControllerTest.java b/src/test/java/org/tkit/onecx/welcome/bff/rs/ImageRestControllerTest.java index 7e79dfb..2fcb438 100644 --- a/src/test/java/org/tkit/onecx/welcome/bff/rs/ImageRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/welcome/bff/rs/ImageRestControllerTest.java @@ -25,6 +25,7 @@ import gen.org.tkit.onecx.welcome.bff.rs.internal.model.ImageDataResponseDTO; import gen.org.tkit.onecx.welcome.bff.rs.internal.model.ImageInfoDTO; +import gen.org.tkit.onecx.welcome.bff.rs.internal.model.ImageInfoReorderRequestDTO; import gen.org.tkit.onecx.welcome.bff.rs.internal.model.ProblemDetailResponseDTO; import gen.org.tkit.onecx.welcome.client.model.ImageDataResponse; import gen.org.tkit.onecx.welcome.client.model.ImageInfo; @@ -262,6 +263,76 @@ void updateImageInfoByIdTest() { assertThat(output.getUrl()).isEqualTo(info.getUrl()); } + @Test + void updateOrderTest() { + ImageInfo info = new ImageInfo(); + info.setUrl("someUrl"); + info.setPosition("1"); + info.setId("11-111"); + ImageInfo info2 = new ImageInfo(); + info2.setUrl("someUrl"); + info2.setPosition("2"); + info2.setId("22-222"); + + // create mock rest endpoint + mockServerClient.when(request().withPath("/internal/images/info/11-111").withMethod(HttpMethod.PUT) + .withContentType(MediaType.APPLICATION_JSON) + .withBody(JsonBody.json(info))) + .withId(mockId) + .respond(httpRequest -> response().withStatusCode(CREATED.getStatusCode()) + .withContentType(MediaType.APPLICATION_JSON) + .withBody(JsonBody.json(info))); + + // create mock rest endpoint + mockServerClient.when(request().withPath("/internal/images/info/22-222").withMethod(HttpMethod.PUT) + .withContentType(MediaType.APPLICATION_JSON) + .withBody(JsonBody.json(info2))) + .withId("mock2") + .respond(httpRequest -> response().withStatusCode(CREATED.getStatusCode()) + .withContentType(MediaType.APPLICATION_JSON) + .withBody(JsonBody.json(info2))); + + ImageInfoDTO infoDTO = new ImageInfoDTO(); + infoDTO.setPosition("1"); + infoDTO.setUrl("someUrl"); + infoDTO.setId("11-111"); + + ImageInfoDTO info2DTO = new ImageInfoDTO(); + info2DTO.setPosition("2"); + info2DTO.setUrl("someUrl"); + info2DTO.setId("22-222"); + + ImageInfoReorderRequestDTO reorderRequestDTO = new ImageInfoReorderRequestDTO(); + reorderRequestDTO.setImageInfos(List.of(infoDTO, info2DTO)); + + given() + .when() + .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) + .header(APM_HEADER_PARAM, ADMIN) + .body(reorderRequestDTO) + .contentType(APPLICATION_JSON) + .post("/info/reorder") + .then() + .statusCode(OK.getStatusCode()); + mockServerClient.clear("mock2"); + } + + @Test + void updateOrderWithEmptyBodyTest() { + ImageInfoReorderRequestDTO reorderRequestDTO = new ImageInfoReorderRequestDTO(); + reorderRequestDTO.setImageInfos(List.of()); + + given() + .when() + .auth().oauth2(keycloakClient.getAccessToken(ADMIN)) + .header(APM_HEADER_PARAM, ADMIN) + .body(reorderRequestDTO) + .contentType(APPLICATION_JSON) + .post("/info/reorder") + .then() + .statusCode(BAD_REQUEST.getStatusCode()); + } + @Test void deleteImageInfoByIdTest() {