Skip to content

Commit

Permalink
이미지 수정 부분 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Johyunik committed Dec 2, 2023
1 parent 53ecc36 commit 3a21eb7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public String insertBoard(@RequestHeader("decodedToken") String nickName, @Reque
String imageUrl = imageService.saveImage(image);

ImageEntity imageEntity = ImageEntity.builder()
.image_url(imageUrl)
.imageUrl(imageUrl)
.boardId(savedBoard)
.build();
imageRepository.save(imageEntity);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/weatherfit/board/domain/BoardEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ImageDTO entityToDTO(ImageEntity imageEntity) {
return ImageDTO.builder()
.boardId(imageEntity.getBoardId().getBoardId())
.imageId(imageEntity.getImageId())
.image_url(imageEntity.getImage_url())
.imageUrl(imageEntity.getImageUrl())
.build();
}
}
7 changes: 2 additions & 5 deletions src/main/java/com/weatherfit/board/domain/ImageEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@ public class ImageEntity {
private BoardEntity boardId;

@Column(name = "image_url", nullable = false)
private String image_url;
private String imageUrl;

public ImageDTO entityToDTO(ImageEntity imageEntity) {
return ImageDTO.builder()
.boardId(imageEntity.getBoardId().getBoardId())
.imageId(imageEntity.getImageId())
.image_url(imageEntity.getImage_url())
.imageUrl(imageEntity.getImageUrl())
.build();

}
public String getImageUrl() { // 수정된 부분
return image_url;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/weatherfit/board/dto/ImageDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class ImageDTO {
private int imageId;
private int boardId;
private String image_url;
private String imageUrl;


}
2 changes: 1 addition & 1 deletion src/main/java/com/weatherfit/board/dto/MyLikeDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MyLikeDTO {
public MyLikeDTO(BoardEntity boardEntity) {
this.boardId = boardEntity.getBoardId();
if(!boardEntity.getImages().isEmpty()) {
this.images = String.valueOf(boardEntity.getImages().get(0).getImage_url());
this.images = String.valueOf(boardEntity.getImages().get(0).getImageUrl());
}
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/weatherfit/board/service/BoardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void patchBoard(int boardId, String boardJson, MultipartFile[] images, St
String imageUrl = imageService.saveImage(image);

ImageEntity imageEntity = ImageEntity.builder()
.image_url(imageUrl)
.imageUrl(imageUrl)
.boardId(originalBoard)
.build();
imageRepository.save(imageEntity);
Expand All @@ -181,10 +181,10 @@ public void patchBoard(int boardId, String boardJson, MultipartFile[] images, St

// 새로운 이미지 URL과 기존의 이미지 URL을 비교하여 이미지가 수정되었는지 판단합니다.
for (ImageEntity originalImage : originalBoard.getImages()) {
boolean isModified = newImages.stream().noneMatch(newImage -> newImage.getImage_url().equals(originalImage.getImage_url()));
boolean isModified = newImages.stream().noneMatch(newImage -> newImage.getImageUrl().equals(originalImage.getImageUrl()));
if (isModified) {
// 이미지가 수정되었을 경우, 기존의 이미지를 삭제합니다.
imageService.deleteImage(originalImage.getImage_url());
imageService.deleteImage(originalImage.getImageUrl());
imageRepository.delete(originalImage);
}
}
Expand Down

0 comments on commit 3a21eb7

Please sign in to comment.