Skip to content

Commit

Permalink
Merge pull request #194 from HongYeseul/feat/image
Browse files Browse the repository at this point in the history
feat(image): 이미지 저장시 이미지 사이즈 같이 저장
  • Loading branch information
HongYeseul authored Sep 25, 2024
2 parents ebd3e99 + 0863ff7 commit 47e111e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public DiaryDetailDTO findById(Long diaryId, Long logInMemberId) {
public List<ImageDTO> getImagesByDiary(Long diaryId) {
return diaryToImageDAO.findByDiaryId(diaryId)
.stream()
.map(image -> ImageDTO.from(image, imageService.getImageURLByImage(image.getImage()), image.getImage().getImageName()))
.map(image -> ImageDTO.from(image, imageService.getImageURLByImage(image.getImage()), image.getImage().getImageName(), image.getImage().getSize()))
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class ImageController {
String THEME_SHOP_URL = "static/images/theme_shop.jpg";

@PostMapping("/diary")
@Operation(
summary = "일기 이미지 저장",
description = "이미지 저장시 사이즈는 KB(킬로바이트) 단위")
public ResponseEntity<?> uploadDiaryImage(
@RequestPart MultipartFile image
) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/chzzk/grassdiary/domain/image/dto/ImageDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
public record ImageDTO (
Long imageId,
String imageURL,
String imageName
String imageName,
Long imageSize
) {
public static ImageDTO from(DiaryToImage diaryToImage, String imageURL, String imageName) {
return new ImageDTO(diaryToImage.getImage().getId(), imageURL, imageName);
public static ImageDTO from(DiaryToImage diaryToImage, String imageURL, String imageName, Long imageSize) {
return new ImageDTO(diaryToImage.getImage().getId(), imageURL, imageName, imageSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public class Image extends BaseCreatedTimeEntity {

private String imageName;

public Image(String imagePath, String imageName) {
private Long size;

public Image(String imagePath, String imageName, Long size) {
this.imagePath = imagePath;
this.imageName = imageName;
this.size = size;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public ImageDTO uploadImage(MultipartFile image, FileFolder category) {
throw new SystemException(ClientErrorCode.IMAGE_FILE_EMPTY);
}
String imagePath = awsS3Service.uploadBucket(image, category);
Image uploadedImage = imageDAO.save(new Image(imagePath, image.getOriginalFilename()));
long sizeInKB = image.getSize() / 1024;
Image uploadedImage = imageDAO.save(new Image(imagePath, image.getOriginalFilename(), sizeInKB));

return new ImageDTO(uploadedImage.getId(), baseURL + imagePath, image.getOriginalFilename());
return new ImageDTO(uploadedImage.getId(), baseURL + imagePath, image.getOriginalFilename(), sizeInKB);
}

/**
Expand Down

0 comments on commit 47e111e

Please sign in to comment.