Skip to content

Commit

Permalink
#162 Also resize the image if updated
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Strittmatter <[email protected]>
  • Loading branch information
Weltraumschaf committed Apr 19, 2023
1 parent eaad47b commit 001a673
Showing 1 changed file with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,7 @@ public ImageDTO save(final ImageDTO image) {
// TODO: See Issue #100
if (shouldResizeImage(image)) {
// FIXME: Validate the input (https://github.com/iteratec/TeamDojo/issues/11)
final var large = image.getLarge();
image.setLarge(resizer.resize(large, ImageResizer.MaxSize.LARGE));
image.setLargeContentType(CONTENT_TYPE);
image.setMedium(resizer.resize(large, ImageResizer.MaxSize.MEDIUM));
image.setMediumContentType(CONTENT_TYPE);
image.setSmall(resizer.resize(large, ImageResizer.MaxSize.SMALL));
image.setSmallContentType(CONTENT_TYPE);
image.setHash(digest(image.getLarge()));
resizeImage(image);
}

tracker.modifyCreatedAndUpdatedAt(image);
Expand All @@ -84,12 +77,15 @@ public ImageDTO save(final ImageDTO image) {
}

@Override
public ImageDTO update(ImageDTO imageDTO) {
log.debug("Request to update Image : {}", imageDTO);
Image image = mapper.toEntity(imageDTO);
image.setHash(digest(image.getLarge()));
image = repo.save(image);
return mapper.toDto(image);
public ImageDTO update(ImageDTO image) {
log.debug("Request to update Image : {}", image);
// TODO: See Issue #100
if (shouldResizeImage(image)) {
// FIXME: Validate the input (https://github.com/iteratec/TeamDojo/issues/11)
resizeImage(image);
}

return super.update(image);
}

String digest(final byte[] input) {
Expand All @@ -112,4 +108,16 @@ boolean shouldResizeImage(final ImageDTO image) {

return false;
}

private void resizeImage(ImageDTO image) {
final var large = image.getLarge();
image.setLarge(resizer.resize(large, ImageResizer.MaxSize.LARGE));
image.setLargeContentType(CONTENT_TYPE);
image.setMedium(resizer.resize(large, ImageResizer.MaxSize.MEDIUM));
image.setMediumContentType(CONTENT_TYPE);
image.setSmall(resizer.resize(large, ImageResizer.MaxSize.SMALL));
image.setSmallContentType(CONTENT_TYPE);
// TODO #162 Move out the method to do it anyways.
image.setHash(digest(image.getLarge()));
}
}

0 comments on commit 001a673

Please sign in to comment.