Skip to content

Commit

Permalink
feat: add update and delete for theme
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteenke committed Feb 28, 2024
1 parent 63c67e4 commit 5630ce2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,34 @@ public Response uploadImage(Integer contentLength, String refId, RefTypeDTO refT
}

@Override
public Response deleteImage(String refId, RefTypeDTO refType) {
public Response deleteImage(String refId) {
imageDAO.deleteQueryByRefId(refId);
return Response.status(Response.Status.NO_CONTENT).build();
}

@Override
public Response updateImageRefType(String refId) {
Image imageForLogo = imageDAO.findByRefIdAndRefType(refId, RefTypeDTO.LOGO.toString());
if (imageForLogo != null) {
imageForLogo.setRefId(refId);
imageDAO.update(imageForLogo);
}
Image imageForFavicon = imageDAO.findByRefIdAndRefType(refId, RefTypeDTO.FAVICON.toString());
if (imageForFavicon != null) {
imageForFavicon.setRefId(refId);
imageDAO.update(imageForFavicon);
}

if (imageForLogo.getRefId() != null) {
return Response.ok(imageMapper.map(imageForLogo)).build();
} else if (imageForFavicon.getRefId() != null) {
return Response.ok(imageMapper.map(imageForFavicon)).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}

}

@ServerExceptionMapper
public RestResponse<ProblemDetailResponseDTO> exception(ConstraintException ex) {
return exceptionMapper.exception(ex);
Expand Down
24 changes: 22 additions & 2 deletions src/main/openapi/onecx-image-internal-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetailResponse'
/internal/images/{refId}:
delete:
tags:
- imagesInternal
Expand All @@ -137,11 +138,30 @@ paths:
required: true
schema:
type: string
- name: refType
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ImageInfo'
"400":
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetailResponse'
put:
tags:
- imagesInternal
description: update Images ref type
operationId: updateImageRefType
parameters:
- name: refId
in: path
required: true
schema:
$ref: "#/components/schemas/RefType"
type: string
responses:
"200":
description: OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void uploadImage() {
.when()
.body(FILE)
.contentType(MEDIA_TYPE_IMAGE_PNG)
.post()
.post("/{refType}")
.then()
.statusCode(CREATED.getStatusCode())
.extract()
Expand All @@ -58,7 +58,7 @@ void uploadImageEmptyBody() {
.pathParam("refType", RefTypeDTO.LOGO.toString())
.when()
.contentType(MEDIA_TYPE_IMAGE_PNG)
.post()
.post("/{refType}")
.then()
.statusCode(BAD_REQUEST.getStatusCode())
.extract().as(ProblemDetailResponseDTO.class);
Expand All @@ -79,7 +79,7 @@ void uploadImage_shouldReturnBadRequest_whenImageIs() {
.when()
.body(FILE)
.contentType(MEDIA_TYPE_IMAGE_PNG)
.post()
.post("/{refType}")
.then()
.statusCode(CREATED.getStatusCode());

Expand All @@ -89,7 +89,7 @@ void uploadImage_shouldReturnBadRequest_whenImageIs() {
.when()
.body(FILE)
.contentType(MEDIA_TYPE_IMAGE_PNG)
.post()
.post("/{refType}")
.then()
.statusCode(BAD_REQUEST.getStatusCode())
.extract().as(ProblemDetailResponseDTO.class);
Expand All @@ -111,15 +111,15 @@ void getImagePngTest() {
.when()
.body(FILE)
.contentType(MEDIA_TYPE_IMAGE_PNG)
.post()
.post("/{refType}")
.then()
.statusCode(CREATED.getStatusCode());

var data = given()
.contentType(APPLICATION_JSON)
.pathParam("refId", refId)
.pathParam("refType", refType)
.get()
.get("/{refType}")
.then()
.statusCode(OK.getStatusCode())
.header(HttpHeaders.CONTENT_TYPE, MEDIA_TYPE_IMAGE_PNG)
Expand All @@ -140,15 +140,15 @@ void getImageJpgTest() {
.when()
.body(FILE)
.contentType(MEDIA_TYPE_IMAGE_JPG)
.post()
.post("/{refType}")
.then()
.statusCode(CREATED.getStatusCode());

var data = given()
.contentType(APPLICATION_JSON)
.pathParam("refId", refId)
.pathParam("refType", refType)
.get()
.get("/{refType}")
.then()
.statusCode(OK.getStatusCode())
.header(HttpHeaders.CONTENT_TYPE, MEDIA_TYPE_IMAGE_JPG)
Expand All @@ -169,15 +169,15 @@ void getImageTest_shouldReturnNotFound_whenImagesDoesNotExist() {
.when()
.body(FILE)
.contentType(MEDIA_TYPE_IMAGE_PNG)
.post()
.post("/{refType}")
.then()
.statusCode(CREATED.getStatusCode());

given()
.contentType(APPLICATION_JSON)
.pathParam("refId", refId + "_not_exists")
.pathParam("refType", refType)
.get()
.get("/{refType}")
.then()
.statusCode(NOT_FOUND.getStatusCode());
}
Expand All @@ -194,7 +194,7 @@ void updateImage() {
.when()
.body(FILE)
.contentType(MEDIA_TYPE_IMAGE_PNG)
.post()
.post("/{refType}")
.then()
.statusCode(CREATED.getStatusCode())
.extract()
Expand All @@ -206,7 +206,7 @@ void updateImage() {
.when()
.body(FILE)
.contentType(MEDIA_TYPE_IMAGE_PNG)
.put()
.put("/{refType}")
.then()
.statusCode(OK.getStatusCode())
.extract()
Expand All @@ -220,7 +220,7 @@ void updateImage() {
.when()
.body(FILE)
.contentType(MEDIA_TYPE_IMAGE_PNG)
.put()
.put("/{refType}")
.then()
.statusCode(NOT_FOUND.getStatusCode());
}
Expand All @@ -237,7 +237,7 @@ void updateImage_returnNotFound_whenEntryNotExists() {
.when()
.body(FILE)
.contentType(MEDIA_TYPE_IMAGE_PNG)
.post()
.post("/{refType}")
.then()
.statusCode(CREATED.getStatusCode())
.extract()
Expand All @@ -249,7 +249,7 @@ void updateImage_returnNotFound_whenEntryNotExists() {
.when()
.body(FILE)
.contentType(MEDIA_TYPE_IMAGE_PNG)
.put()
.put("/{refType}")
.then()
.statusCode(NOT_FOUND.getStatusCode());

Expand All @@ -270,7 +270,7 @@ void testMaxUploadSize() {
.when()
.body(body)
.contentType(MEDIA_TYPE_IMAGE_PNG)
.post()
.post("/{refType}")
.then()
.statusCode(BAD_REQUEST.getStatusCode())
.extract().as(ProblemDetailResponseDTO.class);
Expand Down

0 comments on commit 5630ce2

Please sign in to comment.