diff --git a/src/main/java/chzzk/grassdiary/domain/diary/service/DiaryService.java b/src/main/java/chzzk/grassdiary/domain/diary/service/DiaryService.java index c2572aee..14c41a39 100644 --- a/src/main/java/chzzk/grassdiary/domain/diary/service/DiaryService.java +++ b/src/main/java/chzzk/grassdiary/domain/diary/service/DiaryService.java @@ -112,7 +112,7 @@ public DiaryDetailDTO findById(Long diaryId, Long logInMemberId) { public List 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(); } diff --git a/src/main/java/chzzk/grassdiary/domain/image/controller/ImageController.java b/src/main/java/chzzk/grassdiary/domain/image/controller/ImageController.java index c2f625bc..bd82c7d6 100644 --- a/src/main/java/chzzk/grassdiary/domain/image/controller/ImageController.java +++ b/src/main/java/chzzk/grassdiary/domain/image/controller/ImageController.java @@ -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 ) { diff --git a/src/main/java/chzzk/grassdiary/domain/image/dto/ImageDTO.java b/src/main/java/chzzk/grassdiary/domain/image/dto/ImageDTO.java index a5d53d28..320f5cfe 100644 --- a/src/main/java/chzzk/grassdiary/domain/image/dto/ImageDTO.java +++ b/src/main/java/chzzk/grassdiary/domain/image/dto/ImageDTO.java @@ -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); } } diff --git a/src/main/java/chzzk/grassdiary/domain/image/entity/Image.java b/src/main/java/chzzk/grassdiary/domain/image/entity/Image.java index 83ab074d..e2b15eee 100644 --- a/src/main/java/chzzk/grassdiary/domain/image/entity/Image.java +++ b/src/main/java/chzzk/grassdiary/domain/image/entity/Image.java @@ -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; } } diff --git a/src/main/java/chzzk/grassdiary/domain/image/service/ImageService.java b/src/main/java/chzzk/grassdiary/domain/image/service/ImageService.java index 4fd284e0..8220300f 100644 --- a/src/main/java/chzzk/grassdiary/domain/image/service/ImageService.java +++ b/src/main/java/chzzk/grassdiary/domain/image/service/ImageService.java @@ -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); } /**