Skip to content

Commit

Permalink
Feature/reorder endpoint (#6)
Browse files Browse the repository at this point in the history
* feat: added ednpoint to reorder images

* feat: improved reorder endpoint
  • Loading branch information
JordenReuter authored Mar 13, 2024
1 parent c560d54 commit 19fab17
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ProblemDetailResponseDTO> constraint(ConstraintViolationException ex) {
return exceptionMapper.constraint(ex);
Expand Down
36 changes: 36 additions & 0 deletions src/main/openapi/onecx-welcome-bff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ paths:
responses:
"201":
description: CREATED
content:
application/json:
schema:
$ref: '#/components/schemas/ImageInfo'
"400":
description: BAD REQUEST
content:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {

Expand Down

0 comments on commit 19fab17

Please sign in to comment.