Skip to content

Commit

Permalink
Merge pull request #90 from kko-bugi/feature/deleteImage
Browse files Browse the repository at this point in the history
[feature/deleteImage] 글 삭제 시 이미지도 함께 삭제되도록 수정
  • Loading branch information
JoongHyun-Kim authored Feb 20, 2024
2 parents 5b3bd26 + b033664 commit b63d21c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public enum BaseResponseStatus {

// produce(3100-3199)
NULL_PRODUCE_LIST(false, 3100, "판매글 목록이 비었습니다."),
IMAGE_DELETE_FAIL(false, 3101, "이미지 삭제에 실패했습니다."),

// recipe(3200-3299)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ public String uploadImage(String folderName, MultipartFile multipartFile) throws
.build(), multipartFile.getInputStream());
return fullPath;
}

// 이미지 삭제
public boolean deleteImage(String imageUrl) {
String fullPath = imageUrl.substring(("https://storage.googleapis.com/"+bucketName+"/").length());
return storage.delete(bucketName, fullPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ private static void validateWriter(User user, Giveaway giveaway) throws BaseExce
}

// 나눔글 삭제
@Transactional(rollbackFor = Exception.class)
public void deleteGiveaway(Long giveawayIdx) throws BaseException {
try {
Long userIdx = getUserIdxWithValidation();
Expand All @@ -142,6 +143,9 @@ public void deleteGiveaway(Long giveawayIdx) throws BaseException {
validateWriter(user, giveaway);

giveaway.delete();
boolean isDeleted = gcsService.deleteImage(giveaway.getGiveawayImage());
if (!isDeleted) throw new BaseException(IMAGE_DELETE_FAIL);

giveawayRepository.save(giveaway);
} catch (BaseException e) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Giveaway extends BaseEntity {
@JoinColumn(nullable = false, name = "userIdx")
private User user;

@Column(nullable = false)
@Column(nullable = false, length = 32)
private String title;

@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void changeProduceStatus(Long produceIdx) throws BaseException {
}

// 판매글 삭제
@Transactional(rollbackFor = Exception.class)
public void deleteProduce(Long produceIdx) throws BaseException {
try {
Long userIdx = getUserIdxWithValidation();
Expand All @@ -135,6 +136,9 @@ public void deleteProduce(Long produceIdx) throws BaseException {
validateWriter(user, produce);

produce.delete();
boolean isDeleted = gcsService.deleteImage(produce.getProduceImage());
if (!isDeleted) throw new BaseException(IMAGE_DELETE_FAIL);

produceRepository.save(produce);
} catch (BaseException e) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public void postRecipe(MultipartFile image, RecipePostRequest recipePostRequest)
}

// 레시피글 삭제
@Transactional(rollbackFor = Exception.class)
public void deleteRecipe(Long recipeIdx) throws BaseException {
try {
Long userIdx = getUserIdxWithValidation();
Expand All @@ -143,6 +144,9 @@ public void deleteRecipe(Long recipeIdx) throws BaseException {
validateWriter(user, recipe);

recipe.delete();
boolean isDeleted = gcsService.deleteImage(recipe.getRecipeImage());
if (!isDeleted) throw new BaseException(IMAGE_DELETE_FAIL);

recipeRepository.save(recipe);
} catch (BaseException e) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Recipe extends BaseEntity {
@JoinColumn(nullable = false, name = "userIdx")
private User user;

@Column(nullable = false, length = 100)
@Column(nullable = false, length = 32)
private String title;

@Column(nullable = false)
Expand Down

0 comments on commit b63d21c

Please sign in to comment.